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;
    }
    


  • 相关阅读:
    关于MySql 数据库InnoDB存储引擎介绍
    .netcore 中使用开源的AOP框架 AspectCore
    C#关于反序列化实例时,接收实体字段少于或大于原实体对象 解析测试
    PostgreSQL TIMESTAMP类型 时间戳
    C# 新特性 操作符单?与??和 ?. 的使用
    PostgreSQL 常用函数
    AutoCAD.Net/C#.Net QQ群:193522571 previewicon生成的块图标太小,CMLContentSearchPreviews生成大的图片
    C#winform中OpenFileDialog的用法
    C# winform datagridview 无需点击两次即可编辑内嵌控件的方法和删除默认的空行的方法
    C# winform datagridview 内嵌控件值改变后立即触发事件,而不需要离开该单元格时才触发,此时需要用到dgv_CurrentCellDirtyStateChanged事件
  • 原文地址:https://www.cnblogs.com/cszlg/p/2910564.html
Copyright © 2011-2022 走看看