zoukankan      html  css  js  c++  java
  • Codeforces Round #323 (Div. 2) A 水

    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.

    Examples
    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:

    1. 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;
    2. 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;
    3. 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;
    4. 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天。他们每天来到一个交叉口,如果这个交叉口对应的水平路线和垂直路线都没有被施工过,他们将对其施工,否则不施工。问施工队第几天施过工。

    题解:数据很小,只需要开两个一维数组记录所有水平和垂直路线是否被施工过就行

     1 #include<iostream>
     2 #include<cstring>
     3 #include<cstdio>
     4 #include<queue>
     5 #include<stack>
     6 #include<vector>
     7 #include<map>
     8 #include<algorithm>
     9 #define ll __int64
    10 #define mod 1e9+7
    11 #define PI acos(-1.0)
    12 int n;
    13 using namespace std;
    14 int mp1[105],mp2[105];
    15 int ans[10005];
    16 int h,v;
    17 int main()
    18 {
    19     scanf("%d",&n);
    20     memset(mp1,0,sizeof(mp1));
    21     memset(mp2,0,sizeof(mp2));
    22     memset(ans,0,sizeof(ans));
    23     int jishu=0;
    24     for(int i=1;i<=n*n;i++)
    25     {
    26         scanf("%d %d",&h,&v);
    27         if(mp1[h]==0&&mp2[v]==0)
    28         {
    29             mp1[h]=1;
    30             mp2[v]=1;
    31             ans[jishu]=i;
    32             jishu++;
    33         }
    34     }
    35     cout<<ans[0];
    36     for(int i=1;i<jishu;i++)
    37         cout<<" "<<ans[i];
    38     cout<<endl;
    39     return 0;
    40 }
  • 相关阅读:
    mssql:tsql;创建表;给表添加约束;使用变量;事务,索引,视图;存储过程;触发器trigger;播放器http://www.smartgz.com/blog/Article/956.asp
    str.Replace(" ","");
    DataGrid分页;指定列的总和和平均值;显示鼠标背景色;弹出式窗口;
    .net 面试题 (1)
    数据绑定技术_单值数据绑定示例;将 DataTable,DataSet,DataView,DataReader 绑定到 DataGrid 控件示例;DataBinder.Eval;数组的值赋给ListBox1;Hashtable 绑定到;RadioButtonList;将XML 文件做为数据源绑定到控件
    Lession 17 Always young 保持年轻
    智力面试题
    Lession 16 A Polite request 彬彬有礼的要求
    几道 C 语言面试题
    建表的范例脚本,存储过程中参数的命名
  • 原文地址:https://www.cnblogs.com/hsd-/p/5682968.html
Copyright © 2011-2022 走看看