Codeforence 23 B. Party 比较有趣的思维问题

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



这个题目我想想还是很不错的,因为我一开始看这个题目的时候表示毫无思路,这个题目的意思是说一开始选出

为朋友的个数为0的,然后是1的,然后是2的,逐渐到n-1,问最后最多可以剩下几个。这个题目其实换个说法说

可能会好理解一点,就是在一个无向图中,去除掉度为0,为1,为2,逐渐去,看剩下那些点了。



既然这个题目没有说出到底每个人有几个朋友,完全可以自己花一个,以上图为例。假如我们选择了A离开,
那么c=2,d=3,e=2,b=3,这时让b走,c=1,d=2,e=1,这样就没有办法接着走,也就说走了两个,所以就是n-2,
假如n=1,n=2,这时画下点就知道了,很简单的。




#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{

    int t,i,j,k;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&k);
        if(k<=2)
        {
            printf("0\n");
        }
        else
        {
            printf("%d\n",k-2);
        }










    }











    return 0;
}












發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章