CF Find the problem
来源:互联网 发布:在线影视自动采集源码 编辑:程序博客网 时间:2024/06/02 22:41
F. Find The Problem!
Sohrab & Sepehr are problem-setters of Kashan
programming contest. After they prepared their problems, the
sponsor of event gives them two new raw problems. He asks
them to add the two new problems to the problem set. Now you
should solve one of those problems. Sohrab & Sepehr doesn’t
have any time to prepare the problem, so they explain the original
one given by sponsor and you have to discover what it actually
asks, then solve it!
In this problem you are given a mysterious table and you should change it to a strange one! See
the example to find out how to do it.
Input (Standard Input)
The first line of input contains an integer indicating the number of test cases.
Fig1. A nostalgic figure from IOI95
Machine Part Code
R1 P1 C1
R1 P2 C2
R1 P3 C3
R1 P4 C4
R2 P1 C5
R2 P5 C6
R2 P6 C7
R2 P7 C8
R3 P5 C9
Fig1. Mysterious table
P1 P2 P3 P4 P5 P6 P7
R1 C1 C2 C3 C4
R2 C5 C6 C7 C8
R3 C9
Fig2. Strange table
Page 10 of 21
First line of each test case contains an integer number which is the number of
data rows in the mysterious table. In each of next lines there are three space-separated
words representing saved data fields in the row of mysterious table.
All data in the table only consists of uppercase English letters and digits. Length of all words are
less than or equal to 3 characters. It’s guaranteed that in the given mysterious table all pairs
are distinct.
Output (Standard Output)
For each test case, output a strange table just like the sample input and output. There are two
secret points you must consider:
All data fields must contain exactly 3 characters and must be left justified. If the length of
any field data is less than 3, you should add trailing space characters to it.
Row and column names should appear in ascending lexicographical order.
Sample Input Sample Output
2
9
R1 P1 C1
R1 P2 C2
R1 P3 C3
R1 P4 C4
R2 P1 C5
R2 P5 C6
R2 P6 C7
R2 P7 C8
R3 P5 C9
1
R1 P1 CCC
+---+---+---+---+---+---+---+---+
| |P1 |P2 |P3 |P4 |P5 |P6 |P7 |
+---+---+---+---+---+---+---+---+
|R1 |C1 |C2 |C3 |C4 | | | |
+---+---+---+---+---+---+---+---+
|R2 |C5 | | | |C6 |C7 |C8 |
+---+---+---+---+---+---+---+---+
|R3 | | | | |C9 | | |
+---+---+---+---+---+---+---+---+
+---+---+
| |P1 |
+---+---+
|R1 |CCC|
+---+---+
Hint
The lexicographical order of strings is the order we are all used to, the "dictionary" order. Such comparison is used in
all modern programming languages to compare strings. Formally, a string of length is lexicographically less than
string q of length m, if one of the two statements is correct:
, and is the beginning (prefix) of string (for example, "aba" is less than string "abaa"),
for some , here characters in strings are
Sohrab & Sepehr are problem-setters of Kashan
programming contest. After they prepared their problems, the
sponsor of event gives them two new raw problems. He asks
them to add the two new problems to the problem set. Now you
should solve one of those problems. Sohrab & Sepehr doesn’t
have any time to prepare the problem, so they explain the original
one given by sponsor and you have to discover what it actually
asks, then solve it!
In this problem you are given a mysterious table and you should change it to a strange one! See
the example to find out how to do it.
Input (Standard Input)
The first line of input contains an integer indicating the number of test cases.
Fig1. A nostalgic figure from IOI95
Machine Part Code
R1 P1 C1
R1 P2 C2
R1 P3 C3
R1 P4 C4
R2 P1 C5
R2 P5 C6
R2 P6 C7
R2 P7 C8
R3 P5 C9
Fig1. Mysterious table
P1 P2 P3 P4 P5 P6 P7
R1 C1 C2 C3 C4
R2 C5 C6 C7 C8
R3 C9
Fig2. Strange table
Page 10 of 21
First line of each test case contains an integer number which is the number of
data rows in the mysterious table. In each of next lines there are three space-separated
words representing saved data fields in the row of mysterious table.
All data in the table only consists of uppercase English letters and digits. Length of all words are
less than or equal to 3 characters. It’s guaranteed that in the given mysterious table all pairs
are distinct.
Output (Standard Output)
For each test case, output a strange table just like the sample input and output. There are two
secret points you must consider:
All data fields must contain exactly 3 characters and must be left justified. If the length of
any field data is less than 3, you should add trailing space characters to it.
Row and column names should appear in ascending lexicographical order.
Sample Input Sample Output
2
9
R1 P1 C1
R1 P2 C2
R1 P3 C3
R1 P4 C4
R2 P1 C5
R2 P5 C6
R2 P6 C7
R2 P7 C8
R3 P5 C9
1
R1 P1 CCC
+---+---+---+---+---+---+---+---+
| |P1 |P2 |P3 |P4 |P5 |P6 |P7 |
+---+---+---+---+---+---+---+---+
|R1 |C1 |C2 |C3 |C4 | | | |
+---+---+---+---+---+---+---+---+
|R2 |C5 | | | |C6 |C7 |C8 |
+---+---+---+---+---+---+---+---+
|R3 | | | | |C9 | | |
+---+---+---+---+---+---+---+---+
+---+---+
| |P1 |
+---+---+
|R1 |CCC|
+---+---+
Hint
The lexicographical order of strings is the order we are all used to, the "dictionary" order. Such comparison is used in
all modern programming languages to compare strings. Formally, a string of length is lexicographically less than
string q of length m, if one of the two statements is correct:
, and is the beginning (prefix) of string (for example, "aba" is less than string "abaa"),
for some , here characters in strings are
numbered starting from .
恶心模拟,各种stl。学了一招,把string 用printf的%s输出,方法是printf("%s",s.c_str());
#include <iostream>#include <cstring>#include <cstdio>#include <string>#include <algorithm>#include <map>#include <vector>#include <queue>#include <set>#include <cmath>using namespace std;typedef long long LL;typedef pair<string,string> P;const int maxn = 50 + 5;const int INF = 1000000000;string s1,s2,s3;map<P,string> M;set<string> Se1,Se2;set<string>::iterator it,it2;int main(){ int t; scanf("%d",&t); while(t--){ int n; scanf("%d",&n); M.clear(); Se1.clear();Se2.clear(); for(int i = 0;i < n;i++){ cin >> s1 >> s2 >> s3; M[P(s1,s2)] = s3; Se1.insert(s1); Se2.insert(s2); } for(int i = 0;i < Se2.size()+1;i++) printf("+---"); printf("+\n"); printf("| "); for(it = Se2.begin();it != Se2.end();it++){ printf("|%-3s",it->c_str()); } printf("|\n"); for(int i = 0;i < Se2.size()+1;i++) printf("+---"); printf("+\n"); it = Se1.begin(); for(it = Se1.begin();it != Se1.end();it++){ printf("|%-3s",it->c_str()); for(it2 = Se2.begin();it2 != Se2.end();it2++){ if(M.count(P(*it,*it2)) == 0) printf("| "); else printf("|%-3s",M[P(*it,*it2)].c_str()); } printf("|\n"); for(int i = 0;i < Se2.size()+1;i++) printf("+---"); printf("+\n"); } } return 0;}
- CF Find the problem
- cf find the bone
- Problem G: Find The Difference
- Problem 389. Find the Difference
- Design Tutorial: Inverse the Problem cf 270
- hdu Problem - 1597 find the nth digit
- UVA - 10921 - Problem B - Find the Telephone
- CF 776D The Door Problem TwoSAT 模板题
- Find The Multiple&&http://poj.org/problem?id=1426
- [Java Beginner] Problem to "Could not find the main class"
- HDU Problem 1596 find the safest road【最短路dijkstra】
- CF/379/problem/C
- cf A Trivial Problem
- CF:Problem 383D
- Genymotion提示To find out the cause of the problem,start the virtual device from VirtualBox
- cf#3A Shortest path of the kinghttp://codeforces.com/contest/3/problem/A
- CF GYM 100548 The Problem Needs 3D Arrays(2014ACM西安现场赛Problem C)
- CF GYM 100548 The Problem to Make You Happy(2014ACM西安现场赛Problem H)
- http request status code详解
- 如何选择走过你生命中的100个女孩
- 测试的七个维度
- W5500参考电路图
- Android中中捕获HOME事件
- CF Find the problem
- Busybox 1.17.4 制作根文件系统 (2)
- 淘宝彩蛋--CSS3、Console、web彩蛋指南
- dubbo配置注意
- 集合函数简单入门(一)
- 将txt文件转换成excel文件的方法
- Android 简介
- Linux Core Dump
- #、##和__VA_ARGS__