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












  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值