How Many Points of Intersection?

2024-08-24 22:38
文章标签 many points intersection

本文主要是介绍How Many Points of Intersection?,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

找规律题,最终可以简化为一个式子

  How Many Points of Intersection? 

We have two rows. There are 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.

\epsfbox{p10790.eps}

Input 

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

Output 

For each line of input, print in a line the serial of output followed by the value of 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 2
2 3
3 3
0 0

Sample Output 

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

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>
int main()
{long long a, b, s, i, j, n = 0;while(scanf("%lld%lld",&a,&b)!=EOF){n++;s = 0;if(a==0&&b==0) break;printf("Case %lld: %lld\n", n, (a - 1) * a / 2 * (b - 1) * b / 2);}return 0;
}

这篇关于How Many Points of Intersection?的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1103802

相关文章

uva 10061 How many zero's and how many digits ?(不同进制阶乘末尾几个0)+poj 1401

题意是求在base进制下的 n!的结果有几位数,末尾有几个0。 想起刚开始的时候做的一道10进制下的n阶乘末尾有几个零,以及之前有做过的一道n阶乘的位数。 当时都是在10进制下的。 10进制下的做法是: 1. n阶位数:直接 lg(n!)就是得数的位数。 2. n阶末尾0的个数:由于2 * 5 将会在得数中以0的形式存在,所以计算2或者计算5,由于因子中出现5必然出现2,所以直接一

【HDU】How Many Answers Are Wrong(带权并查集)

num[i]代表i到根节点的值 这道题一开始竟然以为是线段树= =!后来发现线段树无法进行子区间的维护 #include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn = 222222;int fa[maxn],num[maxn];int find_father(int

kubernetes Pod failed to create fsnotify watcher: too many open files

fs.nr_open: 控制单个进程可以打开的文件描述符的最大数量。单个进程的文件描述符限制可以通过 ulimit 命令来设置。 /proc/sys/fs/nr_open 是一个系统级别的全局参数,表示系统中单个进程能够打开的文件描述符总数的限制。/proc/sys/fs/file-max 系统级别,当前系统可打开的最大数量/etc/security/limits.conf 用户级别,指定用户

【HDU】4873 ZCC Loves Intersection 数学

传送门:【HDU】4873 ZCC Loves Intersection 题目大意:给你一个D维的空间,每个维度都有一条线段平行与该维度属于的轴(如X,Y,Z轴),且线段的端点坐标取值范围0~N-1,保证左端点严格小于右端点(除该维度,其他维度的值两端点均相等)。现在告诉你每条线段的左右端点的坐标都是随机的,0~N-1随机到的概率是完全相等的!现在如果两条线段如果相交于一点,你可以获得一点

C# 使用中点查找矩形的角(Find Corners of Rectangle using mid points)

考虑一个矩形 ABCD,我们给出了边 AD 和 BC 中点(分别为 p 和 q)的坐标以及它们的长度 L(AD = BC = L)。现在给定参数,我们需要打印 4 个点 A、B、C 和 D 的坐标。 例子:  输入:p = (1, 0)         q = (1, 2)         L = 2 输出:(0,0),(0,2),(2,2),(2,0) 解释: 打

for 出错 ValueError: too many values to unpack (expected 2) 遍历多个变量

贼简单的代码示例 for [i,j] in [range(3),range(3)]:print(i,j) 输出: ValueError: too many values to unpack (expected 2) 正确示例 for i,j in zip(range(3),range(3)):print(i,j) 输出: 0 0 1 1 2 2 原因:后面zip()包装了两个lis

Host '10.10.120.174' is blocked beacuse of many connection errors;

Host '10.10.120.174' is blocked beacuse of many connection errors;unblock with 'mysqldamin flush-hosts' #使用清楚缓存的方法,这样就会把计数清理掉,进入mysql控制台,执行:flush hosts; /usr/bin/mysqladmin  -u jiaobo -puukkgg  flus

【译】PCL官网教程翻译(18):估计一组点的视点特征直方图(VFH)签名 - Estimating VFH signatures for a set of points

英文原文查看 估计一组点的视点特征直方图(VFH)签名 本文描述了视点特征直方图([VFH])描述符,这是一种针对聚类(如对象)识别和6DOF姿态估计问题的点簇表示方法。 下图展示了一个VFH识别和姿态估计的例子。给定一组火车数据(除最左边的点云外,最上面一行、最下面一行),学习一个模型,然后使用一个云(最左边的部分)查询/测试模型。匹配的结果按从最好到最差的顺序从左到右从左下角开始。有关更多

nginx 出错:socket() failed (24: Too many open files) while connecting to upstream

1. 错误描述 通过nginx负载两个节点的rabbitmq 当用java代码创建超过500个连接时(我的机器默认只能创建这么多),出现错误: com.rabbitmq.client.ShutdownSignalException: connection errorjava.net.SocketException: Software caused connection abort: recv

On Segment's Own Points(可用区间长度)

题目连接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=42180#problem/A 思路一: 排序合并,但是比较繁琐 代码: #include<iostream> #include<cstdio> #include<algorithm> using namespace std; int n,l,r; struct node