题目描述
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 <hour>:<minute>, where <hour> is an integer number between 0 and 23 (inclusive) and <minute> 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
题目大意:
emmmm,此题题目有毒,感觉它说的很模糊,按照代码的思路,最终的意思就是:先输入一个整数n,下面n行输入n个时间(ps:同一天内的),问根据表格最终产生的费用是多少?
解题思路:
需要先对时间进行一个排序,然后从前往后找到第一个符合列1的时间,再从后往前找到第一个符合列2的时间,根据这两个时间即可得到最终的费用。
代码:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#include <utility>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define lep(i,l,r) for(int i=l;i>=r;i--)
#define ms(arr) memset(arr,0,sizeof(arr))
//priority_queue<int,vector<int> ,greater<int> >q;
const int maxn = (int)1e5 + 5;
const ll mod = 1e9+7;
int ju1(int h,int m)
{if(h==6&&m>=30) return 1;else if(h>=7&&h<=9) return 1;else if(h==10&&m==0) return 1;else if(h==10&&m>0) return 2;else if(h>=11&&h<=15) return 2;else if(h==16&&m==0) return 2;else if(h==16&&m>0) return 3;else if(h>=17&&h<=18) return 3;else if(h==19&&m==0) return 3;else return -1;
}
int ju2(int h,int m) {if(h==6&&m>=30) return 1;else if(h>=7&&h<=9) return 1;else if(h==10&&m==0) return 1;else if(h==10&&m>0) return 2;else if(h>=11&&h<=15) return 2;else if(h==16&&m==0) return 2;else if(h==16&&m>0) return 3;else if(h>=17&&h<=18) return 3;else if(h==19&&m==0) return 3;else return -1;
}
struct node
{int h,m;
}arr[120];
bool cmp(node a,node b) {if(a.h==b.h) return a.m<b.m;else return a.h<b.h;
}
int main()
{#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);#endif//freopen("out.txt", "w", stdout);ios::sync_with_stdio(0),cin.tie(0);int n;scanf("%d",&n);rep(i,1,n) scanf("%d:%d\n",&arr[i].h,&arr[i].m);sort(arr+1,arr+1+n,cmp);int t1,t2;for(int i=1;i<=n;i++) {t1=ju1(arr[i].h,arr[i].m);if(t1!=-1) break;}for(int i=n;i>=1;i--) {t2=ju2(arr[i].h,arr[i].m);if(t2!=-1) break;}int ans=0; if(t1==1&&(t2==1||t2==2)) ans=24000;else if(t1==1&&t2==3) ans=36000;else if(t1==2&&t2==2) ans=16800;else if((t1==2||t1==3)&&t2==3) ans=24000;printf("%d\n",ans);return 0;
}