URAL 1711. Code Names (数学啊 )
来源:互联网 发布:人过五十知天命感慨 编辑:程序博客网 时间:2024/04/24 13:23
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1711
1711. Code Names
Time limit: 0.5 second
Memory limit: 64 MB
Memory limit: 64 MB
Imagine that you have to prepare a problem set for the forthcoming programming contest and you have already chosen the problems you will use in it. Before you start writing problem statements, preparing tests, and writing author solutions, you must give code names to all the problems.
A code name is a string that uniquely identifies the problem. For example, instead of saying “problem about the cipher grille”, you can simply say “problem grille.”
The problems in a problem set are arranged according to the lexicographical order of their code names. However, the program committee wants to get a fixed order of the problems. For example, the easiest problem should be put on the first place so that all the teams will be able to find it, or the letter D can be assigned to a really Difficult problem. Therefore, to obtain some predefined order of the problems in the problem set, the program committee needs to carefully choose the code names. This is just what you have to do.
To make your task easier, the program committee proposed three variants of the code name for each of the n problems in the problem set. You only have to choose an appropriate variant for each problem.
Input
The first line contains the number n of problems in the problem set (1 ≤ n ≤ 16). The i-th of the following n lines contains three possible code names for the i-th problem. The variants are separated with a space. The last line contains a permutation of the numbers from 1 to n. This is the order in which the problems must be arranged in the problem set. Each code name consists of lowercase Latin letters and its length is at most 20. All the code names are different.
Output
Output n lines. The i-th line should contain the code name of the problem that will have number i in the problem set. If there are several possible answers, output any of them. If it is impossible to choose the code names as required, output “IMPOSSIBLE”.
Samples
11cipher grille kamkohobnames codenames codesnewtests rejudge timussize volume summitwatchmen braineater twosidessolution random yesornokeywords subversion commandsbosses shooting shaitangame strategy playgamemnemonic palindromes bestnameeligibility rectangle rules2 1 7 10 9 6 11 3 8 4 5
codenamesgrillekeywordsmnemonicplaygamerandomrectanglerejudgeshaitanvolumewatchmen
3problems in thefirst sample areordered not randomly1 2 3
IMPOSSIBLE
代码如下:
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>using namespace std;int main(){ int n; string s[27][27]; while(~scanf("%d",&n)) { for(int i = 0; i < n; i++) { for(int j = 0; j < 3; j++) { cin >> s[i][j]; } sort(s[i],s[i]+3);// for(int j = 0; j < 3; j++)// {// cout<<s[i][j]<<endl;// } } int num; string ans[27]; string tt=""; int flag = 0; for(int i = 0; i < n; i++) { scanf("%d",&num); num--; if(i == 0)//最小的 { tt = s[num][0]; ans[0] = tt; continue; } //cout<<"tt:"<<tt<<endl; int mark = 0; for(int j = 0; j < 3; j++) { mark = 0; if(s[num][j] > tt) { mark = 1; tt = s[num][j]; //cout<<"tt:"<<tt<<endl; ans[i] = s[num][j]; break; } } if(mark == 0) { flag = 1; } } if(flag == 1) { printf("IMPOSSIBLE\n"); continue; } for(int i = 0; i < n; i++) { cout<<ans[i]<<endl; } } return 0;}
1 0
- URAL 1711. Code Names (数学啊 )
- timus 1711.Code Names
- URAL 1515. Cashmaster (数学啊 )
- URAL 1885. Passenger Comfort(数学啊 )
- URAL 1889. Airport Announcements(数学啊 )
- URAL 1718 . Rejudge(数学啊 )
- URAL 1984. Dummy Guy(数学啊)
- URAL 1725. Sold Out!(数学啊 )
- URAL 1731. Dill(数学啊 )
- URAL 1823. Ideal Gas(数学啊 )
- URAL 1617. Flat Spots(数学啊 )
- URAL 1551. Sumo Tournament(数学啊 )
- URAL 1157. Young Tiler (数学啊 )
- URAL 1510. Order(map 数学啊)
- URAL 1113(数学)
- URAL 1820. Ural Steaks(数学啊 )
- URAL 1491. Unreal Story(区间染色, 数学啊)
- URAL 1572. Yekaterinozavodsk Great Well(数学啊)
- WPF制作时钟,依赖属性使用,有个奇怪的地方自己没理解
- 六祖伐竹
- 关于在MFC中实用在基于对话框窗口上面绘制折线的实现方法
- 在人间已是颠,何苦还要上青天
- 变参转换
- URAL 1711. Code Names (数学啊 )
- spring 事务管理详解 学习心得
- jsp 里面map循环使用key/value
- 角点检测
- linux安装oracle先决条件检查全部失败
- ASP.NET微信公众帐号消息帐号接入指南
- Android5.0开关机模块——SystemServer进程
- 点点滴滴 从今天做起
- Multivariance Linear Regression