您的位置:首页 > 编程语言 > ASP

【Codeforces Round 323 (Div 2)A】【水题】Asphalting Roads 行列之进行首次操作

2015-11-13 11:19 555 查看
A. Asphalting Roads

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

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.
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.
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.
According to the schedule of road works tell in which days at least one road will be asphalted.

Input
The first line contains integer n (1 ≤ n ≤ 50)
— the number of vertical and horizontal roads in the city.
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.

Output
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.

Sample test(s)

input
2
1 1
1 2
2 1
2 2


output
1 4


input
1
1 1


output
1


Note
In the sample the brigade acts like that:

On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road;

On the second day the brigade of the workers comes to the intersection of the 1-st horizontal and the 2-nd vertical road. The 2-nd vertical road hasn't been asphalted, but as the 1-st horizontal road has been asphalted on the first day, the workers leave and
do not asphalt anything;

On the third day the brigade of the workers come to the intersection of the 2-nd horizontal and the 1-st vertical road. The 2-nd horizontal road hasn't been asphalted but as the 1-st vertical road has been asphalted on the first day, the workers leave and do
not asphalt anything;

On the fourth day the brigade come to the intersection formed by the intersection of the 2-nd horizontal and 2-nd vertical road. As none of them has been asphalted, the workers asphalt the 2-nd vertical and the 2-nd horizontal road.

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1#define rs o<<1|1typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}
template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}
const int N=55,M=0,Z=1e9+7,ms63=1061109567;
int casenum,casei;
int n,y,x;
int line
,list
;
int main()
{
while(~scanf("%d",&n))
{
MS(line,0);
MS(list,0);
for(int i=1;i<=n*n;i++)
{
scanf("%d%d",&y,&x);
if(!line[y]&&!list[x])
{
printf("%d ",i);
line[y]=list[x]=1;
}
}
puts("");
}
return 0;
}
/*
【题意】
给你n*n(n∈[1,50])个操作,每个操作选取一个二维平面上的点(横纵坐标都是[1,n]范围)。
如果对于一个操作,其横纵坐标上之前都没有选过点,那么我们会选择这个操作执行;否则这个操作不执行。
现在让你输出所有执行的操纵。

【类型】
水题

【分析】
直接暴力哈希行列。

*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  codeforces 水题