HDU 1285 确定比赛名次
2012-07-16 13:59
127 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1285
好久好久没编程了。。。。几个月了。。。。感觉很费劲!基本思想很容易。。。。这里对输入的处理比较关键。。。。因为对于其中2位对手来说。。
只有三种情况(通过多次比赛后最终的结果)。。。还有n==1的时候。。。下面的break漏了会WA。。。
好久好久没编程了。。。。几个月了。。。。感觉很费劲!基本思想很容易。。。。这里对输入的处理比较关键。。。。因为对于其中2位对手来说。。
只有三种情况(通过多次比赛后最终的结果)。。。还有n==1的时候。。。下面的break漏了会WA。。。
#include <iostream> using namespace std; int g[505][505]; int ingree[505]; int main() { int n, m; while(~scanf("%d%d", &n, &m)) { memset(g, 0, sizeof(g)); memset(ingree, 0, sizeof(ingree)); while (m--) { int a, b; scanf("%d%d", &a, &b); if (g[a][b] == 0 && g[b][a] == 0)//处理那3种情况 { g[a][b] = 1; ingree[b]++; } else { if (g[a][b] == 0 && g[b][a] == 1) { g[b][a] = 0; ingree[a]--; } } } if (n == 1)//n == 1的情况 { puts("1"); } else { int count = 0; for (int cnt = 1; cnt <= n; cnt++) { for (int i = 1; i <= n; i++) { if (ingree[i] == 0) { ingree[i] = -1; printf(count == 0 ? "%d" : " %d", i); count++; for (int j = 1; j <= n; j++) { if (g[i][j] == 1) { ingree[j]--; } } break;//每轮只扫一遍,所以不能漏 } } } puts(""); } } return 0; }
相关文章推荐
- hdu 1285 确定比赛名次
- HDU 1285:确定比赛名次 【拓扑排序】
- hdu 1285 确定比赛名次
- 拓扑排序学习小记 HDU 1285 确定比赛名次 + HDU 2647 Reward
- HDU 1285 确定比赛名次(拓扑排序+优先队列)
- hdu 【1285】 确定比赛名次
- hdu 1285 确定比赛名次 拓扑排序
- hdu 1285 确定比赛名次(很典型的拓扑排序)
- 确定比赛名次(http://acm.hdu.edu.cn/showproblem.php?pid=1285)
- hdu 1285 确定比赛名次(给一个拓扑有序图要求输出拓扑有序序列)
- HDU 1285 确定比赛名次
- HDU 1285 确定比赛名次 Topsort
- HDU 1285 确定比赛名次(拓扑排序)
- HDU 1285 确定比赛名次
- HDU 1285 确定比赛名次(简单拓扑排序)
- HDU 1285 确定比赛名次(toposort)
- 【HDU - 1285 确定比赛名次】 拓扑排序
- hdu-1285 确定比赛名次
- hdu 1285 确定比赛名次
- 拓扑排序模板-优先队列 hdu 1285 确定比赛名次