zoukankan      html  css  js  c++  java
  • B题 Before an Exam

    Description

    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 Input

    Input
    1 48 
    5 7
    Output
    NO
    Input
    2 5 
    0 1
    3 5
    Output
    YES 
    1 4

    题意:

    AC代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     int mintime[32]={0},maxtime[32];
     9     int n,sum;
    10     cin>>n>>sum;
    11     int i,j;
    12     for(i=1;i<=n;i++){
    13         cin>>mintime[i%n]>>maxtime[i%n];
    14         sum-=mintime[i%n];
    15     }
    16     if(sum<0){cout<<"NO"<<endl;return 0;}
    17     if(sum==0){
    18         cout<<"YES"<<endl;
    19         for(i=1;i<=n;i++)cout<<mintime[i%n]<<" ";
    20         cout<<endl;return 0;
    21     }
    22     i=1;
    23     int k=sum,s=0;
    24     while(1){
    25         if(mintime[i]<maxtime[i]){
    26             mintime[i]++;
    27             sum--;
    28             if(sum==0){
    29                 cout<<"YES"<<endl;
    30                 for(j=1;j<=n;j++)cout<<mintime[j%n]<<" ";
    31                 cout<<endl;return 0;
    32             }
    33         }
    34         if(k==sum){
    35             s++;
    36             if(s==n+1)break;
    37         }
    38         else {k=sum;s=0;}
    39         i++;
    40         i%=n;
    41     }
    42     cout<<"NO"<<endl;
    43     return 0;
    44 }
    View Code
  • 相关阅读:
    [杂七杂八][高效程序员应该养成的七个习惯][转载]
    链表反转,只用两次头插法就实现了 hello
    清除空格 hello
    单词计数 hello
    单词查找程序 hello
    sdut 超级玛丽
    ural Episode Nth: The Jedi Tournament(缩点+建树)
    sudt 括号东东(模拟题)
    ural Pilot Work Experience(dfs + bfs )
    ural Team building(强连通分支)
  • 原文地址:https://www.cnblogs.com/zhangchengbing/p/3233449.html
Copyright © 2011-2022 走看看