24h購物| | PChome| 登入
2013-07-02 09:08:18| 人氣1,450| 回應0 | 上一篇 | 下一篇

[UVA][模擬] 10138 - CDVII

推薦 0 收藏 0 轉貼0 訂閱站台

Problem C: CDVII

Roman roads are famous for their longevity and sound engineering. Unfortunately, sound engineering does not come cheap, and a number of neo-Caesars have decided to recover the costs through automated tolling.

A particular toll highway, the CDVII, has a fare structure that works as follows: travel on the road costs a certain amount per km travelled, depending on the time of day when the travel begins. Cameras at every entrance and every exit capture the license numbers of all cars entering and leaving. Every calendar month, a bill is sent to the registered owner for each km travelled (at a rate determined by the time of day), plus one dollar per trip, plus a two dollar account charge. Your job is to prepare the bill for one month, given a set of license plate photos.

Input

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.

Standard input has two parts: the fare structure, and the license photos. The fare structure consists of a line with 24 non-negative integers denoting the toll (cents/km) from 00:00 - 00:59, the toll from 01:00 - 00:59, and so on for each hour in the day. Each photo record consists of the license number of the vehicle (up to 20 alphanumeric characters), the time and date (mm:dd:hh:mm), the word "enter" or "exit", and the location of the entrance or exit (in km from one end of the highway). All dates will be within a single month. Each "enter" record is paired with the chronologically next record for the same vehicle provided it is an "exit" record. "enter" records that are not paired with an "exit" record are ignored, as are "exit" records not paired with an "enter" record. You may assume that no two records for the same vehicle have the same time. Times are recorded using a 24-hour clock. There are not more than 1000 photo records.

Output

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.

Print a line for each vehicle indicating the license number, and the total bill, in alphabetical order by license number. Vehicles that don't use the highway shouldn't be listed.

Sample Input

1

10 10 10 10 10 10 20 20 20 15 15 15 15 15 15 15 20 30 20 15 15 10 10 10
ABCD123 01:01:06:01 enter 17
765DEF 01:01:07:00 exit 95
ABCD123 01:01:08:03 exit 95
765DEF 01:01:05:59 enter 17

Output for Sample Input

765DEF $10.80
ABCD123 $18.60

Problem C: CDVII

Roman roads are famous for their longevity and sound engineering. Unfortunately, sound engineering does not come cheap, and a number of neo-Caesars have decided to recover the costs through automated tolling.

A particular toll highway, the CDVII, has a fare structure that works as follows: travel on the road costs a certain amount per km travelled, depending on the time of day when the travel begins. Cameras at every entrance and every exit capture the license numbers of all cars entering and leaving. Every calendar month, a bill is sent to the registered owner for each km travelled (at a rate determined by the time of day), plus one dollar per trip, plus a two dollar account charge. Your job is to prepare the bill for one month, given a set of license plate photos.

Input

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.

Standard input has two parts: the fare structure, and the license photos. The fare structure consists of a line with 24 non-negative integers denoting the toll (cents/km) from 00:00 - 00:59, the toll from 01:00 - 00:59, and so on for each hour in the day. Each photo record consists of the license number of the vehicle (up to 20 alphanumeric characters), the time and date (mm:dd:hh:mm), the word "enter" or "exit", and the location of the entrance or exit (in km from one end of the highway). All dates will be within a single month. Each "enter" record is paired with the chronologically next record for the same vehicle provided it is an "exit" record. "enter" records that are not paired with an "exit" record are ignored, as are "exit" records not paired with an "enter" record. You may assume that no two records for the same vehicle have the same time. Times are recorded using a 24-hour clock. There are not more than 1000 photo records.

Output

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.

Print a line for each vehicle indicating the license number, and the total bill, in alphabetical order by license number. Vehicles that don't use the highway shouldn't be listed.

Sample Input

1

10 10 10 10 10 10 20 20 20 15 15 15 15 15 15 15 20 30 20 15 15 10 10 10
ABCD123 01:01:06:01 enter 17
765DEF 01:01:07:00 exit 95
ABCD123 01:01:08:03 exit 95
765DEF 01:01:05:59 enter 17

Output for Sample Input

765DEF $10.80
ABCD123 $18.60



題目描述:
會給定很多照片,而照片會給車子的進入或者離開時間以及所在的位置,接著對於每個車牌寄出帳單,
帳單建檔花費 $2, 每次上高速公路有基本費 $1, 跑的費率根據一開始上高速公路的時段與跑的距離,
要忽略沒有匹配的測資。

題目解法:

就單純的模擬,不過這題通過率低不是沒有原因的,因為忽略的地方很弔詭。
首先先將同一個車牌的訊息根據時間由小排到大,然後找一個沒有匹配的進入點,
然後去找離開點,但是沒想到,這個寫法會錯,要抓到前一次可能被忽略的進入點費率,
於是就這麼卡了很久,最後這麼過也覺得太扯了。

#include <stdio.h>
#include <string.h>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
struct photo {
string license;
int time, location;
int enter, toll;
bool operator<(const photo &a) const {
if(license != a.license)
return license < a.license;
return time < a.time;
}
};
photo P[1005];
int main() {
int testcase;
int toll[24];
int i, j, k;
char foo[5024], license[5024], enter[50];
scanf("%d", &testcase);
while(testcase--) {
for(i = 0; i < 24; i++)
scanf("%d", &toll[i]);
while(getchar() != '\n');
photo tmp;
int n = 0;
while(gets(foo)) {
if(foo[0] == '\0') break;
int dd, hh, mm, loc;
sscanf(foo, "%s %*d:%d:%d:%d %s %d", license, &dd, &hh, &mm, enter, &loc);
tmp.license = license;
tmp.time = dd*24*60 + hh*60 + mm;
tmp.toll = toll[hh];
tmp.location = loc;
tmp.enter = (enter[1] == 'n');//enter/exit
P[n++] = tmp;
}
sort(P, P+n);
map<string, int> bill;
for(i = 0; i < n; i++) {
if(P[i].enter == 1) {
for(j = i; j < n; j++) {
if(P[j].license != P[i].license) {
break;
}
if(P[j].enter == 0 && P[j].license == P[i].license) {
bill[P[i].license] += abs(P[j].location-P[j-1].location)*P[j-1].toll+100;
j++;
break;
}
}
i = j-1;
}
}
for(map<string, int>::iterator it = bill.begin();
it != bill.end(); it++) {
cout << it->first << " $";
printf("%d.%02d\n", (it->second+200)/100, (it->second+200)%100);
}
if(testcase) puts("");
}
return 0;
}
 

台長: Morris
人氣(1,450) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][窮舉] 129 - Krypton Factor
此分類上一篇:[UVA][最短路] 10187 - From Dusk Till Dawn

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文