题意
修路,一次选定一个横排一个竖排,如果横排竖排都没修,就把横排和竖排都修好,否则不用管。给出你若干修路尝试,问你哪些尝试最终执行了。
思路
照着题意简单模拟一下就好了。
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> #include <set> #include <map> #include <queue> #include <cmath> using namespace std; int hori[55],vect[55]; int main() { int n; scanf(" %d",&n); for(int i = 1;i <= n*n;i++){ int a,b; scanf(" %d %d",&a,&b); if(!hori[a] && !vect[b]){ printf("%d ",i); hori[a] = vect[b] = true; } } return 0; } |