Codeforces Round #323 (Div. 2) A. Asphalting Roads
2015-10-05 13:58
519 查看
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
output
input
output
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
题目大意:
给定一个数m,表示有m条竖立的道路和m条横的要修的道路,然后给定
m*m条道路,表示这两条路需要修,如果有两条路都需要修的话就去修,否则
不用修缮。也就是说,只修不在同一行和同一列的
解题思路:
用两个数组分别记下x和y是否被修,然后只需要找出都没有用过的x和y,输出是第几条就行了
直接上代码:
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
题目大意:
给定一个数m,表示有m条竖立的道路和m条横的要修的道路,然后给定
m*m条道路,表示这两条路需要修,如果有两条路都需要修的话就去修,否则
不用修缮。也就是说,只修不在同一行和同一列的
解题思路:
用两个数组分别记下x和y是否被修,然后只需要找出都没有用过的x和y,输出是第几条就行了
直接上代码:
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <vector> #include <queue> #include <algorithm> #include <set> using namespace std; #define MM(a) memset(a,0,sizeof(a)) typedef long long LL; typedef unsigned long long ULL; const int maxn = 50+5; const int mod = 1000000007; const double eps = 1e-7; bool a[maxn], b[maxn]; int main() { int m; cin>>m; MM(a); MM(b); for(int i=1; i<=m*m; i++) { int x, y; cin>>x>>y; if(!a[x] && !b[y]) { cout<<i<<" "; a[x] = 1; b[y] = 1; } } return 0; }
相关文章推荐
- C#(ASP.Net)获取当前路径的方法集合
- ASP.NET页面内传递参数方法
- C# ,asp.net 获取当前,相对,绝对路径
- 学习ThinkPHP3.2.2:video13,功能的继承,类似ASP的include
- x01.TodoList:Asp.Net 5 初探
- Rich控件一
- Codeforces Round #323 (Div. 2) A. Asphalting Roads
- asp.net数据类型--泛型
- Aspects 源代码解析<一>
- Codeforces 583 DIV2 Asphalting Roads 模拟
- Codeforces Round #323 (Div. 2) 583A. Asphalting Roads
- codeforces #323 div 2 A. Asphalting Roads(暴力
- ASP.NET连接ACCESS数据库WEB.CONFIG内路径最优写法
- ASP.NET 无法向会话状态服务器发出会话状态请求请。确保 ASP.NET State Service (ASP.NET 状态服务)已启动
- cf#323-div2-A. Asphalting Roads-简单模拟
- Asp.Net MVC HTML Helper 中 LabelFor TextBoxFor的一些理解
- Asp.Net MVC 使用 DataAnnotations 进行模型验证
- Asphalting Roads
- ASP.NET,Web界面利用Button来实现将telerik:RadGrid表格内数据导出Excel
- Codeforces Round #323 A Asphalting Roads