zoukankan      html  css  js  c++  java
  • sicily 6768. Log Books

    模拟赛第二题,难度应该是倒数第三……

    看样例输入很晕,其实看懂了还是挺简单的,因为没有跨0点的驾驶记录

    要设计能PASS的测试用例的话会很痛苦……=。=

    Description
    Learner drivers need to complete 50 hours of supervised driving with at least 10 hours, or more, of night driving included in the total amount. Each learner must keep a log book of their supervised driving experience with each entry containing the starting and finishing time for each driving experience.
    Poirot-the-inspector has been given the duty of checking the log books and verifying that the driving times add up to the required values and that no single driving experience exceeds 2 hours. If more than, or equal to, half the length of one driving experience occurs during the night (before sunrise or after sunset), then the whole time counts towards night driving. For example, driving from 04:50 to 06:10 on a day when sunrise is at 05:30 counts as night driving.
    However, Poirot has never been good with numbers and he is requesting assistance with this duty. Your task is to write a program that reads a learner's log book and checks that the required driving times have been completed without violating the 2 hour length rule.

    Input
    The input consists of a number of test cases. The description for each test case starts with an integer N, on a line by itself, that represents the number of entries in one log book. 25 <= N <= 300. Each of the following N lines contains a record of one driving experience with four times representing sunrise, sunset, and the starting and finishing time in that order. The starting time is strictly smaller than the finishing time. A single space separates the times and each time has a value between 00:00 (midnight) and 23:59 (one minute to midnight), inclusive. A line with a zero by itself terminates the input and is not to be processed.

    Output
    The output for each log book consists of the string PASS if the required driving times have been completed without violating the 2 hour length rule. Otherwise, print the string NON.

    View Code
     1 #include<stdio.h>
     2 int main()
     3 {
     4     int risehh, risemm;
     5     int sethh, setmm;
     6     int starthh, startmm;
     7     int endhh, endmm;
     8     int length, start, end,rise, set;
     9     int night = 0, total = 0;
    10     int n;
    11     int ok;
    12     
    13     while ( scanf("%d", &n) && n != 0 )
    14     {
    15         ok = 1;
    16         total = 0;
    17         night = 0;
    18         
    19         while ( n-- )
    20         {
    21             scanf("%d:%d", &risehh, &risemm);
    22             scanf("%d:%d", &sethh, &setmm);
    23             scanf("%d:%d", &starthh, &startmm);
    24             scanf("%d:%d", &endhh, &endmm);
    25             
    26             length = (endhh - starthh)*60 + (endmm - startmm);
    27             
    28             start = starthh*60 + startmm;
    29             end = endhh*60 + endmm;
    30             rise = risehh*60 + risemm;
    31             set = sethh*60 + setmm;
    32             
    33             if(length >= 120)
    34             {
    35                 ok = 0;
    36             }
    37             
    38             if( start + length/2 <= rise || end - length/2 >= set )
    39             {
    40                 night += length;
    41             }
    42         
    43             total += length;
    44         }
    45         
    46         if ( night < 600 )
    47             ok = 0;
    48         if( total < 3000)
    49             ok = 0;
    50             
    51         if ( ok )
    52             printf("PASS\n");
    53         else
    54             printf("NON\n");
    55     }
    56     
    57     return 0;
    58 }
  • 相关阅读:
    趣学算法:一场说走就走的旅行 (最短路)
    趣学算法:一场说走就走的旅行 (最短路)
    计蒜客:节食的限制(01背包)
    计蒜客:节食的限制(01背包)
    计蒜客:箱子剩余空间(01背包)
    计蒜客:箱子剩余空间(01背包)
    计蒜客:汽车费用(完全背包)
    计蒜客:汽车费用(完全背包)
    计蒜客: 等和的分隔子集 (01背包)
    .Cannot create an NSPersistentStoreCoordinator with a nil model
  • 原文地址:https://www.cnblogs.com/joyeecheung/p/2813744.html
Copyright © 2011-2022 走看看