zoukankan      html  css  js  c++  java
  • Google Code Jam 2010 Round 1C Problem A. Rope Intranet

    Google Code Jam 2010 Round 1C Problem A. Rope Intranet
    https://code.google.com/codejam/contest/619102/dashboard#s=p0

    Problem A. Rope Intranet

    A company is located in two very tall buildings. The company intranet connecting the buildings consists of many wires, each connecting a window on the first building to a window on the second building.

    You are looking at those buildings from the side, so that one of the buildings is to the left and one is to the right. The windows on the left building are seen as points on its right wall, and the windows on the right building are seen as points on its left wall. Wires are straight segments connecting a window on the left building to a window on the right building.

    You've noticed that no two wires share an endpoint (in other words, there's at most one wire going out of each window). However, from your viewpoint, some of the wires intersect midway. You've also noticed that exactly two wires meet at each intersection point.

    On the above picture, the intersection points are the black circles, while the windows are the white circles.

    How many intersection points do you see?

    Input

    The first line of the input gives the number of test cases, TT test cases follow. Each case begins with a line containing an integer N, denoting the number of wires you see.

    The next N lines each describe one wire with two integers Ai and Bi. These describe the windows that this wire connects: Ai is the height of the window on the left building, and Biis the height of the window on the right building.

    Output

    For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the number of intersection points you see.

    Limits

    1 ≤ T ≤ 15.
    1 ≤ Ai ≤ 104.
    1 ≤ Bi ≤ 104.
    Within each test case, all Ai are different.
    Within each test case, all Bi are different.
    No three wires intersect at the same point.

    Small dataset

    1 ≤ N ≤ 2.

    Large dataset

    1 ≤ N ≤ 1000.

    Sample


    Input 
     

    Output 
     
    2
    3
    1 10
    5 5
    7 7
    2
    1 1
    2 2
    Case #1: 2
    Case #2: 0

     

    Solution:

    vector<int> linesL;
    vector<int> linesR;
    
    int solve()
    {
        int L1, R1, L2, R2, is = 0;
        int count = (int)linesL.size();
        for (int i = 0; i < count; i++) {
            L1 = linesL[i]; R1 = linesR[i];
            for (int j = i; j < count; j++) {
                L2 = linesL[j]; R2 = linesR[j];
                
                if ((L1 < L2 && R1 > R2) || (L1 > L2 && R1 < R2)) {
                    is++;
                }
            }
        }
        
        return is;
    }
    
    int main()
    {
        freopen("in.in", "r", stdin);
        freopen("out.out", "w", stdout);
        
        int T;
        scanf("%d
    ", &T);
        if (!T) {
            cerr << "Check input!" << endl;
            exit(0);
        }
        
        for (int t = 1; t <= T; t++) {
            cerr << "solving: #" << t << " / " << T << endl;
            
            linesL.clear();
            linesR.clear();
            
            int lc;
            scanf("%d
    ", &lc);
            
            for (int l = 0; l < lc; l++) {
                int lL, lR;
                scanf("%d %d
    ", &lL, &lR);
                linesL.push_back(lL);
                linesR.push_back(lR);
            }
            
            auto result = solve();
            printf("Case #%d: %d
    ", t, result);
        }
        
        fclose(stdin);
        fclose(stdout);
        return 0;
    }

  • 相关阅读:
    GB 51411-2020 金属矿山土地复垦工程设计标准
    GB/T 51413-2020 有色金属工业余热利用设计标准
    DL/T 1907.1-2018等最新电力行业标准
    GB 50205-2020 钢结构工程施工质量验收标准
    DL/T 5210.6-2019 电力建设施工质量验收规程 第6部分:调整试验
    GB/T 38640-2020 盲用数字出版格式
    GB 50325-2020 民用建筑工程室内环境污染控制标准(含条文说明)
    GB 50216-2019 铁路工程结构可靠性设计统一标准
    最新发布的国家标准下载(2020-5-21)
    bind、apply、call的区别
  • 原文地址:https://www.cnblogs.com/fatlyz/p/3678805.html
Copyright © 2011-2022 走看看