cqyz oj | 缃曡鐨勭З搴?| 鎷撴墤鎺掑簭
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cqyz oj | 缃曡鐨勭З搴?| 鎷撴墤鎺掑簭相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/isp' title='isp'>isp
des 绱㈠紩 hid ack ring tchar putc tinDescription
銆€銆€涓€涓弽绋€涔︾睄鐨勬敹钘忓鏈€杩戝彂鐜颁簡涓€鏈敤闄岀敓鐨勮瑷€鍐欑殑涓€鏈功锛岃繖绉嶈瑷€閲囩敤鍜岃嫳璇竴鏍风殑瀛楁瘝銆傝繖鏈功鏈夌畝鍗曠殑绱㈠紩锛屼絾鍦ㄧ储寮曚腑鐨勬潯鐩殑娆″簭涓嶅悓浜庢牴鎹嫳璇瓧姣嶈〃缁欏嚭鐨勫瓧鍏告帓搴忕殑娆″簭銆傝繖浣嶆敹钘忓璇曞浘閫氳繃绱㈠紩鏉ョ‘瀹氳繖涓彜鎬殑瀛楁瘝琛ㄧ殑瀛楃鐨勬搴忥紝(鍗冲绱㈠紩鏉$洰缁勬垚鐨勫簭鍒楄繘琛屾暣鐞?锛屼絾鍥犱负浠诲姟鍐楅暱鑰屼箯鍛筹紝灏辨斁寮冧簡銆?br />銆€銆€璇风紪鍐欑▼搴忓畬鎴愯繖浣嶆敹钘忓鐨勪换鍔★紝绋嬪簭杈撳叆涓€涓寜鐗瑰畾鐨勫簭鍒楁帓搴忕殑瀛楃涓查泦鍚堬紝纭畾瀛楃鐨勫簭鍒楁槸浠€涔堛€?/p>
Input
銆€銆€杈撳叆鏄敱澶у啓瀛楁瘝缁勬垚鐨勫瓧绗︿覆鐨勬湁搴忓垪琛紝姣忚涓€涓瓧绗︿覆銆傛瘡涓瓧绗︿覆鏈€澶氬寘鍚?0涓瓧绗︺€傝鍒楄〃鐨勭粨鏉熸爣蹇楁槸涓€涓崟涓€瀛楃’锛?rsquo;鐨勪竴琛屻€傚苟涓嶆槸鎵€鏈夌殑瀛楁瘝閮借鐢ㄥ埌锛屼絾璇ュ垪琛ㄨ暣娑靛浜庤閲囩敤鐨勯偅浜涘瓧姣嶅瓨鍦ㄧ潃涓€涓畬鍏ㄧ殑娆″簭銆?/p>
Output
銆€銆€杈撳嚭鍙兘瀛樺湪涓夌鎯呭喌锛氬鏋滀笉鑳藉緱鍒颁竴涓畬鍏ㄦ搴忥紝鍒欒緭鍑簄one锛涘鏋滄搴忎笉鍞竴锛屽垯杈撳嚭 non-unique锛涘鏋滆兘鍞竴纭畾锛屽垯杈撳嚭瀛楁瘝鐨勬帓鍒楁搴忋€?/p>
Sample Input 1
XWY
ZX
ZXY
ZXW
YWWX
#
Sample Output 1
XZYW
Hint
#include<cstdio> #include<iostream> #include<queue> #include<cstring> typedef long long ll; using namespace std; const int maxn = 30, maxm = 5005, inf = 0x3f3f3f3f; int fir[maxn], to[maxm], ne[maxm], np; void add(int x, int y) { ne[++np] = fir[x]; fir[x] = np; to[np] = y; } char w[maxm][maxn]; int cnt; void data_in() { char tmp[maxn]; cnt = 0; while(true) { scanf("%s", tmp); if(tmp[0] == 鈥?/span>#鈥?/span>) break; strcpy(w[++cnt], tmp); } } int n; int rd[maxn]; int mark[maxn], ha[maxn][maxn]; vector<int> topo; int toposort() { int ret = 1; queue<int> Q; for(int i=0; i<26; i++) if(mark[i] && !rd[i]) Q.push(i); while(!Q.empty()) { if(Q.size()>=2) ret = 2; int u = Q.front(); Q.pop(); topo.push_back(u); for(int i=fir[u]; i; i=ne[i]) { int v = to[i]; if(!--rd[v]) Q.push(v); } } if(topo.size() < n) ret = 0; return ret; } void sett() { for(int i=2; i<=cnt; i++) { int j = i-1, k = 0; while(w[i][k] && w[j][k]) { if(w[i][k] != w[j][k]) break; k++; } if(w[i][k] && w[j][k]){ int x = w[i][k] - 鈥?/span>A鈥?/span>, y = w[j][k] - 鈥?/span>A鈥?/span>; if(ha[x][y]) continue; ha[x][y] = 1; add(x, y); rd[y]++; mark[x]++; mark[y]++; } } n = 0; for(int i=0; i<26; i++) if(mark[i]) n++; } void solve() { sett(); int ok = toposort(); if(ok == 0) puts("none"); else if(ok == 2) puts("non-unique"); else for(int i = topo.size()-1; i>=0; i--) putchar(topo[i]+鈥?/span>A鈥?/span>); } int main() { data_in(); solve(); return 0; } /* XWY ZX ZXY ZXW YWWX # */
以上是关于cqyz oj | 缃曡鐨勭З搴?| 鎷撴墤鎺掑簭的主要内容,如果未能解决你的问题,请参考以下文章