(贪心)School Marks -- codefor -- 540B】的更多相关文章

http://codeforces.com/problemset/problem/540/B School Marks Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he…
Little Vova studies programming to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests exceeds value x, then his classmates notice how smart h…
题意:先给定5个数,n,  k, p, x, y.分别表示 一共有 n 个成绩,并且已经给定了 k 个,每门成绩 大于0 小于等于p,成绩总和小于等于x, 但中位数大于等于y.让你找出另外的n-k个成绩. 析:利用贪心算法,首先是只能小于等于 p,也就是成绩越小越好, 然后中位数还得大于等于y,所以我们放的成绩只有两个,一个是1,另一个是y,那么是最优的, 所以每次只要判定这个就好,在判定的时候,要先排序,再找中位数,再就是每次放两个,如果n-k不是偶数,那么就放一个数,再进行. 代码如下: #…
题目链接:https://vjudge.net/contest/226823#problem/B Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write e…
题目传送门 /* 贪心:首先要注意,y是中位数的要求:先把其他的都设置为1,那么最多有(n-1)/2个比y小的,cnt记录比y小的个数 num1是输出的1的个数,numy是除此之外的数都为y,此时的numy是最少需要的,这样才可能中位数大于等于y */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> using namespace std; ; con…
http://codeforces.com/problemset/problem/540/B School Marks Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 540B Description Little Vova studies programming in an elite school. Vova and…
B. School Marks time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little Vova studies programming in an elite school. Vova and his classmates are supposed to writen progress tests, for each…
B. School Marks Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/problem/B Description Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test the…
B:School Marks 有n个测试,已经完成了k个,每个测试得分为a[i],接下来的分数不知道,让我们求出任何一个满足题意的即可,满足题意就是n个测试的得分总和<=x, 中位数>=y; 可以想一下先求出来已经有几个大于y的用cnt_y来表示,如果能构成满足题意的数必定至少有(n+1)/ 2个>=y 的数,所以我们可以添加 Y=(n+1)/ 2 - cnt_y 个 y,当然 Y < n - k;剩下的就是添加1了,这样就能 满足总和最小,如果这个总和还大于x那就不存在…
题目链接:http://codeforces.com/problemset/problem/540/B 题目意思:给出 k 个test的成绩,要凑剩下的 n-k个test的成绩,使得最终的n个test之和 <= x,且中位数 >= y.凑的时候   1 <= test的成绩 <= p 做得可辛苦了,泪~~~ 首先统计给出的 k 个test中有多少个是 >= y 的,然后从后往前补充,直到中位数是 k ,其余的数用 1 来填充. 无解结果需要考虑清楚.(1)n-k+sum_k…