首页 > 其他分享 >UVA How Many Points of Intersection?

UVA How Many Points of Intersection?

时间:2023-04-20 21:32:43浏览次数:43  
标签:int segments two long Points UVA line Intersection row


  How Many Points of Intersection? 

a dots on the top row and b 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 compute P(ab), the number of intersections in between the two rows. For example, in the following figure a = 2 and b = 3. This figure illustrates that P(2, 3) = 3.





Input 

a ( 0 < a20000) and b ( 0 < b20000). Input is terminated by a line where both a and b

Output 

P(ab). Look at the output for sample input for details. You can assume that the output for the test cases will fit in 64-bit signed integers.

Sample Input 


2 22 3 3 3 0 0


Sample Output 


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



Problem setter: Md. Bahlul Haider

Special Thanks: Shahriar Manzoor


Miguel Revilla 2004-12-10





    题意:给出两个数字n,m分别代表上和下有多少个点,求这些点连成的线会有多少个交点。输出。。。找到之间的关系就可以根据式子求出来。




#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main()
{
    long long int n,m;
    int k = 0;
    while(scanf("%lld%lld",&n,&m)!=EOF)
    {
        k++;
        if(n == 0 && m == 0)
        {
            break;
        }
        long long int sum = 0;
        sum = (n-1)*n/2 * (m-1)*m/2;
        printf("Case %d: %lld\n",k,sum);
    }
    return 0;
}





标签:int,segments,two,long,Points,UVA,line,Intersection,row
From: https://blog.51cto.com/u_14834528/6210680

相关文章

  • (UVA) The ? 1 ? 2 ? ... ? n = k problem
    The?1?2?...?n=kproblemTheproblemGiventhefollowingformula,onecansetoperators'+'or'-'insteadofeach'?',inordertoobtainagivenk?1?2?...?n=kForexample:toobtaink=12,theexp......
  • How Many O's? UVA - 11038
    写下区间[a,b]的所有数 ,问一共有多少个0 #include<iostream>#include<cstring>#include<vector>usingnamespacestd;#defineintlonglongintn,f[40][40][2][2];vector<int>a;intdfs(intx,intcnt0,intflg,intlead){ if(x<0){ i......
  • Investigating Div-Sum Property UVA - 11361
     定问在[A,B]中,有多少个整数本身能被m整除,各个数位上数字之和也能被m整除?  #include<iostream>#include<cstring>#include<vector>usingnamespacestd;vector<int>a;intm,f[40][105][105][2];intdfs(intx,intv1,intv2,intflg){ if(x<0) retur......
  • UVA11806 Cheerleaders
    你有一个n×m的网格图,现在你要将K个人放在网格中,满足一下条件:网格图的四个边都至少有一个人。每个格子上不能有两个人。每个人必须都有位置。注意:四个角的人可以同时算作在两个边上  容斥原理   J=0时就是allAnswer#include<iostream>#include<cstri......
  • Hackers' Crackdown UVA11825
    你需要将n个集合分成尽量多组,使得每一组里面所有集合的并集等于全集  32122022014111013120   f[S]=max(f[S],f[S-j]+1)且j是一个包含所有点的集合#include<iostream>#include<algorithm>#include<cstring>usingname......
  • Robotruck UVA - 1169
    有n个垃圾,第i个垃圾的坐标为(xi,yi),重量为wi。有一个机器人,要按照编号从小到大的顺序捡起所有垃圾并扔进垃圾桶(垃圾桶在原点(0,0))。机器人可以捡起几个垃圾以后一起扔掉,但任何时候其手中的垃圾总重量不能超过最大载重C。两点间的行走距离为曼哈顿距离(即横坐标之差的绝对值加上纵......
  • Add Again UVA - 11076
     defineS,itissumofallpossiblepermutationsofagivensetofdigits.Forexample,ifthedigitsare<123>,thensixpossiblepermutationsare<123>,<132>,<213>,<231>,<312>,<321>andthesumofthemis......
  • The Super Powers UVA - 11752
     求1~2^64区间里,有多少合法数X合法数:X=a^b,至少存在2个不同的a #include<iostream>#include<algorithm>#include<vector>usingnamespacestd;constintN=65536+3;intb[int(1e6)];__int128_tMAX=1;voidinit(){ inti,j; b[0]=b[1]=1; fo......
  • LCM Cardinality UVA - 10892
    给出n,求有多少对(a,b)(a<b),满足LCM(a,b)=n 暴力求所有因数#include<iostream>#include<algorithm>#include<vector>usingnamespacestd;constintN=1e4+20;#defineintlonglongconstintinf=1e9;voidsov(intn){ vector<int>v;......
  • Again Prime? No Time. UVA - 10780
    给定m,n,求最大的k使得m^k∣n! 分解质因数   #include<iostream>#include<cstring>#include<sstream>usingnamespacestd;constintN=1e4+20;constintinf=1e9;intn,m,a[N],b[N];intprime[N],tot,vis[N];voidinit(inttop){ for(......