ZOJ-2954

来源:互联网 发布:mac移动硬盘隐藏文件 编辑:程序博客网 时间:2024/05/17 23:52

 模拟题,无算法,细心处理细节就行

#include<stdio.h>int main(){int t, n, m, tower[4][10], count[4];scanf("%d", &t);while (t--){int from, to, i, finish = 0;scanf("%d %d", &n, &m);count[1] = n, count[2] = count[3] = 0;for (i = 0; i < n; i++)tower[1][i] = n - i;for (i = 1; i <= m; i++){scanf("%d %d", &from, &to);if (finish)continue;if (count[from]&& (count[to] == 0|| (count[to]&& tower[from][count[from] - 1]< tower[to][count[to] - 1]))){tower[to][count[to]++] = tower[from][--count[from]];if (to == 3 && count[3] == n){printf("%d\n", i);finish = 1;}}else{printf("%d\n", -i);finish = 1;}}if (!finish)puts("0");}return 0;}


0 0
原创粉丝点击