Descriptionthis
City X consists of n vertical and n horizontal infinite roads, forming n × n intersections. Roads (both vertical and horizontal) are numbered from 1 to n, and the intersections are indicated by the numbers of the roads that form them.spa
Sand roads have long been recognized out of date, so the decision was made to asphalt them. To do this, a team of workers was hired and a schedule of work was made, according to which the intersections should be asphalted.code
Road repairs are planned for n2 days. On the i-th day of the team arrives at the i-th intersection in the list and if none of the two roads that form the intersection were already asphalted they asphalt both roads. Otherwise, the team leaves the intersection, without doing anything with the roads.orm
According to the schedule of road works tell in which days at least one road will be asphalted.blog
Inputip
The first line contains integer n (1 ≤ n ≤ 50) — the number of vertical and horizontal roads in the city.ci
Next n2 lines contain the order of intersections in the schedule. The i-th of them contains two numbers hi, vi (1 ≤ hi, vi ≤ n), separated by a space, and meaning that the intersection that goes i-th in the timetable is at the intersection of the hi-th horizontal and vi-th vertical roads. It is guaranteed that all the intersections in the timetable are distinct.input
Outputstring
In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1.it
Sample Input
2
1 1
1 2
2 1
2 2
1 4
1
1 1
1
Hint
In the sample the brigade acts like that:
題目意思:有n條橫向的路和n條縱向的路,交叉獲得n*n個路口,要修理路到某個路口,只有當造成這個路口的兩條路都沒有被修過的時候,這兩條路纔會被修,問那一天修過路。
解題思路:。。。。。。要什麼思路分明是水題,能夠我看不懂英語啊,英語是不可能看懂的,這輩子都不可能了(仍是好好學吧,捂臉)
上代碼:
1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 int n,x,y,k,i; 6 int a[100],s1[100],s2[100]; 7 scanf("%d",&n); 8 k=1; 9 memset(s1,0,sizeof(s1)); 10 memset(s2,0,sizeof(s2)); 11 for(i=1;i<=n*n;i++) 12 { 13 scanf("%d%d",&x,&y); 14 if(s1[x]==0&&s2[y]==0) 15 { 16 s1[x]=1; 17 s2[y]=1; 18 a[k++]=i; 19 } 20 } 21 for(i=1;i<k;i++) 22 { 23 printf("%d ",a[i]); 24 } 25 printf("\n"); 26 return 0; 27 }