UVa Problem Solution: 10138 - CDVII
来源:互联网 发布:2016淘宝直通车技巧 编辑:程序博客网 时间:2024/05/22 13:01
Sort the the photo records according to license number, then time. If a license has no cost, do not output it.
Code:
- /*************************************************************************
- * Copyright (C) 2008 by liukaipeng *
- * liukaipeng at gmail dot com *
- *************************************************************************/
- /* @JUDGE_ID 00000 10138 C++ "CDVII" */
- #include <algorithm>
- #include <cmath>
- #include <cstring>
- #include <deque>
- #include <fstream>
- #include <iostream>
- #include <list>
- #include <map>
- #include <queue>
- #include <set>
- #include <stack>
- #include <string>
- #include <vector>
- using namespace std;
- int const linesize = 256;
- int const recordcount = 1000;
- struct record
- {
- char license[21];
- int month;
- int day;
- int hour;
- int minute;
- char status[6];
- int location;
- };
- struct recordcmp
- {
- bool operator()(record const& r1, record const& r2)
- {
- int c = strcmp(r1.license, r2.license);
- if (c < 0) return true;
- if (c > 0) return false;
- if (r1.day < r2.day) return true;
- if (r1.day > r2.day) return false;
- if (r1.hour < r2.hour) return true;
- if (r1.hour > r2.hour) return false;
- if (r1.minute < r2.minute) return true;
- if (r1.minute > r2.minute) return false;
- return false;
- }
- };
- struct bill
- {
- char *license;
- int cost;
- };
- int get_bills(int *fares, record *records, int nrecords, bill *bills)
- {
- sort(records, records + nrecords, recordcmp());
- int nbills = 0;
- for (int i = 0; i < nrecords;) {
- char *license = records[i].license;
- bool entered = false;
- int cost = 0;
- for (; i < nrecords && strcmp(license, records[i].license) == 0; ++i) {
- if (!entered) {
- if (records[i].status[1] == 'n') {
- entered = true;
- } else continue;
- }
- if (entered) {
- if (records[i].status[1] == 'x') {
- entered = false;
- cost += 100 + fares[records[i-1].hour] *
- abs(records[i].location - records[i-1].location);
- } else continue;
- }
- }
- if (cost > 0) {
- cost += 200;
- bills[nbills].license = license;
- bills[nbills].cost = cost;
- ++nbills;
- }
- }
- return nbills;
- }
- int main(int argc, char *argv[])
- {
- #ifndef ONLINE_JUDGE
- freopen((string(argv[0]) + ".in").c_str(), "r", stdin);
- freopen((string(argv[0]) + ".out").c_str(), "w", stdout);
- #endif
- int ncases;
- scanf("%d/n/n", &ncases);
- while (ncases-- > 0) {
- char buf[linesize];
- fgets(buf, linesize, stdin);
- int fares[24];
- sscanf(buf, "%d %d %d %d %d %d %d %d %d %d %d "
- "%d %d %d %d %d %d %d %d %d %d %d %d %d/n",
- &fares[0], &fares[1], &fares[2], &fares[3], &fares[4],
- &fares[5], &fares[6], &fares[7], &fares[8], &fares[9],
- &fares[10], &fares[11], &fares[12], &fares[13], &fares[14],
- &fares[15], &fares[16], &fares[17], &fares[18], &fares[19],
- &fares[20], &fares[21], &fares[22], &fares[23]);
- record records[recordcount];
- int nrecords = 0;
- for (; fgets(buf, linesize, stdin) && buf[0] != '/n'; ++nrecords) {
- sscanf(buf, "%s %2d:%2d:%2d:%2d %s %d/n",
- records[nrecords].license, &records[nrecords].month,
- &records[nrecords].day, &records[nrecords].hour,
- &records[nrecords].minute, records[nrecords].status,
- &records[nrecords].location);
- }
- bill bills[recordcount];
- int nbills = get_bills(fares, records, nrecords, bills);
- for (int i = 0; i < nbills; ++i) {
- printf("%s $%d.%02d/n", bills[i].license, bills[i].cost / 100,
- bills[i].cost % 100);
- }
- if (ncases > 0) putchar('/n');
- }
- return 0;
- }
- UVa Problem Solution: 10138 - CDVII
- UVa Problem 10138 CDVII (CDVII 高速公路)
- UVa Problem Solution: 10189 - Minesweeper
- UVa Problem Solution: 10033 - Interpreter
- UVa Problem Solution: 10050 - Hartals
- UVa Problem Solution: 10149 - Yahtzee
- UVa Problem Solution: 10082 - WERTYU
- UVa Problem Solution: 10150 - Doublets
- UVa Problem Solution: 848 - Fmt
- UVa Problem Solution: 10037 - Bridge
- UVa Problem Solution: 10152 - ShellSort
- UVa Problem Solution: 10127 - Ones
- UVa Problem Solution: 10198 - Counting
- UVa Problem Solution: 10157 - Expressions
- UVa Problem Solution: 846 - Steps
- UVa Problem Solution: 10139 - Factovisors
- UVa Problem Solution: 10090 - Marbles
- UVa Problem Solution: 10089 - Repackaging
- prototype.js开发笔记
- 私有构造函数 私有析构函数
- Adapter 适配器模式
- 灵图李仲亮:人生地图需要导航
- Berkeley DB 以及 DB_SECONDARY_BAD: Secondary index inconsistent with primary 问题
- UVa Problem Solution: 10138 - CDVII
- 泪的告白
- 编程规范和范例
- 全新电脑防御时代的革命,通过军方认证的美杜杉一号
- 求一字符串出现次数最多的字符,asm
- 绑定端口与INADDR_ANY
- C++中的虚析构函数
- Interface Design & UAR
- Getting Real ——把握现实