hdu 4096
来源:互联网 发布:我欲封天灵珠升阶数据 编辑:程序博客网 时间:2024/06/05 10:29
大模拟准定挂好多次,心塞塞的
#include <iostream>#include <stdlib.h>#include <string.h>#include <algorithm>#include <stdio.h>#include <map>using namespace std;map<string,int> nword;map<string,int> vword;int wcnt;bool vis[3005];int head[3005], ecnt;char str[11111];char word[10][100];bool flag = false;void init(){ nword.clear(); vword.clear(); wcnt = ecnt = 1; memset(head, -1, sizeof(head));}struct Edge{ int to, next;} E[111111];void Addedge( int u, int v){ E[ecnt].to = v; E[ecnt].next = head[u]; head[u] = ecnt++;}void dfs(int cur,int aim){ vis[cur] = true; if(flag) return ; if(cur == aim) { flag = true; return ; } for(int i = head[cur]; i != -1; i = E[i].next) { if(!vis[E[i].to]) { dfs(E[i].to, aim); if(flag) return ; } } return ;}int main(){ int t; scanf("%d",&t); int ca = 1; gets(str); while(t--) { init(); printf("Case #%d:\n",ca++); while(true) { gets(str); int len = strlen(str); if(str[len - 1] == '!') break; else if(str[len - 1] == '.') { str[len - 1] = '\0'; int u, v; if(sscanf(str,"%s%s%s%s%s%s",word[0], word[1], word[2], word[3], word[4], word[5]) != 6) { sscanf(str, "%s%s%s", word[2], word[3], word[4]); string a, b; a = word[2]; b = word[4]; if(nword.find(a) == nword.end()) nword[a] = wcnt++; if(word[3][0] == 'a') { if(nword.find(b) == nword.end()) nword[b] = wcnt++; Addedge(nword[a], nword[b]); } else { if(vword.find(b) == vword.end()) vword[b] = wcnt++; Addedge(nword[a], vword[b]); } } else { sscanf(str,"%s%s%s%s%s%s",word[2], word[2], word[2], word[2], word[3], word[4]); string a, b; a = word[2]; b = word[4]; if(vword.find(a) == vword.end()) vword[a] = wcnt++; if(word[3][0] == 'a') { if(nword.find(b) == nword.end()) nword[b] = wcnt++; Addedge(vword[a], nword[b]); } else { if(vword.find(b) == vword.end()) vword[b] = wcnt++; Addedge(vword[a], vword[b]); } } } else { str[len-1] = '\0'; int u, v; if(sscanf(str,"%s%s%s%s%s%s",word[0], word[1], word[2], word[3], word[4], word[5]) != 6) { sscanf(str, "%s%s%s", word[3], word[2], word[4]); string a, b; a = word[2]; b = word[4]; if(nword.find(a) == nword.end()) nword[a] = wcnt++; if(word[3][0] == 'a') { if(nword.find(b) == nword.end()) nword[b] = wcnt++; u = nword[a], v = nword[b]; } else { if(vword.find(b) == vword.end()) vword[b] = wcnt++; u = nword[a], v = vword[b]; } flag = false; memset(vis, false, sizeof(vis)); dfs(u, v); if(flag) putchar('Y'); else putchar('M'); } else { sscanf(str,"%s%s%s%s%s%s",word[3], word[3], word[3], word[3], word[2], word[4]); string a, b; a = word[2]; b = word[4]; if(vword.find(a) == vword.end()) vword[a] = wcnt++; sscanf(str,"%s",word[3]); if(word[3][0] == 'a') { if(nword.find(b) == nword.end()) nword[b] = wcnt++; u = vword[a], v = nword[b]; } else { if(vword.find(b) == vword.end()) vword[b] = wcnt++; u = vword[a], v = vword[b]; } flag = false; memset(vis, 0,sizeof(vis)); dfs(u, v); if(flag) putchar('Y'); else putchar('M'); } } } puts(""); } return 0;}
0 0
- hdu 4096
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- C/C++ 32位/64位 sizeof(数据类型)
- Spring官网改版后下载
- 《剑指Offer》面试题:连续子数组的最大和
- mysql查询实例
- 虚基类中的虚函数在部分虚函数表中为0
- hdu 4096
- C++编程实现单链表的逆置
- reverse words in a sentence
- html之实战二--用table和form完成注册界面
- spring+struts2整合(二)
- 合并流
- Swipemenulistview
- 测试知识总结
- IOS学习首页