【思维】Congestion Charging Zone
題目描述
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.
?
樣例輸入
復(fù)制樣例數(shù)據(jù)
4 7:30 2:20 7:30 17:30樣例輸出
36000題目大意:
emmmm,此題題目有毒,感覺它說的很模糊,按照代碼的思路,最終的意思就是:先輸入一個(gè)整數(shù)n,下面n行輸入n個(gè)時(shí)間(ps:同一天內(nèi)的),問根據(jù)表格最終產(chǎn)生的費(fèi)用是多少?
解題思路:
需要先對時(shí)間進(jìn)行一個(gè)排序,然后從前往后找到第一個(gè)符合列1的時(shí)間,再從后往前找到第一個(gè)符合列2的時(shí)間,根據(jù)這兩個(gè)時(shí)間即可得到最終的費(fèi)用。
代碼:
#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; }?
總結(jié)
以上是生活随笔為你收集整理的【思维】Congestion Charging Zone的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: Angular6_PWA
 - 下一篇: 九个案例简述Web设计原则:简洁清晰