zoukankan      html  css  js  c++  java
  • Asphalting Roads(判断什么时候修马路)

    Description

    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 Input

    Input

    2
    1 1
    1 2
    2 1
    2 2
    

    Output

    1 4 
    

    Input

    1
    1 1
    

    Output

    1
    说是有n条横向的路,n条纵向的路,交叉得到n*n个路口...
    
    
    要修理路.到某个路口,只有当形成这个路口的两条路都没有被修过的时候,这两条路才会被修.否则什么都不会做.
    给出道路数n以及时间安排表(第i天到达哪个路口..路口用两条路的标号来表示)
    问哪天修路了... 
    #include<stdio.h>
    #include<string.h>
    int main()
    {
        int n,a[10000]={0},b[10000]={0},i,v,u,ans[10000];
        while(scanf("%d",&n)!=EOF)
        {
            int j=0;
            for(i=1;i<=n*n;i++)
            {
                scanf("%d%d",&u,&v);
                if(a[u]==0&&b[v]==0)//都没修过才修
                {
                    a[u]=1;
                    b[v]=1;
                    ans[j++]=i;
                }
            }
            for(i=0;i<j;i++)
                printf("%d ",ans[i]);
            puts("");
            memset(a,0,sizeof(a));
            memset(b,0,sizeof(b));
        }
        return 0;
    }
    
  • 相关阅读:
    Halcon HWindowControl 控件中图像的缩放与移动
    OpenCV cv::mean()函数详解
    OpenCV 霍夫变换(Hough Transform)
    OpenCV 图像分割
    OpenCV 使用ROI进行图像切割
    OpenCV 轮廓查找与绘制-最小外接矩形
    OpenCV 提取轮廓的凸包、外包矩形、最小外包矩形、最小外包圆
    KubeDL 加入 CNCF Sandbox,加速 AI 产业云原生化
    DataWorks 功能实践速览
    coredump 瘦身风云
  • 原文地址:https://www.cnblogs.com/zcy19990813/p/9702828.html
Copyright © 2011-2022 走看看