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;
}












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