Hdu 2800

来源:互联网 发布:windows xp sp2 编辑:程序博客网 时间:2024/06/16 01:48

Adding Edges

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 314    Accepted Submission(s): 216

Problem Description
There are N+1 points on the plane, number A,1,2…N. N is an odd integer. Initially, there exist (N+1)/2 edges, as shown in the picture below.

Now your mission is add some edges to the graph, makes that
① degree(i) != degree(j), (i != j, 1 <= i, j <= N).
② degree(1) as small as possible.
For example, when N = 3, there are two possible answers:

 

 

Input
Each test case contains a single odd integer N(N<=10^6), indicating the number of points. The input is terminated by a set starting with N = 0.
 

 

Output
For each test case, output on a line the smallest possible value of the degree(1).
 

 

Sample Input
30
 

 

Sample Output
2
24300082010-05-08 10:31:21Accepted280046MS232K137 BC++chen

//n是奇数,算上A一共有n+1个点,所以某个点的最大的度数为n,因为要所有度数不一样,所以度数序列为1,2,……,n;先设一

//个点的度数为n,则它要和除了与它相对的点之外的所有点再连线,所以其它点的度数这时都为2,只有它的相对的点是1,所以这两

//个点的度数都确定。去掉这两个点后发现剩下的n-1个点的度数都是2,依次类推就可以找到第一个点的最小度数了,简化为公式就是

//(n+1)/2;

//这道题真让人崩溃,就是一个找规律的题。

//改成移位竟然比除以2还要慢


#include<iostream>
using namespace std;

int main()
{
 int n;
 while(scanf("%d",&n)!=EOF&&n)
 {
  printf("%d/n",(n+1)>>1);
 }

原创粉丝点击