Code Forces 583 A. Asphalting Roads(水~)

Description
有两排点,每排n个,现在在这两排点之间连n*n条边,每连完一条边这条边的两个端点就被标记,每次连边如果两端点都没被标记则输出这条边的编号
Input
第一行一个整数n表示点数,之后n*n行每行两个整数描述一条边
Output
输出连边时两端点都没被标记的边的编号
Sample Input
2
1 1
1 2
2 1
2 2
Sample Output
1 4
Solution
水题
Code

#include<stdio.h>
#include<string.h>
int n,ver[55],hor[55],ans[55],res;
int main()
{
    while(~scanf("%d",&n))
    {
        memset(ver,0,sizeof(ver));
        memset(hor,0,sizeof(hor));
        res=0;
        for(int i=1;i<=n*n;i++)
        {
            int a,b;
            scanf("%d%d",&a,&b);
            if(!ver[a]&&!hor[b])
            {
                ver[a]=hor[b]=1;
                ans[res++]=i;
            }
        }
        for(int i=0;i<res;i++)
            printf("%d%c",ans[i],i==res-1?'\n':' ');
    }
    return 0;
}

你可能感兴趣的:(Code Forces 583 A. Asphalting Roads(水~))