BestCoder Round #71 (div.2) (hdu 5621)

KK's Point

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 644    Accepted Submission(s): 220

Problem Description
Our lovely KK has a difficult mathematical problem:He points N(2≤N≤105) points on a circle,there are all different.Now he's going to connect the N points with each other(There are no three lines in the circle to hand over a point.).KK wants to know how many points are there in the picture(Including the dots of boundary).
 
Input
The first line of the input file contains an integer T(1≤T≤10), which indicates the number of test cases.

For each test case, there are one lines,includes a integer N(2≤N≤105),indicating the number of dots of the polygon.

 
Output
For each test case, there are one lines,includes a integer,indicating the number of the dots.
 
Sample Input
2
3
4
 
Sample Output
3
5

题意:一个圆上给n个点,将这些点两两相连,问有多少个交点

要求:1、圆上的点也算   2、圆内只有两条线的交点,没有两条以上线的交点

题解:圆上的点为n个,我们只需计算圆内有多少个交点即可,4个点可以在圆内形成一个交点,所以我们计算n个点可以组成多少个四边形即可

求解组合公式C(n,4)+n;

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
#define MAX 100100
#define INF 0x3f3f3f
using namespace std;
int main()
{
int t;
unsigned long long n;
scanf("%d",&t);
while(t--)
{
scanf("%llu",&n);
if(n<4)
{
printf("%llu\n",n);
continue;
}
unsigned long long ans=n*(n-1)/2*(n-2)/3*(n-3)/4+n;
printf("%llu\n",ans);
}
return 0;
}

  

上一篇:Hi3516EV100烧录出厂固件


下一篇:CSDN社区之星专訪:我的蜕变之路