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 ...
随机推荐
- A simple Snippet in ST2
Reference: http://web-design-weekly.com/2012/07/03/snippets-in-sublime-text-2/ A sample - cofirm (To ...
- PHP中获取内网用户MAC地址(WINDOWS/linux)的实现代码
做一个内网根据MAC地址自动登录的应用,在WINDOW 2003可以正常使用,函数如下 复制代码 代码如下: function ce_getmac() { if(PHP_OS == 'WINNT' ...
- call() 和 apply() ----预定义的函数方法
- Linux 开机启动方式设置 inittab 详解,开机直接进入“命令行”模式
Linux下的 /etc/inittab 中的英文解释: This file describes how the INIT process should set up the system in a ...
- mac 下 xampp 多域名 多站点 多虚拟主机 配置
前言:最近用mac工作了,需要搭建个调试前段程序的站点,选了xampp,需求是能同时运行多个站点,多个域名,目录自定义,网上找了好多资料,都感觉有些不符合心意,且复制文确实很多,甚至有些没实践过的在乱 ...
- mysql 修改表结构
alter table 表名 modify column 字段名 varchar(数量); 将varchar(50)改为255 alter table 表名 modify column 字段名 var ...
- EF初接触01
自动属性:{get;set} 隐式类型 var, dynamic var: 隐式的类型推断出来,在编译阶段把Var换成对应的实际的类型 所以只应用在编译之间, 在运行阶段是和实际类型意义的 dyna ...
- php的字符串转2进制函数
<?php $file1 = '16.jpg'; $file2 = 'test.txt'; $file3 = '47.jpg'; $size = filesize($file1); echo ' ...
- 理解js中this的指向
学习自原文 http://www.cnblogs.com/pssp/p/5216085.html后的一点小结(原文作者总结的很棒^_^)! 关于js中this的指向,在函数定义的时候还无法 ...
- createElement() 创建元素 appendChild()添加元素
Javascript window 对象的document.createElement() 方法.语法及其使用. 1.方法 创建一个新的html元素对象,并可返回一个Element 对象,新创建的El ...