问题 I: Congestion Charging Zone

问题 I: Congestion Charging Zone
时间限制: 1 Sec 内存限制: 128 MB
提交: 839 解决: 109
[提交] [状态] [命题人:admin]
题目描述
Tehran municipality has set up a new charging method for the Congestion Charging Zone (CCZ) which controls the passage of vehicles in Tehran’s high-congestion areas in the congestion period (CP) from 6:30 to 19:00. There are plate detection cameras inside or at the entrances of the CCZ recording vehicles seen at the CCZ. The table below summarizes the new charging method.

Note that the first time and the last time that a vehicle is seen in the CP may be the same. Write a program to compute the amount of charge of a given vehicle in a specific day.

输入
The first line of the input contains a positive integer n (1 ⩽ n ⩽ 100) where n is the number of records for a vehicle. Each of the next n lines contains a time at which the vehicle is seen. Each time is of form :, where is an integer number between 0 and 23 (inclusive) and is formatted as an exactly two-digit number between 00 and 59 (inclusive).

输出
Print the charge to be paid by the owner of the vehicle in the output.

样例输入
复制样例数据
4
7:30
2:20
7:30
17:30
样例输出
36000

记好排序,是个坑

#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <set>
#include <queue>
#include <stack>
#define inf 0x3f3f3f3f
#define maxn 1e5
using namespace std;

int main(){
    int n, d = 0;
    int t1,t2;
    cin >> n;
    int* a = new int[n];
    int ts, te;
    char s;
    for (int i=0;i<n;i++)
    {
        cin >> ts >> s >>te;
        a[i] = ts*60+te;
    }
    sort(a,a+n);
    for(int i=0;i<n;i++)
    {
        if(a[i] >= 6*60+30 && a[i] <= 19*60)
        {
            t1=a[i];
           // cout<<t1<<endl;
            break;
        }

    }
    for(int i=n-1;i>=0;i--)
    {
        if(a[i] >= 6*60+30 && a[i] <= 19*60)
        {
            t2=a[i];
            //cout <<t2<<endl;
            break;
        }
    }

            if (t1 >= 6*60+30 && t1 <= 10*60)
            {
                if (t2 >= 6*60+30 && t2 <= 16*60)
                {
                    d+=24000;
                }
                if (t2 >= 16*60+1 && t2 <= 19*60)
                {
                    d+=36000;
                }
            }
            if (t1 >= 10*60+1 && t1 <= 16*60)
            {
                if (t2 >= 10*60+1 && t2 <= 16*60)
                {
                    d+=16800;
                }
            }
            if (t1 >= 10*60+1 && t1 <= 19*60)
            {
                if (t2 >= 16*60+1 && t2 <= 19*60)
                {
                    d+=24000;
                }
            }

    cout << d << endl;

    return 0;
}


猜你喜欢

转载自blog.csdn.net/abc1235454/article/details/89058411