Codeforces-540B-School Marks(思维贪心)
2018-02-06 12:28
363 查看
/** 题意: 给你n,k,p,x,y,五个数,分别表示小明要考n门课,现在已经考了k门课了,每门课的最高成绩为p,但小明有两个小要求。 1、小明考的n门课的总成绩不能超过x; 2、小明的n门课的成绩在排完序后,他的中位数要>=y。 问小明剩下的几门课要考多少分,若有多种情况,输出其中任意一种就行,如果不能满足两个条件,输出-1. 思路: 贪心,寻找有几门是小于y的,几门是等于y的,几门是大于y,要求总分最小,所以只需要补充1和y 。 */ #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn = 1000; int sorce[maxn]; int main() { int n,k,p,x,y; while(~scanf("%d%d%d%d%d",&n,&k,&p,&x,&y)) { int len = (n-1) / 2,low = 0,high = 0,sum = 0,cnt = 0; for(int i=1;i<=k;i++) { scanf("%d",&sorce[cnt]); if(sorce[cnt]<y) low++; else high++; sum += sorce[cnt]; cnt++; } if(low > len||sum > x) { printf("-1\n");continue;} else { if(high >= len+1) for(int i=1;i<=n-k;i++) sorce[cnt++] = 1,sum+=1; else { for(int i=1;i<=len - low;i++) sorce[cnt++] = 1,sum+=1; for(int i=1;i<=len+1-high;i++) sorce[cnt++] = y,sum+=y; } if(sum > x) printf("-1\n"); else { for(int i = k;i<n-1;i++) printf("%d ",sorce[i]); printf("%d\n",sorce[n-1]); } } } return 0; }
4000
相关文章推荐
- [CodeForces 540B]School Marks[贪心]
- Codeforces 540B - School Marks (贪心)
- Codeforces 540B - School Marks (思维)
- CodeForces 721D. Maxim and Array(贪心,思维题)
- Codeforces 478C Table Decorations【贪心】【思维】
- 【CodeForces - 849】C From Y to Y 【思维+构造+贪心】
- codeforces 500C New Year Book Reading (贪心,很好的思维题)
- CodeForces - 818B Permutation Game(贪心+思维)
- Codeforces 344C Rational Resistance【思维+贪心】
- Codeforces Round #301 (Div. 2)B. School Marks//CodeForces - 540B 贪心
- CodeForces - 808C-贪心-思维
- Codeforces 349B Color the Fence【贪心+思维】
- CodeForces - 827B High Load(贪心+思维)
- codeforces 232A Cycles 图论 贪心 思维
- codeforces-500【B思维】【C贪心】
- Codeforces 521A DNA Alignment【贪心+思维】
- Codeforces 526C - Om Nom and Candies (贪心 + 思维)
- codeforces-486【C-贪心-思维】【D-树状DP】
- 【CodeForces】337C - Quiz(贪心,思维)
- Codeforces 320E Kalila and Dimna in the Logging Industry【思维+贪心+斜率优化Dp】好题!