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 }
  • 相关阅读:
    date之Hi时间的思考
    空循环比较 for foreach array_map array_walk
    ECSHOP 数据库结构说明 (适用版本v2.7.3)
    自定义写入读出文件作为存储的函数
    session 重写进入redis测试
    单独批次性任务采用MySQL定时器解决需求
    php 接收 Content-Type 是 application/json的请求数据
    centos 6.4 mysql rpm 离线安装【备忘】
    solr单机版安装与基本部署
    vim&vi在编辑的时候突然卡死,不接收输入问题的解决
  • 原文地址:https://www.cnblogs.com/hsd-/p/5682968.html
Copyright © 2011-2022 走看看