首页 > 代码库 > 1016. Phone Bills (25)(神之模拟==)
1016. Phone Bills (25)(神之模拟==)
A long-distance telephone company charges its customers by the following rules:
Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connecting a long-distance call, the time will be recorded, and so will be the time when the customer hangs up the phone. Every calendar month, a bill is sent to the customer for each minute called (at a rate determined by the time of day). Your job is to prepare the bills for each month, given a set of phone call records.
Input Specification:
Each input file contains one test case. Each case has two parts: the rate structure, and the phone call records.
The rate structure consists of a line with 24 non-negative integers denoting the toll (cents/minute) from 00:00 - 01:00, the toll from 01:00 - 02:00, and so on for each hour in the day.
The next line contains a positive number N (<= 1000), followed by N lines of records. Each phone call record consists of the name of the customer (string of up to 20 characters without space), the time and date (mm:dd:hh:mm), and the word "on-line" or "off-line".
For each test case, all dates will be within a single month. Each "on-line" record is paired with the chronologically next record for the same customer provided it is an "off-line" record. Any "on-line" records that are not paired with an "off-line" record are ignored, as are "off-line" records not paired with an "on-line" record. It is guaranteed that at least one call is well paired in the input. You may assume that no two records for the same customer have the same time. Times are recorded using a 24-hour clock.
Output Specification:
For each test case, you must print a phone bill for each customer.
Bills must be printed in alphabetical order of customers‘ names. For each customer, first print in a line the name of the customer and the month of the bill in the format shown by the sample. Then for each time period of a call, print in one line the beginning and ending time and date (dd:hh:mm), the lasting time (in minute) and the charge of the call. The calls must be listed in chronological order. Finally, print the total charge for the month in the format shown by the sample.
Sample Input:
10 10 10 10 10 10 20 20 20 15 15 15 15 15 15 15 20 30 20 15 15 10 10 1010CYLL 01:01:06:01 on-lineCYLL 01:28:16:05 off-lineCYJJ 01:01:07:00 off-lineCYLL 01:01:08:03 off-lineCYJJ 01:01:05:59 on-lineaaa 01:01:01:03 on-lineaaa 01:02:00:01 on-lineCYLL 01:28:15:41 on-lineaaa 01:05:02:24 on-lineaaa 01:04:23:59 off-line
Sample Output:
CYJJ 0101:05:59 01:07:00 61 $12.10Total amount: $12.10CYLL 0101:06:01 01:08:03 122 $24.4028:15:41 28:16:05 24 $3.85Total amount: $28.25aaa 0102:00:01 04:23:59 4318 $638.80Total amount: $638.80
Means:
第一行给出一天内24小时资费,接着n,最后n行表示n个通话记录时间地点。每个通话记录都有姓名,月、日、时、分,以及通话开始还是结束,其中有些通话记录是无效的,每一个通话开始对应一个结束,通话开始和结束之间不能再出现其他的通话记录。输出要求:按姓名的字典序从小到大的顺序输出存在有效通话记录的用户,姓名和通话的月份只输出一次占一行,后面是每个符合要求的通话开始时间和结束时间,本次通话时间和产生的费用。最后需要输出所有通话的总费用。
Solve:
直接模拟,写模拟题真的恶心。。。
Code:
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 const int INF = 0x7FFFFFFF; 5 const int maxn = 1e3 + 10; 6 double f[maxn]; 7 int n, x; 8 char ss[maxn]; 9 10 struct point11 {12 string s;13 int a, b, c, d, f;14 void read()15 {16 cin >> s;17 scanf("%d:%d:%d:%d", &a, &b, &c, &d);18 scanf("%s", ss);19 if (ss[1] == ‘n‘) f = 0; else f = 1;20 }21 bool operator<(const point &x)const22 {23 return s == x.s ? a == x.a ? b == x.b ? c == x.c ? d < x.d : c < x.c : b < x.b : a < x.a : s < x.s;24 }25 bool operator==(const point &x)const26 {27 return b == x.b&&c == x.c&&d == x.d;28 }29 }a[maxn];30 31 double putout(point x, point y)32 {33 double ans = 0;34 int cnt = 0;35 point u = x;36 while (true)37 {38 ans += f[u.c]; u.d += 1;39 u.c += u.d / 60; u.d %= 60;40 u.b += u.c / 24; u.c %= 24;41 cnt++; if (u == y) break;42 }43 printf("%02d:%02d:%02d %02d:%02d:%02d %d $%.2lf\n", x.b, x.c, x.d, y.b, y.c, y.d, cnt, ans);44 return ans;45 }46 47 int main()48 {49 for (int i = 0; i < 24; i++) scanf("%d", &x), f[i] = x / 100.0;50 scanf("%d", &n);51 for (int i = 0; i < n; i++) a[i].read();52 sort(a, a + n);53 for (int i = 0, j; i < n; i = j)54 {55 int flag = 0, y = a[i].f;56 for (j = i + 1; a[j].s == a[i].s; j++)57 {58 if (!y&&a[j].f) { flag = 1; break; }59 else y = a[j].f;60 }61 if (flag)62 {63 cout << a[i].s;64 printf(" %02d\n", a[i].a);65 point x = a[i];66 double ans = 0;67 for (j = i + 1; a[j].s == a[i].s; j++)68 {69 if (!x.f && a[j].f) ans += putout(x, a[j]);70 x = a[j];71 }72 printf("Total amount: $%.2lf\n", ans);73 }74 }75 return 0;76 }
1016. Phone Bills (25)(神之模拟==)