Lotus and Characters__HDU6011
来源:互联网 发布:proe散热模拟软件 编辑:程序博客网 时间:2024/06/18 18:54
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 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.
Output For each test case.output one line containing a single integer,denoting the answer.
Since it's valid to construct an empty string,the answer is always
。
For each test case,first line is an integer
#include <iostream>#include<cstdio>#include<cstring>#include <algorithm>using namespace std;typedef struct{ int v,c;}cha;int cmp(const cha&a,const cha&b){ if(a.v<b.v) return 1; return 0;}int main(){ int T; scanf("%d",&T); for(int i=0;i<T;i++){ int n,k=-1; scanf("%d",&n); cha *p=new cha[n]; for(int i=0;i<n;i++){ int a,b; scanf("%d%d",&a,&b); k++; p[k].v=a,p[k].c=b; } sort(p,p+k+1,cmp); int tp=0,s=0; for(int i=k;i>=0;i--){ for(int j=1;j<=p[i].c;j++){ tp+=p[i].v; if(tp<=0) break; s+=tp; } if(tp<=0)break; } printf("%d\n",s); delete[]p; } return 0;}
从题目来看,我们要讲字符按价值大小进行排序,再从大价值的字符开始累加,由于有负数的字符,所以可以从tp(每添加一个字符所带来的收益)大于0作为循环的条件。 0 0
- Lotus and Characters__HDU6011
- Lotus and Characters
- Lotus and Characters
- Lotus and Horticulture
- hdu6011 Lotus and Characters
- Lotus and Horticulture
- HDU6011 Lotus and Characters
- Lotus and Characters
- Lotus and Characters
- Lotus and Characters
- Lotus and Characters
- HDU6011 Lotus and Characters
- hdu----Lotus and Characters
- Lotus and Characters
- hdu6011 -Lotus and Characters
- HDU 6011 Lotus and Characters
- 【HDU 6011 Lotus and Characters】
- HDU6012 Lotus and Horticulture 扫描
- appium自动化_登录apk代码
- Easyui dialog中嵌入iframe
- 在MathType编辑乘号的方法介绍
- 自己封装的 —— 三级缓存
- python scrapy 去重
- Lotus and Characters__HDU6011
- js跳转页面方法汇总。
- Android View的事件体系
- SpringBoot集成Swagger2
- hdu 4908 以k为中位数的子序列计数
- 安卓开发笔记——关于图片的三级缓存策略(内存LruCache+磁盘DiskLruCache+网络Volley)
- 八皇后计算
- C++知识点--继承
- 数据挖掘-目录-集成算法