当前位置: 代码迷 >> 综合 >> Party(简单题,但很奇妙)
  详细解决方案

Party(简单题,但很奇妙)

热度:34   发布时间:2024-01-13 21:19:28.0

1、点击打开链接Party

2、题目大意:

现在party上有n个人参加,然后依次按照规律离开,第一次是有0个朋友的人离开,第二次是有1个朋友的人离开,第三次是有2个朋友的人离开,依次是3,4,5,6,。。n-1个朋友的一次离开,求最后party会剩下多少人

奇妙之处在于,当一个人或2个人的时候,将会剩下0个人,3个人以上,即n个人时,将会剩下(n-2)个人

试想将定最少离开1个人,那么此人假设有d个朋友,那么剩下的人要是不走,那么此时剩下的人的朋友数将<d,如果只有一个人离开,那么d将会是n-1,那么就能得出原来除了走的那个人外,其余的(n-1)个人都有n个朋友,而在一个完全图中,一个点的度最大是(n-1),推出矛盾;

假设最少离开的人是2,那么成立,只需要假设n个人的关系构成一个去掉一条边的完全图,当前这个图只有去掉的那条边的两个端点的度是(n-2),其余的点的度都是(n-1),那么将这两个度为(n-2)的点去掉后,其余的点度都变为(n-2),此时剩下的这些度为(n-2)的点将剩下,所以,只要超过3个点,就可以构成一个完全图,所以超过三个点,最少删除2个点,若果是n个点,将剩下(n-2)个点

3、代码:

#include<stdio.h>
int main()
{int t,n;scanf("%d",&t);while(t--){scanf("%d",&n);if(n<=2)printf("0\n");if(n>2)printf("%d\n",n-2);}return 0;
}


 

4、题目:

B. Party
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

n people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2,?3,?...,?n?-?1 friends among those who stayed by the moment of their leaving, did the same.

What is the maximum amount of people that could stay at the party in the end?

Input

The first input line contains one number t — amount of tests (1?≤?t?≤?105). Each of the following t lines contains one integer number n (1?≤?n?≤?105).

Output

For each test output in a separate line one number — the maximum amount of people that could stay in the end.

Sample test(s)
Input
1
3
Output
1