sicily 1021

好久没写C/c++了,明天有个小比赛,然后找了一道超水的题来练手,结果很悲剧。。。虽然是1AC,解题书路就是用数组模仿个链表。。。。

/* * ===================================================================================== * * Filename: test.cpp * * Description: * * Version: 1.0 * Created: 04/06/2012 08:09:29 PM * Revision: none * Compiler: gcc * * Author: alfredtofu (Tofu), alfredtofu@gmail.com * Company: * * ===================================================================================== */ #include <iostream> #include <string> #include <stack> #include <cstring> using namespace std; struct Pair { int x; int y; }; int main() { int n; int a, b, c; int next[100002]; cin >> n; while(n != 0) { bool ok = false; memset(next, -1, sizeof(next)); stack<Pair> s; for(int i = 0; i < n; i++) { cin >> a >> b; ok = false; if(a > b) { c = a; a = b; b = c; } if(a + 1 == b) { next[a] = b; ok = true; } else if(next[a + 1] == b - 1){ next[a] = b; ok = true; } if(!ok) { Pair tmp; tmp.x = a; tmp.y = b; s.push(tmp); } else { Pair tmp; while(!s.empty()) { tmp = s.top(); ok = false; if(tmp.x + 1 == tmp.y) { next[tmp.x] = tmp.y; ok = true; }else if(next[tmp.x + 1] == tmp.y - 1) { next[tmp.x] = tmp.y; ok = true; } if(!ok) break; s.pop(); } } } cin >> n; if(s.empty()) cout << "Yes\n"; else cout << "No\n"; } return 0; }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值