CodeForces 379C -- D - New Year Ratings Change
来源:互联网 发布:验证yum源修改 编辑:程序博客网 时间:2024/05/27 06:50
学长们说是签到题难度,瞬间就心凉了!
大体题意:
给你一个n,代表有n个人,没个人想要至少a[i]分数,但分配分数又要各不相同!求最后结果!
思路:
向舍友学习了一下方法!自己做总超时!
建立一个结构体,记录id编号,和初始值!
刚上来先按初始值排序!
然后从i = 1 到 i = n-1 遍历 发现比前一个小,就变为前一个的加1
最后在按编号排序输出答案就行了!
#include<cstdio>#include<cstring>#include<string>#include<algorithm>using namespace std;const int maxn = 300000 + 10;struct rating{int id,beg;}rat[maxn];bool cmp1(const rating&a,const rating &b){return a.beg < b.beg;}bool cmp2(const rating&a,const rating &b){return a.id < b.id;}int main(){int n;while(scanf("%d",&n) == 1){for (int i = 0; i < n; ++i){scanf("%d",&rat[i].beg);rat[i].id = i;}sort(rat,rat+n,cmp1);for (int i = 1; i < n; ++i){if (rat[i].beg <= rat[i-1].beg)rat[i].beg = rat[i-1].beg+1;}sort(rat,rat+n,cmp2);for (int i = 0 ;i < n; ++i){if (i)printf(" ");printf("%d",rat[i].beg);}printf("\n");}return 0;}
0 0
- CodeForces 379C -- D - New Year Ratings Change
- codeforces-379C. New Year Ratings Change
- Codeforces-379C-New Year Ratings Change
- Codeforces 379C New Year Ratings Change(模拟)
- 379C - New Year Ratings Change 贪心
- C. New Year Ratings Change
- C. New Year Ratings Change
- codeforce 379C New Year Ratings Change 题解
- codeforces 379CNew Year Ratings Change(MAP的用法)
- CodeForces 379D New Year Letter
- CodeForces 379 D. New Year Letter
- CodeForces Good Bye 2016 :C New Year and Rating、D New Year and Fireworks、E New Year and Old Subsequ
- Codeforces 379D. New Year Letter【动态规划、暴力枚举】
- codeforces 500D New Year Santa Network
- 【codeforces 750D】New Year and Fireworks
- [Codeforces goodbye2016] D. New Year and Fireworks
- Codeforces 750 D New Year and Fireworks
- Codeforces 500C New Year Book Reading
- 不可不知的CSS小技巧
- 解决root@localhost's password:localhost:permission denied,please try again
- 对c++11下新增字符编码格式转换函数的简单封装
- STL 算法接口及用法说明 (二)
- java几个小数取整例子
- CodeForces 379C -- D - New Year Ratings Change
- 移动端适配问题
- ORA-00132
- ORA-00214
- 网易笔试题编程题--小易的升级之路
- PHP中支持的原始数据类型和伪类型
- ORA-01172
- JS中的call、apply、bind方法
- 使用MyBatis的一个好习惯