日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

A watermeten 《Before an Exam》

發布時間:2025/3/13 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 A watermeten 《Before an Exam》 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
這是第二次參加的網絡比賽,雖然是內部的,但也體會了一把比賽的感覺;題目比上次簡單多了,會做的也不少,現在把其中我做的問題拿出來分析一下: A. 《Watermelon》 time limit per test 1 second ? ? ??memory limit ? ? ?per test?64 megabytes input standard input output standard output

One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed?w?kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.

Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.

Input

The first (and the only) input line contains integer number?w?(1?≤?w?≤?100) — the weight of the watermelon bought by the boys.

Output

Print?YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and?NO?in the opposite case.

Sample test(s) input 8 output YES Note

For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).

這個問題實在太簡單了,當然是在能理解題意的前提下,呵呵,我也是用了很長時間才翻譯過來。

題意:兩個人買了一個西瓜,兩個人想把西瓜分成兩份,每一份都是偶數的重量,等不等分都可以,問他們是否能成功。

陷阱:考慮w=2的情況。

源代碼:

#include<iostream> using namespace std; int main() {int n;cin>>n;if(n==2)cout<<"NO";else if(n%2==0)cout<<"YES"<<endl;else cout<<"NO"<<endl;return 0; }

第二個問題:

B. 《Before an Exam》

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?dnumbers, 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 numbersminTimei,?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.

Sample test(s) input 1 48
5 7 output NO input 2 5
0 1
3 5 output YES
1 4


源代碼:
#include<iostream> using namespace std; int main() {int i,d,sum,s=0,w=0;int m[31],n[31],t[31];cin>>d>>sum;for(i=1;i<=d;i++) //輸入每天的Min和MAx,并算出最小值總和和最大值總和{cin>>m[i]>>n[i];s+=n[i];w+=m[i];}if(w>sum||s<sum)cout<<"NO";if(w<=sum&&s>=sum){cout<<"YES"<<endl; //最小值總和與Sum相等的情況if(w==sum)for(i=1;i<=d;i++)cout<<m[i]<<" ";else {for(i=1;i<=d;i++) //把第i 天可以補充的時間存起來{t[i]=n[i]-m[i];}int p=1;int e=m[1];while (w+t[p]<=sum) //從前往后補充時間{m[p]=n[p];w+=t[p];p++;}m[p]=m[p]+sum-w; for(i=1;i<=d;i++){cout<<m[i];if(i!=d)cout<<" ";}}}return 0; }

題目分析:題目也不是很難,大意是:Peter在 d 天之后有一場考試,他父母給他規定了一個復習的總時間Sum,Peter要自己制定一個學習計劃表,其中每一天都要包含這天學習的最少時間Mini 和最大時間 Maxi ,每一天學習時間 Mini<= timei <=Maxi 是否能達到 父母的規定,既在d 天里學習時間總和為Sum。

不能達到輸出“NO”;能達到輸出“YES”和每天的學習時間(一種情況即可)。

思路:知道每天的最小時間和最大時間,那么 如果最小時間總和大于Sum,或者最大時間總和小于Sum,那么不能達到要求。如果Sum在最小值總和 與最大值總和之間,那么符合;

? ? ? 我輸出的一種情況是:先比較最小值總和與Sum的大小關系,如果相等,那么輸出即可,如果不等,那么從前至后依次補充時間數,直到滿足為止,注意,最后補充的那一天要特殊處理;而后輸出即可;

?

?

?

?

?

?

轉載于:https://www.cnblogs.com/sdauyqy/p/3235958.html

總結

以上是生活随笔為你收集整理的A watermeten 《Before an Exam》的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。