zoukankan      html  css  js  c++  java
  • Electricity(简单)

    Electricity
    Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

    Description

    Download as PDF

    Martin and Isa stopped playing crazy games and finally got married. It's good news! They're pursuing a new life of happiness for both and, moreover, they're moving to a new house in a remote place, bought with most of their savings.

    Life is different in this new place. In particular, electricity is very expensive, and they want to keep everything under control. That's why Martin proposed to keep a daily record of how much electricity has been consumed in the house. They have an electricity meter, which displays a number with the amount of KWh (kilowatt-hour) that has been consumed since their arrival.

    At the beginning of each day they consult the electricity meter, and write down the consumption. Some days Martin does it, and some days Isa does. That way, they will be able to look at the differences of consumption between consecutive days and know how much has been consumed.

    But some days they simply forget to do it, so, after a long time, their register is now incomplete. They have a list of dates and consumptions, but not all of the dates are consecutive. They want to take into account only the days for which the consumption can be precisely determined, and they need help.

    Input

    The input contains several test cases. The first line of each test case contains one integer N indicating the number of measures that have been taken (2 ≤ N ≤ 103). Each of the N following lines contains four integers DMY and C, separated by single spaces, indicating respectively the day (1 ≤ D ≤ 31), month (1 ≤ M ≤ 12), year (1900 ≤ Y ≤ 2100), and consumption (0 ≤ C ≤ 106) read at the beginning of that day. These N lines are increasingly ordered by date, and may include leap years. The sequence of consumptions is strictly increasing (this is, no two different readings have the same number). You may assume that DM and Y represent a valid date.

    Remember that a year is a leap year if it is divisible by 4 and not by 100, or well, if the year is divisible by 400.

    The end of input is indicated by a line containing only one zero.

    Output

    For each test case in the input, your program must print a single line containing two integers separated by a single space: the number of days for which a consumption can be precisely determined, and the sum of the consumptions for those days.

    Sample input
    5
    9 9 1979 440
    29 10 1979 458
    30 10 1979 470
    1 11 1979 480
    2 11 1979 483
    3
    5 5 2000 6780
    6 5 2001 7795
    7 5 2002 8201
    8
    28 2 1978 112
    1 3 1978 113
    28 2 1980 220
    1 3 1980 221
    5 11 1980 500
    14 11 2008 600
    15 11 2008 790
    16 12 2008 810
    0
    
    Output for the sample input
    2 15
    0 0
    2 191
    

    ACM ICPC :: South American Regional 2008

    AC CODE:

    #include <iostream>
    #include <cstdio>
    using namespace std;
    
    struct Date
    {
        int d, m, y, c;
    }date[1001];
    int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    
    int main()
    {
        int N, cnt, sum, i, j;
        while(scanf("%d", &N) && N)
        {
            cnt = sum = 0;
            scanf("%d %d %d %d", &date[0].d, &date[0].m, &date[0].y, &date[0].c);
            N--;
            for(i = 1, j = 0; N--; i++, j++)
            {
                scanf("%d %d %d %d", &date[i].d, &date[i].m, &date[i].y, &date[i].c);
                if(date[i].y != date[j].y)
                {
                    if(date[i].m == 1 && date[j].m == 12 && date[i].d == 1 && date[j].d == 31)
                    {
                        sum += (date[i].c - date[j].c);
                        cnt++;
                    }
                }
                else
                {
                    if(date[i].m == date[j].m)
                    {
                        if(date[i].d - date[j].d == 1)
                        {
                            cnt++;
                            sum += (date[i].c - date[j].c);
                        }
                    }
                    else if(date[i].m - date[j].m == 1)
                    {
                        if((!(date[i].y % 4) && date[i].y % 100) || !(date[i].y % 400))
                            days[2] = 29;
                        if(date[i].d == 1 && date[j].d == days[date[j].m])
                        {
                            cnt++;
                            sum += (date[i].c - date[j].c);
                        }
                        days[2] = 28; //记得还原,因为这WA了三次
                    }
                }
            }
            printf("%d %d\n", cnt, sum);
        }
        return 0;
    }
    


  • 相关阅读:
    实现图片加载从模糊到清晰显示的方法
    审批流程设计方案-介绍(一)
    SpringBoot+JPA实现DDD(一)
    RabbitMQ使用入门
    SpringBoot+JPA实现DDD(六)
    SpringBoot+JPA实现DDD(五)
    Spring Boot+JPA实现DDD(四)
    Spring Boot+JPA实现DDD(三)
    Spring Boot+JPA实现DDD(二)
    DDD入门之解决了什么问题(二)
  • 原文地址:https://www.cnblogs.com/cszlg/p/2910564.html
Copyright © 2011-2022 走看看