HDU-6011 Lotus and Characters
2017-10-18 14:17
501 查看
Lotus and Characters
Description
Lotus has $n$ kinds of characters,each kind of characters has a value and a amount.She wants to construct a string using some of these characters.Define the value of a string is:its first character's value*1+its second character's value *2+...She wants to
calculate the maximum value of string she can construct.
Since it's valid to construct an empty string,the answer is always $\geq 0$。
Input
First line is $T(0 \leq T \leq 1000)$ denoting the number of test cases.
For each test case,first line is an integer $n(1 \leq n \leq 26)$,followed by $n$ lines each containing 2 integers $val_i,cnt_i(|val_i|,cnt_i\leq 100)$,denoting the value and the amount of the ith character.
Output
For each test case.output one line containing a single integer,denoting the answer.
Sample Input
2
2
5 1
6 2
3
-5 3
2 1
1 1
Sample Output
35
5
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int z[100008];
struct ha
{
int a;
int b;
}he[30];
int cmp(int a,int b)
{
return a<b;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,i,j;
scanf("%d",&n);
int t=0,sum=0,ans=0;
for(i=0;i<n;i++)
{
scanf("%d%d",&he[i].a,&he[i].b);
while(he[i].b--)
{
z[t++]=he[i].a;
}
}
sort(z,z+t,cmp);
for(j=t-1;j>=0;j--)
{
// printf("%d\n",z[j]);
sum+=z[j];
if(sum<0)
break;
ans+=sum;
}
printf("%d\n",ans);
}
return 0;
}
Description
Lotus has $n$ kinds of characters,each kind of characters has a value and a amount.She wants to construct a string using some of these characters.Define the value of a string is:its first character's value*1+its second character's value *2+...She wants to
calculate the maximum value of string she can construct.
Since it's valid to construct an empty string,the answer is always $\geq 0$。
Input
First line is $T(0 \leq T \leq 1000)$ denoting the number of test cases.
For each test case,first line is an integer $n(1 \leq n \leq 26)$,followed by $n$ lines each containing 2 integers $val_i,cnt_i(|val_i|,cnt_i\leq 100)$,denoting the value and the amount of the ith character.
Output
For each test case.output one line containing a single integer,denoting the answer.
Sample Input
2
2
5 1
6 2
3
-5 3
2 1
1 1
Sample Output
35
5
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int z[100008];
struct ha
{
int a;
int b;
}he[30];
int cmp(int a,int b)
{
return a<b;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,i,j;
scanf("%d",&n);
int t=0,sum=0,ans=0;
for(i=0;i<n;i++)
{
scanf("%d%d",&he[i].a,&he[i].b);
while(he[i].b--)
{
z[t++]=he[i].a;
}
}
sort(z,z+t,cmp);
for(j=t-1;j>=0;j--)
{
// printf("%d\n",z[j]);
sum+=z[j];
if(sum<0)
break;
ans+=sum;
}
printf("%d\n",ans);
}
return 0;
}
相关文章推荐
- BestCoder Round #91 1001 (HDU 6011 Lotus and Characters) 1002 (HDU 6012 Lotus and Horticulture)
- hdu 6011Lotus and Characters
- hdu 6011 Lotus and Characters
- HDU 6011 Lotus and Characters
- HDU 6011 Lotus and Characters
- hdu 6011 Lotus and Characters 思维
- HDU:6011 Lotus and Characters
- 【HDU 6011 Lotus and Characters】
- hdu 6011 Lotus and Characters
- Hdu 6011 Lotus and Characters【贪心+暴力】
- HDU 6011 Lotus and Characters
- HDU 6011 Lotus and Characters【思维】【pair】
- hdu 6011 lotus and characters
- hdu 6011 Lotus and Characters
- HDU 6011 BC 91 Lotus and Characters
- 【杭电6011】BC-Lotus and Characters
- hdu----Lotus and Characters
- Lotus and Characters
- Lotus and Characters
- Lotus and Characters (stronger)