hdu 6011 Lotus and Characters
2017-05-13 10:41
411 查看
Lotus has nn
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
≥0≥0。
InputFirst line is T(0≤T≤1000)T(0≤T≤1000)
denoting the number of test cases.
For each test case,first line is an integer
n(1≤n≤26)n(1≤n≤26),followed
by nn
lines each containing 2 integers
vali,cnti(|vali|,cnti≤100)vali,cnti(|vali|,cnti≤100),denoting
the value and the amount of the ith character.
OutputFor each test case.output one line containing a single integer,denoting the answer.
Sample Input
Sample Output
//by swust_t_p
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
≥0≥0。
InputFirst line is T(0≤T≤1000)T(0≤T≤1000)
denoting the number of test cases.
For each test case,first line is an integer
n(1≤n≤26)n(1≤n≤26),followed
by nn
lines each containing 2 integers
vali,cnti(|vali|,cnti≤100)vali,cnti(|vali|,cnti≤100),denoting
the value and the amount of the ith character.
OutputFor 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> #include<math.h> #include<iostream> #include<set> using namespace std; #define mem(x,y) memset(x,y,sizeof(x)) struct node { int num, value; int f=0; friend bool operator<(const node &a, const node &b) { return a.value < b.value; } }; node zi[10000]; int n; int jia(int i) { int t = 0; for (int j = 1; j <= i; j++) { t += j; } return t; } int main() { int t; scanf("%d", &t); while (t--) { scanf("%d", &n); int sum=0; for (int i = 0; i < n; i++) { scanf("%d %d", &zi[i].value, &zi[i].num); if (zi[i].value > 0) { sum += zi[i].num*zi[i].value; } } sort(zi, zi + n); int a; int ans=0; int temp = 0; for (int i = n-1,k=1; i >= 0; i--) { int nowans = ans; for (int j = 0; j < zi[i].num; j++) { nowans = temp + nowans + zi[i].value; if (nowans > ans) { ans = nowans; a = zi[i].value; temp += a; } else if (nowans < ans) { break; } } } printf("%d\n", ans); } return 0; }
//by swust_t_p
相关文章推荐
- hdu 6011 Lotus and Characters
- 【HDU 6011 Lotus and Characters】
- HDU 6011 Lotus and Characters【思维】【pair】
- BestCoder Round #91 1001 (HDU 6011 Lotus and Characters) 1002 (HDU 6012 Lotus and Horticulture)
- Hdu 6011 Lotus and Characters【贪心+暴力】
- HDU-6011 Lotus and Characters
- hdu 6011 Lotus and Characters 思维
- hdu 6011Lotus and Characters
- HDU 6011 Lotus and Characters
- HDU 6011 BC 91 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
- 【杭电6011】BC-Lotus and Characters
- hdu----Lotus and Characters
- hdu 6012 Lotus and Horticulture
- 【HDU】6012 Lotus and Horticulture (BC#91 T2)
- hdu 6012 Lotus and Horticulture 思维+前缀和处理