/*1021. Couples 初始化存储:两夫妻的位置和下标对应,例如夫妻(1,4),则,他们存储时采用a[1] = 4, a[4] =1; 扫描a, 然后a[i]是否等于栈顶的值,即判断他们夫妻得,如果等于,则pop,否则push(i),即 存入a[i]的夫妻值 */ #include <iostream> #include <stdlib.h> #include <stack> using namespace std; int main() { int n; int a[2*100000+1]; while(1) { stack<int> temp; cin >> n; if( n== 0) break; int b,c; for(int i=0; i<n; i++) { cin >>b >> c; a[b] = c; a[c] = b; } for(int i=1; i<= 2*n; i++) { if(!temp.empty() && a[i] == temp.top()) temp.pop(); else temp.push(i); } if(temp.empty()) cout << "Yes" << endl; else cout << "No" << endl; } system ("pause"); return 0; }
Sicily.1021. Couples
最新推荐文章于 2019-06-26 23:26:56 发布