Codeforces 540B - School Marks (贪心)
来源:互联网 发布:网络链路冗余技术 编辑:程序博客网 时间:2024/06/05 22:53
第一次在CF上水题, 果断wa了好几发, 纪念一下,一发水题。
题意:有N门成绩, 已经告知你K门, 在保证N门总和小于X且中位数大于Y的情况, 让你求出剩下N-K门,
题解:
明显 要保证和越小越好, 插入的数字只有1和Y,在插的时候保证中位数合法。记录小于Y的值,然后用1和Y去补缺失的。简单题, 有一点小细节,wa了好几发
代码:
#include<stdio.h>
#include<string.h>
int minn(int a, int b)
{
if(a < b) return a;
return b;
}
int main()
{
int n, k, p, x, y, sum, big, sm, a;
while(scanf("%d", &n) != EOF)
{
sum = sm = 0;
scanf("%d%d%d%d", &k, &p, &x, &y);
for(int i = 0; i < k; i++)
{
scanf("%d", &a);
sum += a;
if(a < y) sm++;
}
if(sm > n/2) {printf("-1\n"); continue;}
sm = minn(n/2-sm, n-k), big = (n-k-sm);
sum += sm;
sum += (big * y);
if(sum > x) {printf("-1\n"); continue;}
else
{
int flag = 1;
for(int i = 1; i <= big; i++)
{
if(flag) printf("%d", y);
else printf(" %d",y);
flag = 0;
}
for(int i = 1; i <= sm; i++)
{
if(flag) printf("1");
else printf(" 1");
flag = 0;
}
printf("\n");
}
}
}
- Codeforces 540B - School Marks (贪心)
- [CodeForces 540B]School Marks[贪心]
- Codeforces 540B School Marks 【贪心构造】
- Codeforces 540B School Marks
- CodeForces 540B School Marks
- codeforces 540B School Marks
- Codeforces 540B - School Marks
- CodeForces 540B School Marks
- School Marks CodeForces - 540B
- Codeforces Round #301 (Div. 2) B. School Marks(贪心)
- codeforces B. School Marks
- codeforces B. School Marks
- cf 540b School Marks 贪心
- Codeforces Round #301 (Div. 2)B. School Marks//CodeForces - 540B 贪心
- CodeForces - 540B School Marks (数学思维题 中位数)
- Codeforces 540B - School Marks (思维)
- CF 301 B School Marks
- B. School Marks (CF #301 (Div. 2))
- javascript笔记:深入分析javascript里对象的创建(上)
- 送上最新鲜的互联网行业新闻-【2015-05-20】
- 如何修改github账号的用户名
- hdu 1829 A Bug's Life
- Spring MVC中@Repository、@Service、@Controller、@Compon的使用及区别
- Codeforces 540B - School Marks (贪心)
- uva 297
- Ehcache 整合Spring 使用页面、对象缓存
- C#中文转拼音
- javascript笔记:深入分析javascript里对象的创建(上)续篇
- 第十一周项目2 - 职员有薪水了
- 【LeetCode】012.Integer to Roman
- 浅谈凸优化问题中的Bregman迭代算法
- git忽略已经被提交的文件