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 ...
随机推荐
- 如何申请https证书、搭建https网站
如何申请https证书.搭建https网站 随着国内搜索引擎巨头百度启用全站https加密服务,全国掀起了网站https加密浪潮.越来越多的站点希望通过部署https证书来解决“第三方”对用户隐私的嗅 ...
- 【AngularJS】—— 4 表达式
前面了解了AngularJS的基本用法,这里就跟着PDF一起学习下表达式的相关内容. 在AngularJS中的表达式,与js中并不完全相同. 首先它的表达式要放在{{}}才能使用,其次相对于javas ...
- UML浅析
UML概述 UML (Unified Modeling Language)为面向对象软件设计提供统一的.标准的.可视化的建模语言.适用于描述以用例为驱动,以体系结构为中心的软件设计的全过程. UML模 ...
- SGU 495. Kids and Prizes
水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...
- oracle删除表以及清理表空间
若要彻底删除表,则使用语句:drop table <table_name> purge; 清除回收站里的信息 清除指定表:purge table <table_name>; 清 ...
- java 1.7
http://superuser.com/questions/740064/how-to-install-java-1-7-runtime-on-macos-10-9-mavericks sudo r ...
- 安装Sublime Text 3插件的方法
直接安装 安装Sublime text 3插件很方便,可以直接下载安装包解压缩到Packages目录(菜单->preferences->packages). 使用Package Contr ...
- oracle 彻底删除用户及表空间
1.删除表空间 可以先将其offline alter tablespace xxx offline; 将磁盘上的数据文件一同删除 drop tablespace xxx including conte ...
- 【转】关于URL编码/javascript/js url 编码/url的三个js编码函数
来源:http://www.cnblogs.com/huzi007/p/4174519.html 关于URL编码/javascript/js url 编码/url的三个js编码函数escape(),e ...
- 【转载】javaAgent 参数
-javaagent 这个JVM参数是JDK 5引进的. java -help的帮助里面写道: -javaagent:<jarpath>[=<options>] load Ja ...