NBUT 1114 Alice's Puppets
来源:互联网 发布:神话情话知乎 编辑:程序博客网 时间:2024/05/22 10:58
NBUT 1114 Alice's Puppets
东方系列的题目。。。一开始想复杂了,还用深搜结果超时。直接暴力一个个存进去就好了
记得最后要按字典序排序一下。最后还因为这个WA了次。。
#include <algorithm>using namespace std;#include <stdio.h>#include <string.h>int cmp(const void *elem1,const void *elem2){return(strcmp((char*)elem1,(char*)elem2));}int n;char a[1005][25], b[1005][25];int vis[1005];struct Q{char name[1005][25];int name_num;} lv[1005];int main(){int i, j;while (scanf("%d", &n) != EOF){getchar();int num = n;memset(lv, 0, sizeof(lv));memset(a, 0, sizeof(a));memset(b, 0, sizeof(b));memset(vis, 0, sizeof(vis));strcpy(lv[0].name[0], "Alice");lv[0].name_num ++;for (i = 0; i < n; i ++){scanf("%s%s", a[i], b[i]);}int t = 0;while( num ){for (i = 0; i < lv[t].name_num ; i ++){for (j = 0; j < n; j ++){if (strcmp(lv[t].name[i], b[j]) == 0 && vis[j] == 0){vis[j] = 1;strcpy(lv[t + 1].name[lv[t+1].name_num ++], a[j]);num --;}}}t ++;}for (i = 1; i <= n; i++){qsort(lv[i].name,lv[i].name_num,sizeof(lv[i].name[0]),cmp);}for (i = 1; i <= n; i ++){for (j = 0; j < lv[i].name_num; j ++){printf("%s %d\n", lv[i].name[j], i);}}}return 0;}
- NBUT 1114 Alice's Puppets
- NBUT 1114 Alice's Puppets
- NOJ [1114] Alice's Puppets
- Alice In Bloomingdale's
- pku1698 Alice's Chance
- poj1698 - Alice's Chance
- hdu3544 Alice's Game
- Alice's Chance
- POJ1698 Alice's Chance
- [HDU3544] Alice's Game
- HDU3220-Alice’s Cube
- poj1698 Alice's Chance
- POJ 1698 Alice's Chance
- 1698 Alice's Chance //MAXMATCH
- Alice's Chance【多重匹配】
- POJ 1698 Alice's Chance
- poj 1698 Alice's Chance
- ZOJ 3633 Alice's present
- 我遇到过的异常 in JavaWeb
- void及void指针含义的深刻解析(转,void * 在gcc中被看做char *处理,即void *p; p++;实际加1,而不是加整形的4或者long型的8)
- 局域网 学习笔记 1
- Android架构
- HTML5语音识别
- NBUT 1114 Alice's Puppets
- HTML5语音识别 Demo
- 网站排障分析常用的命令
- UVA 133 Power of Cryptography 。。。其实很简单
- IAR包含文件的路径定义
- UVA 439 Knight Moves 简单广搜
- UVA 11292 The Dragon of Loowater 英文略长略长
- How to Set Up vsftpd on Ubuntu 12.04
- 深入剖析mean shift 图像分割 原理及代码