Description
N couples are standing in a circle, numbered consecutively clockwise from 1 to 2N. Husband and wife do not always stand together. We remove the couples who stand together until the circle is empty or we can't remove a couple any more. Can we remove all the couples out of the circle?
Input
There are multiple test cases. The first line contains an integer T, indicating the number of test cases. In each case, the first line is an integer N(1 <= N <= 100000)----the number of couples. In the following N lines, each line contains two integers ---- the numbers of each couple.
Output
Output "Yes" if we can remove all the couples out of the circle. Otherwise, output "No".
Sample Input
2 4 1 4 2 3 5 6 7 8 2 1 3 2 4
Sample Output
Yes No | ||
各种各样的错误 算是熬过来了 弄了一上午 这是WA,测试Sample Input并没有问题后来把两者顺序颠倒一下测试 发现stack没有清空 之后用了一个while清空stack 出来的结果是RE看遍整个程序没发现什么可优化的地方(是我技术太差) 后来找到一种办法可以把while去掉 把stack<int> sta放到for循环中 每次结束后重新构造一个stack 结果继续RE顿时炸了... 那输入输出没法优化 唯一能优化的就是两个for里面的语句 我在想能不能少用一点if 于是有了这样的代码
于是AC了... 两个for都改了 如果有高手能解答一下这个程序到底是哪一步快了就最好了-,- | ||
|