codeforces 492C. Vanya and Exams 解题报告
题目链接:http://codeforces.com/problemset/problem/492/C
题目意思:给出 3 个整数:n, r, avg。然后有 n 行,每行有两个数:第 i 行有 ai 和 bi。表示如果写 bi 篇文章那么可以在 ai 这个分数上增加 1 分。可以增加好多次,但是前提是加完得到的分数不能超过 r。要使得 n 个exam 的分数平均分至少达到avg时需要写的最少文章是多少篇。
解决方法很简单,贪心即可。
我们当然希望写的文章越少越好,所以先对文章从小到大排序。然后尽量往这个exam的分数加分,直到到达上限 r 。最后的情况是不需要到达 r 时,就把剩余的加上即可,就是代码中的else 循环的:ans += need * exam[i].b;
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std; typedef __int64 LL;
const int maxn = 1e5 + ;
struct node
{
LL a, b;
}exam[maxn]; LL cmp(node x, node y)
{
if (x.b == y.b)
return x.a < y.a;
return x.b < y.b;
} int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
LL n, r, avg;
LL has, need, needed; while (scanf("%I64d%I64d%I64d", &n, &r, &avg) != EOF)
{
has = ;
for (__int64 i = ; i < n; i++)
{
scanf("%I64d%I64d", &exam[i].a, &exam[i].b);
has += exam[i].a;
} sort(exam, exam+n, cmp);
LL needed = 1ll * avg * n;
LL need = 1ll*needed - 1ll*has;
if (need <= )
printf("0\n");
else
{
LL ans = ;
for (LL i = ; i < n && need > ; i++)
{
if ((r-exam[i].a) <= need)
{
ans += (r-exam[i].a) * exam[i].b;
need -= r-exam[i].a;
}
else
{
ans += need * exam[i].b;
need -= need;
}
}
printf("%I64d\n", ans);
}
}
return ;
}
codeforces 492C. Vanya and Exams 解题报告的更多相关文章
- CodeForces 492C Vanya and Exams (贪心)
C. Vanya and Exams time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- codeforces 492B. Vanya and Lanterns 解题报告
题目链接:http://codeforces.com/problemset/problem/492/B #include <cstdio> #include <cstdlib> ...
- Codeforces Educational Round 92 赛后解题报告(A-G)
Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...
- codeforces 476C.Dreamoon and Sums 解题报告
题目链接:http://codeforces.com/problemset/problem/476/C 题目意思:给出两个数:a 和 b,要求算出 (x/b) / (x%b) == k,其中 k 的取 ...
- Codeforces Round #382 (Div. 2) 解题报告
CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...
- codeforces 479C Exams 解题报告
题目链接:http://codeforces.com/problemset/problem/479/C 题目意思:简单来说,就是有个人需要通过 n 门考试,每场考试他可以选择ai, bi 这其中一个时 ...
- codeforces 507B. Amr and Pins 解题报告
题目链接:http://codeforces.com/problemset/problem/507/B 题目意思:给出圆的半径,以及圆心坐标和最终圆心要到达的坐标位置.问最少步数是多少.移动见下图.( ...
- codeforces 500B.New Year Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...
- codeforces B. Xenia and Ringroad 解题报告
题目链接:http://codeforces.com/problemset/problem/339/B 题目理解不难,这句是解题的关键 In order to complete the i-th ta ...
随机推荐
- Linux下的一个图形管理工具webmin
这个工具其实我在两年前的小白时期还是经常用的,因为那时候对Linux比较陌生在为数server的时候帮了我很多工作,现在周末外面下雨,闲来无事莫名其妙的想起他来. 工具优点:最大特点是他是脚本安装 不 ...
- django学习<一>:安装
这两天打算摸索下和python相关的东西,然后正好小伙伴有个关于网站的任务,就怀着好奇的心态了解了下,然后就很自然地开始涉及django的问题. 首先就是django安装的问题,想不到第一步就出问题了 ...
- php5调用web service
工作中需要用php调用web service接口,对php不熟,上网搜搜,发现关于用php调用web service的文章也不多,不少还是php4里用nusoap这个模块调用的方法,其实php5里已经 ...
- golang笔记——数据类型
25个关键字 程序声明:import, package 程序实体声明和定义:chan, const, func, interface, map, struct, type, var 程序流程控制:go ...
- Python XML解析(转载)
Python XML解析 什么是XML? XML 指可扩展标记语言(eXtensible Markup Language). 你可以通过本站学习XML教程 XML 被设计用来传输和存储数据. XML是 ...
- iOS: ARC & MRC下string内存管理策略探究
ARC & MRC下string内存管理策略探究 前两天跟同事争论一个关于NSString执行copy操作以后是否会发生变化,两个人整了半天,最后写代码验证了一下,发现原来NSString操作 ...
- uva10870 递推关系Recurrences
Consider recurrent functions of the following form:f(n) = a1f(n - 1) + a2f(n - 2) + a3f(n - 3) + : : ...
- js 日期处理,json处理
模块化js :requirejshttp://www.requirejs.cn/ 好用的日期控件:http://www.bootcss.com/p/bootstrap-datetimepicker/i ...
- CTSC2016游记
打了几天酱油.. day1 3分滚..考场上打了5+0+3,5文件名挂了. (因为5那题我会nlog^3n做法,然而只是暴力分而已.(被KDTree艹过去的一题)) 提答xjb玩了三分,原因是exgc ...
- IDEA 进入到项目的系统文件路径
选中项目,单击右键,在弹出的菜单中点击file path