题目链接: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 解题报告的更多相关文章

  1. codeforces C1. The Great Julya Calendar 解题报告

    题目链接:http://codeforces.com/problemset/problem/331/C1 这是第一次参加codeforces比赛(ABBYY Cup 3.0 - Finals (onl ...

  2. codeforces B. Eugeny and Play List 解题报告

    题目链接:http://codeforces.com/problemset/problem/302/B 题目意思:给出两个整数n和m,接下来n行给出n首歌分别的奏唱时间和听的次数,紧跟着给出m个时刻, ...

  3. codeforces 433C. Ryouko's Memory Note 解题报告

    题目链接:http://codeforces.com/problemset/problem/433/C 题目意思:一本书有 n 页,每页的编号依次从 1 到 n 编排.如果从页 x 翻到页 y,那么| ...

  4. 【LeetCode】860. Lemonade Change 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  5. codeforces 556B. Case of Fake Numbers 解题报告

    题目链接:http://codeforces.com/problemset/problem/556/B 题目意思:给出 n 个齿轮,每个齿轮有 n 个 teeth,逆时针排列,编号为0 ~ n-1.每 ...

  6. codeforces 510B. Fox And Two Dots 解题报告

    题目链接:http://codeforces.com/problemset/problem/510/B 题目意思:给出 n 行 m 列只有大写字母组成的字符串.问具有相同字母的能否组成一个环. 很容易 ...

  7. codeforces 505A. Mr. Kitayuta's Gift 解题报告

    题目链接:http://codeforces.com/problemset/problem/505/A 题目意思:给出一个长度不大于10的小写英文字符串 s,问是否能通过在字符串的某个位置插入一个字母 ...

  8. codeforces 499A.Inna and Pink Pony 解题报告

    题目链接:http://codeforces.com/problemset/problem/499/A 题目意思:有两种按钮:1.如果当前观看的时间是 t,player 可以自动处理下一分钟,姑且理解 ...

  9. codeforces 374A Inna and Pink Pony 解题报告

    题目链接:http://codeforces.com/problemset/problem/374/A 题目意思:给出一个 n 行  m 列 的棋盘,要将放置在坐标点为(i, j)的 candy 移动 ...

随机推荐

  1. 结构体和类中属性定义需要static地方

    private function Readxxx:Integer;static; public class property XXX:Integer read ReadXXx; Txxx =recor ...

  2. 【spring boot】注解@SpringBootApplication 相当于 @Configuration、@EnableAutoConfiguration 、 @ComponentScan 三个的作用

    注解@SpringBootApplication 相当于 @Configuration.@EnableAutoConfiguration . @ComponentScan 三个的作用 代码示例:Git ...

  3. 一天时间用OpenFire打造自己的IM聊天工具

    Openfire采用Java开发,开源的实时协作(RTC)服务器基于XMPP(Jabber)协议.Openfire安装和使用都非常简单,并利用Web进行管理.单台服务器可支持上万并发用户. 好友界面 ...

  4. Mysql的四种key

    我们看到Key那一栏,可能会有4种值,即 '','PRI','UNI','MUL'1. 如果Key是空的, 那么该列值的可以重复, 表示该列没有索引, 或者是一个非唯一的复合索引的非前导列2. 如果K ...

  5. 需要配置执行path?no

    下面的代码以管理员权限运行即可,保存为bat 2018/2/6(basic) - 初始化版本 @echo off :continue echo 输入exit退出 set /p My_PATH=请输入要 ...

  6. vue 避免渲染时闪烁

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  7. LeetCode – Copy List with Random Pointer

    A linked list is given such that each node contains an additional random pointer which could point t ...

  8. 学会读懂 MySql 的慢查询日志

    在前边的博客<何时.怎样开启 MySql 日志?>中,我们了解到了怎样启用 MySql 的慢查询日志. 今天我们来看一下怎样去读懂这些慢查询日志.在跟踪慢查询日志之前.首先你得保证最少发生 ...

  9. 专訪阿里陶辉:大规模分布式系统、高性能server设计经验分享

    http://www.csdn.net/article/2014-06-27/2820432 摘要:先后就职于在国内知名的互联网公司,眼下在阿里云弹性计算部门做架构设计与核心模块代码的编写,主要负责云 ...

  10. UVA - 11354Bond最小生成树,LCA寻找近期公共祖先

    看懂题目意思.他的意思是求将全部的城市走一遍,危急度最小.而且给 你两个s,t后让你求在走的时候,从s到t过程中危急度最大的值,并输出它, 然后就是怎样攻克了,这个题目能够说简单,也能够说难 通过思考 ...