codeforces C. New Year Ratings Change 解题报告
题目链接:http://codeforces.com/problemset/problem/379/C
题目意思:有n个users,每个user都有自己想升的rating。要解决的问题是给予每个人不同的rating,使得每个人rating不比他期望的rating小,即 安排的rating >= 他自己的希望的rating,还有一个条件就是 总rating之和要最小。
要想使得总rating最少,那么安排的rating要尽可能小。把rating从小到大排序。对最小的rating值当然就给予这个值,于是下一次安排的rating在这个值的基础下递增1(rmin+1),当下一个user期望的rating和这个值相同时,就把rmin+1分配给他,接着下一次安排的最小rating是rmin+2。当遇到期望的rating比这个安排的rating要大时,安排的rating恰好可以安排他所期望的,而下一次安排的rating的值是 他自己希望的rating+1
由于要按顺序把这些rating输出,还要附加一个id值表明这些user初始的位置。
| Time | Memory |
|---|
| 717 ms | 3500 KB |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = *1e5 + ; struct ratings
{
int id;
int ra;
int ans;
} exp[maxn]; int cmpid(ratings x, ratings y)
{
return x.id < y.id; // id从小到大排序
} int cmpra(ratings x, ratings y)
{
return x.ra < y.ra; // ra从小到大排序
} int main()
{
int i, n;
while (scanf("%d", &n) != EOF)
{
for (i = ; i <= n; i++)
{
scanf("%d", &exp[i].ra);
exp[i].id = i;
}
sort(exp+, exp+n+, cmpra);
int cur = exp[].ra;
for (i = ; i <= n; i++)
{
if (exp[i].ra <= cur)
{
exp[i].ans = cur;
cur++;
}
else
{
exp[i].ans = exp[i].ra;
cur = exp[i].ra + ;
}
}
sort(exp+, exp+n+, cmpid);
for (i = ; i < n; i++)
printf("%d ", exp[i].ans);
printf("%d\n", exp[i].ans);
}
return ;
}
参考人家写的,pair原来这么强大的!!! ^_^
| Time |
Memory |
|---|
| 171 ms | 3500 KB |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std; #define f first
#define s second
#define max(a, b) ((a) > (b) ? (a) : (b)) const int maxn = *1e5 + ;
pair<int, int> p[maxn];
int ans[maxn]; int main()
{
int i, n, cur;
while (scanf("%d", &n) != EOF)
{
for (i = ; i <= n; i++)
{
scanf("%d", &p[i].f);
p[i].s = i;
}
sort(p+, p+n+);
cur = ;
for (i = ; i <= n; i++)
{
cur = max(p[i].f, cur+);
ans[p[i].s] = cur;
}
for (i = ; i < n; i++)
printf("%d ", ans[i]);
printf("%d\n", ans[i]);
}
return ;
}
codeforces C. New Year Ratings Change 解题报告的更多相关文章
- codeforces C1. The Great Julya Calendar 解题报告
题目链接:http://codeforces.com/problemset/problem/331/C1 这是第一次参加codeforces比赛(ABBYY Cup 3.0 - Finals (onl ...
- codeforces B. Eugeny and Play List 解题报告
题目链接:http://codeforces.com/problemset/problem/302/B 题目意思:给出两个整数n和m,接下来n行给出n首歌分别的奏唱时间和听的次数,紧跟着给出m个时刻, ...
- codeforces 433C. Ryouko's Memory Note 解题报告
题目链接:http://codeforces.com/problemset/problem/433/C 题目意思:一本书有 n 页,每页的编号依次从 1 到 n 编排.如果从页 x 翻到页 y,那么| ...
- 【LeetCode】860. Lemonade Change 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- codeforces 556B. Case of Fake Numbers 解题报告
题目链接:http://codeforces.com/problemset/problem/556/B 题目意思:给出 n 个齿轮,每个齿轮有 n 个 teeth,逆时针排列,编号为0 ~ n-1.每 ...
- codeforces 510B. Fox And Two Dots 解题报告
题目链接:http://codeforces.com/problemset/problem/510/B 题目意思:给出 n 行 m 列只有大写字母组成的字符串.问具有相同字母的能否组成一个环. 很容易 ...
- codeforces 505A. Mr. Kitayuta's Gift 解题报告
题目链接:http://codeforces.com/problemset/problem/505/A 题目意思:给出一个长度不大于10的小写英文字符串 s,问是否能通过在字符串的某个位置插入一个字母 ...
- codeforces 499A.Inna and Pink Pony 解题报告
题目链接:http://codeforces.com/problemset/problem/499/A 题目意思:有两种按钮:1.如果当前观看的时间是 t,player 可以自动处理下一分钟,姑且理解 ...
- codeforces 374A Inna and Pink Pony 解题报告
题目链接:http://codeforces.com/problemset/problem/374/A 题目意思:给出一个 n 行 m 列 的棋盘,要将放置在坐标点为(i, j)的 candy 移动 ...
随机推荐
- 给button添加长按手势并侦测到此button
1, 添加手势 self.longPressRecognizer = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@ ...
- GOF 23种设计摩搜-建造者模式
• 场景: – 我们要建造一个复杂的产品.比如:神州飞船,Iphone.这个复杂的产品的创建.有这样 一个问题需要处理: • 装配这些子组件是不是有个步骤问题? – 实际开发中,我们所需要的对象构建时 ...
- Access自定义函数(人民币大写)
人民币大写函数:整数不超过13位. Public Function 人民币大写(A) As String Dim aa As String Dim bb As String Dim cc As Str ...
- less 项目实战
1.注释 less 的注释有两种方法,"/**/" 和 "//",前一种会在 css 文件中显示,后一种不会在 css 显示. 2.定义变量的方法:" ...
- IOS_DatePicker_PickerView_SegmentControl_键盘处理
H:/0712/01_UIController_MJViewController.m // MJViewController.m // 01-总结复习 // Created by apple on 1 ...
- Sencha Touch 之初接触
1.Sencha Touch开发与普通web开发有什么区别? Sencha Touch(为方便起见,本文后面一律简写为ST)页面的开发跟普通html页面相比,总体来说没有本质上的区别,只是引入了对ht ...
- struts1.3中使用DispatchAction的一个问题
近期做项目发现我们公司的项目是用struts1写的,在多方百度下,总有理解了struts1.3的DispatchAction的使用方法 一:struts.xml文件的配置 <?xml versi ...
- python(21)- python内置函数练习
题目一:用map来处理字符串列表啊,把列表中所有人都变成sb,比方alex_sbname=['alex','wupeiqi','yuanhao'] name=['alex','wupeiqi','yu ...
- 在没有安装access的电脑上读写.mdb文件
在微软官方下载MDAC access数据库访问组件即可
- 【HDOJ 5654】 xiaoxin and his watermelon candy(离线+树状数组)
pid=5654">[HDOJ 5654] xiaoxin and his watermelon candy(离线+树状数组) xiaoxin and his watermelon c ...