timus 1711.Code Names
来源:互联网 发布:轩辕剑之天之痕mac 编辑:程序博客网 时间:2024/04/20 07:05
鼓励对该题目有过思考后再来看题解,这样会有帮助一点。
刚开始是真的彻底地没思路,后来仔细看看test1的output:
codenamesgrillekeywordsmnemonicplaygamerandomrectanglerejudgeshaitanvolumewatchmen
output呈字典序排列,才清楚题意,有就知道为什么test2的结果会是IMPOSSBLE了
其中input为
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
实现的代码:
#include<iostream>#include<algorithm>using namespace std;struct A //数据结构{int num;char s[25];};A a[50];int cmp(A aa,A b)//字典序排列{int i;for(i=0;;){if(aa.s[i]>b.s[i])return 0;else if(aa.s[i]<b.s[i])return 1;i++;}return 1;};int main(){int n,i,j,arr[20];char ans[20][25]; //记录最容易找的方案while(scanf("%d",&n)!=-1){for(i=0;i<3*n;i++){scanf("%s",a[i].s);a[i].num=i/3+1;}sort(a,a+3*n,cmp);for(i=1;i<=n;i++)scanf("%d",&arr[i]);int kk=0,i=1,ff=0; //ff用来判断是否有满足条件的解法,kk记录上个arr[]访问的位置while(kk<3*n){for(j=kk;j<3*n;j++){if(a[j].num==arr[i]){strcpy(ans[i],a[j].s);i++;break;}}kk=j+1;if(i==n+1){ff=1;break;}}if(ff){for(i=1;i<=n;i++){printf("%s\n",ans[i]);}}else{printf("IMPOSSIBLE\n");}}return 0;}
- timus 1711.Code Names
- URAL 1711. Code Names (数学啊 )
- J2SE Code Names
- Timus 1792. Hamming Code 题解
- English country names and code elements
- Method Names and Non-ARC Compiled Code
- <clean code>-chapter 02 : Meaningful Names
- Express names in code: Bad vs Clean
- names
- ISO 639: Code for the Representation of the Names of Languages
- [Code Complete] CH11 The Power of Variable Names 变量名的力量
- timus 1017
- timus 1073
- Data Names
- echo 'names';
- echo 'names';
- About Names
- Meaningful Names
- log4j入门
- N个数中第k大的元素
- linux awk命令详解
- ubuntu 12.0 下nginx+mysql+php 的安装
- oracle 创建 用户
- timus 1711.Code Names
- Ural-1044. Lucky Tickets. Easy!(简单题)
- linux网络 记住 关闭防火墙
- jQuery.extend 函数详解
- shell脚本-----按行读取文件
- Microsoft Visual Studio 2010 遇到了异常,可能是由某个扩展导致的
- JAVA设计模式笔记整理(四)
- HibernateCallback實現分頁查詢
- 内存对齐问题