前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CodeForces 23B (图论 思维)

CodeForces 23B (图论 思维)

作者头像
glm233
发布2020-09-29 23:30:24
7710
发布2020-09-29 23:30:24
举报

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-12,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?

输入格式

The first input line contains one number tt — amount of tests ( 1<=t<=10^{5}1<=t<=105 ). Each of the following tt lines contains one integer number nn ( 1<=n<=10^{5}1<=n<=105 ).

输出格式

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

题意翻译

现在聚会上有n个人参加,然后依次按照规律离开,第一次是有0个朋友的人离开,第二次是有1个朋友的人离开,第三次是有2个朋友的人离开,之后依次是有3,4,5,6。。n-1个朋友的一次离开,求最后聚会会剩下多少人 输入:第一行一个整数t,表示数据组数,之后t行每行一个整数n 输出:对于每组数据,输出一个答案 1<=t<=100000 1<=n<=100000

Translated by 稀神探女

输入输出样例

输入 #1复制

代码语言:javascript
复制
1
3

输出 #1复制

代码语言:javascript
复制
1

思路:唉, 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-12,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?

输入格式

The first input line contains one number tt — amount of tests ( 1<=t<=10^{5}1<=t<=105 ). Each of the following tt lines contains one integer number nn ( 1<=n<=10^{5}1<=n<=105 ).

输出格式

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

题意翻译

现在聚会上有n个人参加,然后依次按照规律离开,第一次是有0个朋友的人离开,第二次是有1个朋友的人离开,第三次是有2个朋友的人离开,之后依次是有3,4,5,6。。n-1个朋友的一次离开,求最后聚会会剩下多少人 输入:第一行一个整数t,表示数据组数,之后t行每行一个整数n 输出:对于每组数据,输出一个答案 1<=t<=100000 1<=n<=100000

Translated by 稀神探女

输入输出样例

输入 #1复制

1

3

输出 #1复制

1

思路:唉,真的要多练练思维,题意是一开始没有朋友的人走,然后有一个的走,有两个的走......直到有n-1个朋友的走,

那么我们如果能想清楚一点的话这道题其实就不难了,我们要使最后剩下来的人最多,那么必须要使先走的人造成让剩下来的人的朋友数-1,这样就可以跳过踢出剩下这些人的环节了,最好的情况是两个人只有n-2个朋友,然后他们先在其他n-2个人前面被踢出,然后其他n-2个人原来是有n-1个朋友,现在只有n-2个朋友但是现在是踢出n-1个朋友的环节了,所以这n-2个人还保留着,可以去证明,n-2是可以保留最多的人数

代码语言:javascript
复制
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rg register ll
#define inf 2147483647
#define lb(x) (x&(-x))
template <typename T> inline void read(T& x)
{
    x=0;char ch=getchar();ll f=1;
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}x*=f;
}
int main()
{
	ll t;
	cin>>t;
	for(rg i=1;i<=t;i++)
	{
		ll n;
		cin>>n;
		cout<<max(0ll,n-2)<<endl;
	}
    return 0;
    
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-03-16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 输入格式
  • 输出格式
  • 题意翻译
  • 输入输出样例
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档