BestCoder Round #91-A .Lotus and Characters(贪心)
来源:互联网 发布:人类登月是真是假 知乎 编辑:程序博客网 时间:2024/06/08 01:16
记录一个菜逼的成长。。
题目链接
有中文题面。
PS:感觉自己还是太年轻,套路还是太少。。orz
官方题解:
根据排序不等式,显然应该把字母从小往大放。 一种错误的做法是把正权值的字母取出来从前往后放。错误是因为负权的也可能出现在答案中:放在最前面来使后面每个字母的贡献都增加。 正确的做法是把字母从大往小从后往前放,如果加入该字母后答案变劣就停下来。
考虑到要放的字母对整个串的贡献,放前后进行比较。
#include <cstdio>#include <iostream>#include <algorithm>using namespace std;typedef long long LL;typedef pair<int,int> PII;const int maxn = 30 + 10;PII a[maxn];int main(){ ios::sync_with_stdio(false); cin.tie(0); int T;cin>>T; while(T--){ int n,tot = 0; cin>>n; for( int i = 1; i <= n; i++ ){ cin>>a[i].first>>a[i].second; } int ans = 0,cnt = 0; sort(a+1,a+n+1); for( int i = n; i >= 1; i-- ){ for( int j = 0; j < a[i].second; j++ ){ cnt += a[i].first; if(cnt >= 0)ans += cnt; } } cout<<ans<<endl; } return 0;}
0 0
- BestCoder Round #91-A .Lotus and Characters(贪心)
- BestCoder#91Lotus and Characters
- BestCoder Round #91 1001 (HDU 6011 Lotus and Characters) 1002 (HDU 6012 Lotus and Horticulture)
- BestCoder Round #91-B.Lotus and Horticulture(尺取法)
- [Bestcoder Round#91][HDU6012] Lotus and Horticulture 排序
- Hdu 6011 Lotus and Characters【贪心+暴力】
- BestCoder#91Lotus and Horticulture
- HDU 6011 BC 91 Lotus and Characters
- Lotus and Characters
- Lotus and Characters
- hdu6011 Lotus and Characters
- HDU6011 Lotus and Characters
- Lotus and Characters
- Lotus and Characters
- Lotus and Characters
- Lotus and Characters
- HDU6011 Lotus and Characters
- hdu----Lotus and Characters
- JAVA常用排序算法
- Java String endsWith()方法
- Objective-C 自动生成文档工具:appledoc
- C++11 标准新特性:Defaulted 和 Deleted 函数
- H264编码原理以及I帧B帧P帧
- BestCoder Round #91-A .Lotus and Characters(贪心)
- 【JAVA秒会技术之异常解决】Dmaven.multiModuleProjectDirectory system propery is not set
- 扫描二维码简单实现Zxing
- Linux内存管理机制控制--mallopt,避免大量小内存不回收问题
- 1 div+css布局初体验
- Android Fragment之间的通信
- java设计模式大话之命令模式
- jquery.datatables添加跳转到指定页
- Merkle tree在区块链中的应用