codeforce 4B(思维水题)
2017-05-26 11:23
399 查看
Tomorrow Peter has a Biology exam. He does not like this subject much, but d days ago he learnt that he would have to take this exam. Peter's strict parents made him prepare for the exam immediately, for this purpose
he has to study not less than minTimei and not more than maxTimei hours per each i-th
day. Moreover, they warned Peter that a day before the exam they would check how he has followed their instructions.
So, today is the day when Peter's parents ask him to show the timetable of his preparatory studies. But the boy has counted only the sum of hours sumTime spent him on preparation, and now he wants to know if he can
show his parents a timetable sсhedule with d numbers, where each number sсhedulei stands for the time
in hours spent by Peter each i-th day on biology studies, and satisfying the limitations imposed by his parents, and at the same time the sum total of all schedulei should
equal to sumTime.
Input
The first input line contains two integer numbers d, sumTime (1 ≤ d ≤ 30, 0 ≤ sumTime ≤ 240) — the amount of days, during which Peter studied, and the total amount
of hours, spent on preparation. Each of the following d lines contains two integer numbers minTimei, maxTimei (0 ≤ minTimei ≤ maxTimei ≤ 8),
separated by a space — minimum and maximum amount of hours that Peter could spent in the i-th day.
Output
In the first line print YES, and in the second line print d numbers (separated by a space), each of the numbers — amount of hours, spent by Peter on preparation in the corresponding
day, if he followed his parents' instructions; or print NO in the unique line. If there are many solutions, print any of them.
Example
Input
Output
Input
Output
/*题意:给你一个d表示前d天,给你一个sumtime表示应该复习的时间。接下来d行表示每天的最少复习时间和最多复习时间,你可以复习时间在这个区间内。题意在考试前d天开始复习,判断是否存在每天复习时间加起来等于sumtime,并打印每天复习时间*/
/*思路:按照每天最小时间复习加起来,如果小于sumtime,那么总的最小时间减去第一天的复习时间加上选第一天时间区间的其他数如果相等输出,如果加上第一天最大时间任然小于那么第一天复习时间就为最大值,继续向第二天枚举,以此类推找到最大的。数字小直接暴力(注意特判若最小天数的和或最大天数的和恰好等于sumtime)(第一次想复杂了写了好多)*/
he has to study not less than minTimei and not more than maxTimei hours per each i-th
day. Moreover, they warned Peter that a day before the exam they would check how he has followed their instructions.
So, today is the day when Peter's parents ask him to show the timetable of his preparatory studies. But the boy has counted only the sum of hours sumTime spent him on preparation, and now he wants to know if he can
show his parents a timetable sсhedule with d numbers, where each number sсhedulei stands for the time
in hours spent by Peter each i-th day on biology studies, and satisfying the limitations imposed by his parents, and at the same time the sum total of all schedulei should
equal to sumTime.
Input
The first input line contains two integer numbers d, sumTime (1 ≤ d ≤ 30, 0 ≤ sumTime ≤ 240) — the amount of days, during which Peter studied, and the total amount
of hours, spent on preparation. Each of the following d lines contains two integer numbers minTimei, maxTimei (0 ≤ minTimei ≤ maxTimei ≤ 8),
separated by a space — minimum and maximum amount of hours that Peter could spent in the i-th day.
Output
In the first line print YES, and in the second line print d numbers (separated by a space), each of the numbers — amount of hours, spent by Peter on preparation in the corresponding
day, if he followed his parents' instructions; or print NO in the unique line. If there are many solutions, print any of them.
Example
Input
1 48 5 7
Output
NO
Input
2 5 0 1 3 5
Output
YES 1 4
/*题意:给你一个d表示前d天,给你一个sumtime表示应该复习的时间。接下来d行表示每天的最少复习时间和最多复习时间,你可以复习时间在这个区间内。题意在考试前d天开始复习,判断是否存在每天复习时间加起来等于sumtime,并打印每天复习时间*/
/*思路:按照每天最小时间复习加起来,如果小于sumtime,那么总的最小时间减去第一天的复习时间加上选第一天时间区间的其他数如果相等输出,如果加上第一天最大时间任然小于那么第一天复习时间就为最大值,继续向第二天枚举,以此类推找到最大的。数字小直接暴力(注意特判若最小天数的和或最大天数的和恰好等于sumtime)(第一次想复杂了写了好多)*/
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; int d, sumtime; struct node{ int s, e, index; }day[50]; void print() { for(int i = 0; i < d - 1; i++) printf("%d ", day[i].s); printf("%d\n", day[d-1].s); return ; } int main() { while(scanf("%d%d", &d, &sumtime) != EOF){ int sums = 0; int sume = 0; for(int i = 0; i < d; i++){ scanf("%d%d", &day[i].s, &day[i].e); day[i].index = i + 1; sums += day[i].s; sume += day[i].e; } int flag = 0; if(sums <= sumtime && sume >= sumtime){ printf("YES\n"); flag = 1; } else if(sumtime < sums || sumtime > sume){ printf("NO\n"); continue; } int flag1 = 0; if(flag){ if(sums == sumtime){ print(); flag1 = 1; } if(flag1) continue; if(sume == sumtime){ for(int i = 0; i < d; i++) day[i].s = day[i].e; //因为我始终跟新的一天最少的复习时间 print(); flag1 = 1; } if(flag1) continue; if(sums < sumtime && sume > sumtime){ for(int i = 0; i < d; i++){ if(day[i].s == day[i].e) continue; for(int j = day[i].s; j < day[i].e;){ sums -= day[i].s; j = j + 1; sums += j; day[i].s = j; if(sums == sumtime) print(); } } } } } }
相关文章推荐
- hdoj 1229 还是A+B(简单水题,但是因为思维不够活跃,一开始做的很麻烦)
- codeforce 839A Arya and Bran(水题)
- codeforce-501【B思维&&map】【C思维&&树】
- codeforce 315B Sereja and Array 【水题,封顶距离统计 OR 线段树延迟更新】
- bzoj2296: 【POJ Challenge】随机种子(思维题/水题)
- (HDU 5922)Minimum’s Revenge 思维水题 <2016CCPC东北地区大学生程序设计竞赛 - 重现赛 >
- Codeforce 894B Ralph And His Magic Field (思维+快速幂)
- HDU 6016 Count the Sheep(思维水题)
- HDU 2674 N!Again(数学思维水题)
- 水题其实也能反映思维的严谨性:USACO The Tamworth Two
- HDU 4442 Physical Examination【水题】【思维题】
- 贪心+思维策略 - codeforce 839B Game of the Rows
- (HDU 5924)Mr. Frog’s Problem 思维水题 <2016CCPC东北地区大学生程序设计竞赛 - 重现赛 >
- Codeforce-152C-Pocket Book(排列组合+思维)
- HDU 5670 Machine(水题锻炼思维)
- hpu暑假训练C - Patrick and Shopping 【思维】&&【水题】
- 51nod 1435 位数阶乘 (思维水题)
- (HDU 5744)Keep On Movin <回文数,思维水题> 2016 Multi-University Training Contest 2
- HDOJ/HDU 1256 画8(绞下思维~水题)
- hpuoj【1188】Pесторан【思维】&&【水题】