zoukankan      html  css  js  c++  java
  • UVA 10790 (13.08.06)

     

     How Many Points of Intersection? 

    We have two rows. There are a dots on the toprow andb dots on the bottom row. We draw line segments connecting every dot on the top row with every dot on the bottom row. The dots are arranged in such a way that the number of internal intersections among the line segments is maximized. To achieve this goal we must not allow more than two line segments to intersect in a point. The intersection points on the top row and the bottom are not included in our count; we can allow more than two line segments to intersect on those two rows. Given the value of a and b, your task is to computeP(a, b), the number of intersections in between the two rows. For example, in the following figurea = 2 and b = 3. This figure illustrates thatP(2, 3) = 3.

    epsfbox{p10790.eps}

    Input 

    Each line in the input will contain two positive integers a(0 <a$ le$20000) andb (0 < b$ le$20000).Input is terminated by a line where botha and b are zero. Thiscase should not be processed. You will need to process at most 1200 sets of inputs.

    Output 

    For each line of input, printin a line the serial of output followed by the value ofP(a, b). Look atthe output for sample input for details. You can assume that the output for the test cases will fit in64-bit signed integers.

    Sample Input 

    2 2
    2 3
    3 3
    0 0
    

    Sample Output 

    Case 1: 1
    Case 2: 3
    Case 3: 9
    

    解题思路请参考: http://www.cnblogs.com/xiaocai905767378/archive/2011/04/27/2030213.html

    注意啊注意: 用long long

    row_a = 20000

    roe_b = 20000 时, 会超啊~


    AC代码:

    #include<stdio.h>
    
    long long a, b;
    int cas = 0;
    
    int main() {
        while(scanf("%lld %lld", &a, &b) != EOF) {
            if(a == 0 && b == 0)
                break;
            long long ans = (a * (a-1) * b * (b-1) / 4);
            printf("Case %d: %lld
    ", ++cas, ans);
        }
        return 0;
    }
  • 相关阅读:
    Rsync企业实战之自动异地备份(转)
    Linux启动过程详解 (转)
    Linux系统下修改环境变量PATH路径的三种方法
    linux更改启动级别后,无法启动的问题解决
    MySQLAdmin用法
    mysql toolkit 用法[备忘] (转)
    mysql edit
    MySQL中SSL配置
    mysql ALTER COLUMN MODIFY COLUMN CHANGE COLUMN 区别及用法 (转)
    MySQL 使用mysqld_multi部署单机多实例详细过程 (转)
  • 原文地址:https://www.cnblogs.com/pangblog/p/3243849.html
Copyright © 2011-2022 走看看