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.
Input
Each line in the input will contain two positive integers a(0 <a20000) andb (0 < b20000).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\n", ++cas, ans);
}
return 0;
}
UVA 10790 (13.08.06)的更多相关文章
- UVA 253 (13.08.06)
Cube painting We have a machine for painting cubes. It is supplied withthree different colors: blu ...
- UVA 573 (13.08.06)
The Snail A snail is at the bottom of a 6-foot well and wants to climb to the top.The snail can cl ...
- UVA 10499 (13.08.06)
Problem H The Land of Justice Input: standard input Output: standard output Time Limit: 4 seconds In ...
- UVA 10025 (13.08.06)
The ? 1 ? 2 ? ... ? n = k problem Theproblem Given the following formula, one can set operators '+ ...
- UVA 10194 (13.08.05)
:W Problem A: Football (aka Soccer) The Problem Football the most popular sport in the world (ameri ...
- UVA 465 (13.08.02)
Overflow Write a program that reads an expression consisting of twonon-negative integer and an ope ...
- UVA 10494 (13.08.02)
点此连接到UVA10494 思路: 采取一种, 边取余边取整的方法, 让这题变的简单许多~ AC代码: #include<stdio.h> #include<string.h> ...
- UVA 424 (13.08.02)
Integer Inquiry One of the first users of BIT's new supercomputer was Chip Diller. Heextended his ...
- UVA 10106 (13.08.02)
Product The Problem The problem is to multiply two integers X, Y. (0<=X,Y<10250) The Input T ...
随机推荐
- 【LOJ】#2174. 「FJOI2016」神秘数
题解 这道题的结论很显然= = 就是暴力求的话,把一个区间的数排一下序,如果当前这个数大于前面所有数的前缀和+1,那么前缀和+1即我们所求的答案 那么我们设置一个当前答案(初始为1),在主席树上求出来 ...
- Socket编程(一):建立与客户端的连接并接受数据
我们这里利用Socket在模拟一个客户端与服务器通信,其实客户端与服务端通信就像人与人打电话一样,想要给一个人打电话,我们首先必须要有手机,必须知道对方的手机号码,这里Socket就好比一部手机,而短 ...
- 哈尔滨理工大学第七届程序设计竞赛初赛(高年级组)I - B-旅行
题目描述 小z放假了,准备到RRR城市旅行,其中这个城市有N个旅游景点.小z时间有限,只能在三个旅行景点进行游玩.小明租了辆车,司机很善良,说咱不计路程,只要你一次性缴费足够,我就带你走遍RRR城. ...
- android intent 传递 二进制数据
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha 实现序列化.
- luoguP1354房间最短路问题
判断两点间连通性,建图跑floyed #include<bits/stdc++.h> using namespace std; ; struct node { ],x; }q[N];dou ...
- [BZOJ4289][PA2012]TAX(最短路)
首先考虑一种暴力做法,为每条边拆成两条有向边,各建一个点.若某两条边有公共点,则在边所对应的点之间连一条边,权值为两条边中的较大值.这样跑最短路是$O(m^2\log m)$的. 用类似网络流中补流的 ...
- 【插头DP】BZOJ1814-Formula
[题目大意] 给出一个m*n的矩阵里面有一些格子为障碍物,求经过所有非障碍格子的哈密顿回路个数. [思路] 最典型的插头DP.分为三种情况: (1)当前格子既没有上插头也没有左插头. 如果下边和右边都 ...
- ElasticSearch学习笔记--2、ES相关配置
1.配置文件 ES的配置文件位置:config/elasticsearch.yml可以直接搜索elasticsearch.yml 2.配置远程api访问 network.host: 192.168.1 ...
- bzoj 3165
题意: 给出平面上一些线段,在线询问与x=x0相交的线段中,交点y最大的线段的标号,支持添加线段. 大概思路: 用线段树维护,线段树每个线段记录贯穿(左右端点在该区间外或上)的原线段中能覆盖其它贯穿该 ...
- windows server 2008 r2, 每隔一段时间自动关机
前段时间在做Exchange 2010测试的时候,由于windows server 2008 r2试用过期,开机后二个小时就会自动关机,可是我又不想重装系统,加为那样我可能需要重装好多东西,包括 ...