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 移动 ...
随机推荐
- PyTorch框架+Python 3面向对象编程学习笔记
一.CNN情感分类中的面向对象部分 sparse.py super(Embedding, self).__init__() 表示需要父类初始化,即要运行父类的_init_(),如果没有这个,则要自定义 ...
- php curl xml传输和转换
<?php /** * API * User: sgfoot * Date: 2017/3/20 * Time: 18:05 */ class apiCurl { private $config ...
- WCF中常用的binding方式 z
WCF中常用的binding方式: BasicHttpBinding: 用于把 WCF 服务当作 ASMX Web 服务.用于兼容旧的Web ASMX 服务. WSHttpBinding: 比 Bas ...
- linux内核I2C子系统学习(三)
写设备驱动: 四部曲: 构建i2c_driver 注册i2c_driver 构建i2c_client ( 第一种方法:注册字符设备驱动.第二种方法:通过板文件的i2c_board_info填充,然后注 ...
- C# 将long类型写入二进制文件用bw.Write(num);将其读出用long num= br.ReadInt64();
理由: 因为long类型是 System.Int64 (长整型,占 8 字节,表示 64 位整数,范围大约 -(10 的 19) 次方 到 10 的 19 次方) 而long BinaryReader ...
- PS 如何用制作键盘图标
1 键盘可以大致分为笔记本键盘和台式机键盘,颜色一般是黑色或白色.不同的键盘,拍摄角度不同(俯视或者平视)得到的效果也不一样.一般我们根据自己需要得到需要的键盘形式.比如下面别人制作的一套立体键盘,立 ...
- 数据库 ""和null的在java 持久化中的区别
如果查找的时候查找了dealerCarType中a字段,但是数据库中a字段为"",那么持久化结果dealerCarType.getA() 结果为""; 如果查找 ...
- struts1.3中使用DispatchAction的一个问题
近期做项目发现我们公司的项目是用struts1写的,在多方百度下,总有理解了struts1.3的DispatchAction的使用方法 一:struts.xml文件的配置 <?xml versi ...
- Python--数据类型整理
数据类型整理-------------------------------------------------------------------------------------------- ...
- kubernetes容器探针检测
系列目录 kubernetes提供了livenessProbe(可用性探针)和readinessProbe(就绪性探针)对容器的健康性进行检测,当然这仅仅简单的关于可用性方面的探测,实际上我们不仅仅要 ...