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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值