zoukankan      html  css  js  c++  java
  • codeforces #323 div 2 A. Asphalting Roads(暴力

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

    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条横向的路,n条纵向的路,交叉得到n*n个路口...

    要修理路.到某个路口,只有当形成这个路口的两条路都没有被修过的时候,这两条路才会被修.否则什么都不会做.

    给出道路数n以及时间安排表(第i天到达哪个路口..路口用两条路的标号来表示)

    问哪天修路了...

    理解题意就很好搞了

    开两个bool数组记录修路情况即可

     1 /*************************************************************************
     2     > File Name: code/cf/#323/A.cpp
     3     > Author: 111qqz
     4     > Email: rkz2013@126.com 
     5     > Created Time: 2015年10月04日 星期日 00时24分37秒
     6  ************************************************************************/
     7 
     8 #include<iostream>
     9 #include<iomanip>
    10 #include<cstdio>
    11 #include<algorithm>
    12 #include<cmath>
    13 #include<cstring>
    14 #include<string>
    15 #include<map>
    16 #include<set>
    17 #include<queue>
    18 #include<vector>
    19 #include<stack>
    20 #include<cctype>
    21                  
    22 #define yn hez111qqz
    23 #define j1 cute111qqz
    24 #define ms(a,x) memset(a,x,sizeof(a))
    25 using namespace std;
    26 const int dx4[4]={1,0,0,-1};
    27 const int dy4[4]={0,-1,1,0};
    28 typedef long long LL;
    29 typedef double DB;
    30 const int inf = 0x3f3f3f3f;
    31 const int N=76;
    32 int ans[5000];
    33 int n;
    34 int a,b;
    35 bool x[N],y[N];
    36 int main()
    37 {
    38   #ifndef  ONLINE_JUDGE 
    39    freopen("in.txt","r",stdin);
    40   #endif
    41 
    42    scanf("%d",&n);
    43    ms(x,false);
    44    ms(y,false);
    45    int cnt = 0 ;
    46    for ( int i = 0 ; i < n*n ; i++)
    47     {
    48     scanf("%d %d",&a,&b);
    49     if (!x[a]&&!y[b])
    50     {
    51         cnt++;
    52         ans[cnt] = i+1;
    53         x[a] = true;
    54         y[b] = true;
    55     }
    56     }
    57    for ( int i = 1 ; i < cnt ; i++)
    58        printf("%d ",ans[i]);
    59  //  cout<<"cnt:"<<cnt<<endl;
    60    printf("%d
    ",ans[cnt]);
    61   
    62    
    63  #ifndef ONLINE_JUDGE  
    64   fclose(stdin);
    65   #endif
    66     return 0;
    67 }
    View Code
  • 相关阅读:
    SDOI2008Cave 洞穴勘测
    使用Nginx反向代理和内容替换模块实现网页内容动态替换功能
    使用Nginx反向代理和内容替换模块实现网页内容动态替换功能
    Js 变量声明提升和函数声明提升
    Js 变量声明提升和函数声明提升
    Golang-filepath使用
    Golang-filepath使用
    44、File类简介
    44、File类简介
    div/dom元素拖拽缩放插件,纯js实现拖拽缩放,不依赖jQuery~
  • 原文地址:https://www.cnblogs.com/111qqz/p/4854679.html
Copyright © 2011-2022 走看看