codeforces 583A Asphalting Roads
来源:互联网 发布:迅游加速器mac版 编辑:程序博客网 时间:2024/06/05 10:12
点击打开链接
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.
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.
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.
21 11 22 12 2
1 4
11 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.
注意:审清题。
#include<stdio.h>#include<string.h>int main(){ int n,a,b,x[100000],y[100000]; memset(x,0,sizeof(x)); memset(y,0,sizeof(y)); scanf("%d",&n); int f[100000],k=0; memset(f,0,sizeof(f)); for(int i=0; i<n*n; i++) { scanf("%d%d",&a,&b); if(x[a]==0&&y[b]==0) { x[a]=1; y[b]=1; f[k++]=i; } } for(int i=0;i<k;i++) { if(i==0) printf("%d",f[i]+1); else printf(" %d",f[i]+1); } printf("\n"); return 0;}
- Codeforces 583A Asphalting Roads
- codeforces 583A Asphalting Roads
- Codeforces Round #323 (Div. 2) 583A. Asphalting Roads
- Codeforces Round #323 A Asphalting Roads
- A. Asphalting Roads
- Codeforces Round #323 (Div. 2) A. Asphalting Roads
- Codeforces Round #323 (Div. 2) A. Asphalting Roads
- Codeforces Round #323 (Div. 2)A. Asphalting Roads
- Code Forces 583 A. Asphalting Roads(水~)
- 【Codeforces Round 323 (Div 2)A】【水题】Asphalting Roads 行列之进行首次操作
- Asphalting Roads
- cf#323-div2-A. Asphalting Roads-简单模拟
- Asphalting Roads [水题]
- nwerc2013 A - Absurdistan Roads
- poj1724 ROADS (spfa + A*)
- CodeForces 583A
- Destroying Roads - CodeForces 543 B
- codeforces 544 D. Destroying Roads
- Sublime Text 3 快捷键
- idea写代码注意事项
- C3P0连接池使用
- Spring MVC中Controller的四种配置方法
- hpuoj 【1166】阶乘问题(一) 【数学】&&【思维转化】
- codeforces 583A Asphalting Roads
- iOS懒加载不执行的坑
- LeetCode之路:543. Diameter of Binary Tree
- 求素数及素数表的获取
- parse(),stringify()
- Notification通知
- 使用nose组织自动化测试用例(1)
- uva10305--拓扑
- Unity Android 支付宝 接入