hdu 6011 Lotus and Characters
来源:互联网 发布:mysql局域网访问配置 编辑:程序博客网 时间:2024/05/29 18:03
Problem 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≥0 。
Since it's valid to construct an empty string,the answer is always
Input
First line is T(0≤T≤1000) denoting the number of test cases.
For each test case,first line is an integern(1≤n≤26) ,followed by n lines each containing 2 integers vali,cnti(|vali|,cnti≤100) ,denoting the value and the amount of the ith character.
For each test case,first line is an integer
Output
For each test case.output one line containing a single integer,denoting the answer.
Sample Input
225 16 23-5 32 11 1
Sample Output
355
Source
BestCoder Round #91
大的肯定往后放。排序后先把正的放进去。
然后考虑往前面放负的。后面所有都会右移一位。因此记录后面所有数的和。如果大于当前负数的绝对值则放入负数
#include<cstdio>#include<algorithm>using namespace std;struct num{int v,c;}a[1001];inline bool cmp(num x,num y){return x.v<y.v;}int main(){int T;scanf("%d",&T);while(T>0){T--;int n;scanf("%d",&n);int i;for(i=1;i<=n;i++)scanf("%d%d",&a[i].v,&a[i].c);sort(a+1,a+1+n,cmp);int ans=0,d=1,la=-1,sum=0;for(i=1;i<=n;i++){if(a[i].v<0)continue;if(la==-1)la=i-1;while(a[i].c>0){ans+=a[i].v*d;sum+=a[i].v;a[i].c--;d++;}}for(i=la;i>=1;i--){while(a[i].c>0){sum+=a[i].v;if(sum<0)break;ans+=sum;a[i].c--;d++;}if(sum<0)break;}printf("%d\n",ans);}return 0;}
1 0
- 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 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----Lotus and Characters
- Hdu 6011 Lotus and Characters【贪心+暴力】
- HDU 6011 BC 91 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)
- 【杭电6011】BC-Lotus and Characters
- 倒序输出单链表
- 蓝桥杯 数独
- typedef使用
- matlab学习之一些常用函数(3)
- RobHess的SIFT算法实现介绍
- hdu 6011 Lotus and Characters
- padding-top 百分比黑知识
- Tengine编译记录
- ZCMU—1893
- JAVA基本基础
- 【知识了解】RFID、4Gmodule、Lora、
- JDBC:PreparedStatement
- 由于默认网关导致oracle 10g rac vip无法启动
- HBase最佳实践-写性能优化策略