Codeforces Round #323 (Div. 2) A 水
1 second
256 megabytes
standard input
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.
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.
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(1 ≤ N ≤ 50)条水平路线和N条垂直路线分割出N*N个交叉口。有一个施工队将对城市路线进行施工N*N天。他们每天来到一个交叉口,如果这个交叉口对应的水平路线和垂直路线都没有被施工过,他们将对其施工,否则不施工。问施工队第几天施过工。
题解:数据很小,只需要开两个一维数组记录所有水平和垂直路线是否被施工过就行
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<algorithm>
#define ll __int64
#define mod 1e9+7
#define PI acos(-1.0)
int n;
using namespace std;
int mp1[],mp2[];
int ans[];
int h,v;
int main()
{
scanf("%d",&n);
memset(mp1,,sizeof(mp1));
memset(mp2,,sizeof(mp2));
memset(ans,,sizeof(ans));
int jishu=;
for(int i=;i<=n*n;i++)
{
scanf("%d %d",&h,&v);
if(mp1[h]==&&mp2[v]==)
{
mp1[h]=;
mp2[v]=;
ans[jishu]=i;
jishu++;
}
}
cout<<ans[];
for(int i=;i<jishu;i++)
cout<<" "<<ans[i];
cout<<endl;
return ;
}
Codeforces Round #323 (Div. 2) A 水的更多相关文章
- Codeforces Round #365 (Div. 2) A 水
A. Mishka and Game time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #323 (Div. 1) B. Once Again... 暴力
B. Once Again... Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/582/probl ...
- Codeforces Round #323 (Div. 2) C. GCD Table 暴力
C. GCD Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/583/problem/C ...
- 重复T次的LIS的dp Codeforces Round #323 (Div. 2) D
http://codeforces.com/contest/583/problem/D 原题:You are given an array of positive integers a1, a2, . ...
- Codeforces Round #404 (Div. 2)(A.水,暴力,B,排序,贪心)
A. Anton and Polyhedrons time limit per test:2 seconds memory limit per test:256 megabytes input:sta ...
- Codeforces Round #408 (Div. 2)(A.水,B,模拟)
A. Buying A House time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- Codeforces Round #323 (Div. 2) D. Once Again... 乱搞+LIS
D. Once Again... time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #323 (Div. 2) C. GCD Table map
题目链接:http://codeforces.com/contest/583/problem/C C. GCD Table time limit per test 2 seconds memory l ...
- Codeforces Round #394 (Div. 2)A水 B暴力 C暴力 D二分 E dfs
A. Dasha and Stairs time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- nginx installl
参考http://jingyan.baidu.com/album/4b07be3cbbb54848b380f322.html?picindex=5 安装nginx需要的依赖包 wget 下载 编译安装 ...
- 驾考试题的json代码
{ "statusCode": "000000", "desc": "请求成功", "result" ...
- iphone丢失或忘记锁屏密码
1.首先,我们要保证手机资料已经备份到iColud或者电脑(不想要恢复备份的可跳过该步骤) 2.保证,手机的 设置 → iCloud 处于打开状态: 3.手机的查找iphone软件登录了iColud ...
- 64位系统InlineHook
APIHook64Class.h #ifndef APIHOOK64CLASS_H_ #define APIHOOK64CLASS_H_ #include <Windows.h> clas ...
- python 使用requests 请求 https 接口 ,取消警告waring
response = requests.request("POST", url, timeout=20, data=payload, headers=headers, proxie ...
- 4- vue django restful framework 打造生鲜超市 -restful api 与前端源码介绍
4- vue django restful framework 打造生鲜超市 -restful api 与前端源码介绍 天涯明月笙 关注 2018.02.20 19:23* 字数 762 阅读 135 ...
- 七、Shell printf 命令
Shell printf 命令 上一章节我们学习了 Shell 的 echo 命令,本章节我们来学习 Shell 的另一个输出命令 printf. printf 命令模仿 C 程序库(library) ...
- Linux ps与top命令
Linux ps与top命令 这两个命令都是查看系统进程信息的命令,但是用处有点儿不同 1.ps命令--提供系统过去信息的一次性快照 也就是说ps命令能够查看刚刚系统的进程信息 命令:ps aux或 ...
- VPS搭建***
yum -y install epel-release** yum update yum -y install python-setuptools m2crypto supervisor easy_i ...
- js数据类型的检测总结,附面试题--封装一个函数,输入任意,输出他的类型
一.javascript 中有几种类型的值 1.基本数据类型 : 包括 Undefined.Null.Boolean.Number.String.Symbol (ES6 新增,表示独一无二的值) 特点 ...