City X consists of n vertical and n horizontal infinite roads, forming n × nintersections. 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.
InputThe 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.
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.
2 1 1 1 2 2 1 2 2
1 4
1 1 1
1
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.本
- 题用打表就行了,题意就是给你一个n,有N*N的期盼,每次往棋盘里放棋子,每放一颗,那么这颗棋子所在的行和列都不能在放别的棋子了
- 问哪几次可以放棋子
- #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
const int maxn=1e5+5;
typedef long long ll;
#define INF 9999999
int a[55];
int b[55];
int c[55];
int main()
{
int n;
scanf("%d",&n);
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
int t=0;
for(int i=0;i<n*n;i++)
{
int x,y;
scanf("%d%d",&x,&y);
if(a[x]==0&&b[y]==0)
{
c[t++]=i+1;
a[x]=1;
b[y]=1;
}
}
for(int i=0;i<t;i++)
printf("%d ",c[i]);
printf("\n");
return 0;
}
本文介绍了一个基于城市道路铺设的工作调度算法。该算法通过记录已铺设的道路,在特定条件下选择需要进行工作的交叉口,确保每次施工都能有效进行。文章还提供了一个示例程序,展示了如何实现这一算法。

606

被折叠的 条评论
为什么被折叠?



