B. Party
来源:互联网 发布:淘宝首页1920全屏代码 编辑:程序博客网 时间:2024/04/30 07:37
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
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
题目大意:
现在party上有n个人参加,然后依次按照规律离开,第一次是有0个朋友的人离开,第二次是有1个朋友的人离开,第三次是有2个朋友的人离开,依次是3,4,5,6,。。n-1个朋友的一次离开,求最后party会剩下多少人?
首先人数小于3个的时候直接可以判断是没有人可以留下的 ,但是人数大于等于三个的时候,可以发现如果假设所有的人之间都是朋友关系,就不会有人能够留下(比如4的时候每个人的朋友都是3,那么第4次的时候朋友数为3的人离开,那么这4个人都会离开),所以先假设只离开一个人为X,判断行不行,假设X只有d(d<n-1)个朋友,想保证剩下的n-1人不离开,那么这n-1个人(去除X外的人),每个人的朋友数必须是d+1,但是这是不可能的,因为X和部分人是朋友关系,和一些人是没有关系的,所以剩下的n-1个人,每人的朋友数不可能为d+1(即不可能相同),所以接着假设两个人离开是否可行,明显两个人(设X,Y)可以弥补上面的问题,一本分和X有关系,一部分和Y有关系,达到开始的假设条件
#include<bits/stdc++.h>//#include<iostream>//#include<cmath>//#include<cstring>//#include<string>//#include<cstdlib>//#include<cstdio>//#include<map>//#include<algorithm>using namespace std;template<class T>inline T read(T&x){ char c; while((c=getchar())<=32); bool ok=false; if(c=='-')ok=true,c=getchar(); for(x=0; c>32; c=getchar()) x=x*10+c-'0'; if(ok)x=-x; return x;}template<class T> inline void read_(T&x,T&y){ read(x); read(y);}template<class T> inline void read__(T&x,T&y,T&z){ read(x); read(y); read(z);}template<class T> inline void write(T x){ if(x<0)putchar('-'),x=-x; if(x<10)putchar(x+'0'); else write(x/10),putchar(x%10+'0');}template<class T>inline void writeln(T x){ write(x); putchar('\n');}//-------ZCC IO template------const int maxn=11;const double inf=999999999;#define lson (rt<<1),L,M#define rson (rt<<1|1),M+1,R#define M ((L+R)>>1)#define For(i,n) for(int i=0;i<(n);i++)typedef long long LL;typedef double DB;#define bug printf("---\n");int main(){ int t; read(t); while(t--) { int n; read(n); if(n>=3)writeln(n-2); else writeln(0); } return 0;}
0 0
- B. Party
- B. Party
- CodeForces 23B Party
- CodeForces 23B-Party
- codeforces 549B B. Looksery Party(构造)
- B. Party – Codeforces Beta Round #23
- CodeForces 23B Party (简单题)
- WEEKLY TRAINING2-B Party 树+dfs
- Looksery Cup 2015 B. Looksery Party
- Codeforces 549B Looksery Party [贪心]
- CodeForces 23B Party (思维题)
- Party
- Party
- Party
- Party
- Party
- Codeforence 23 B. Party 比较有趣的思维问题
- Announce of Looksery Cup 2015-B. Looksery Party
- Oracle 数据库11g 最佳培训教程PPT合集
- [LeetCode刷题记录]Length of Last Word
- 第二章作业
- PHP 学习之--第一个PHP脚本
- Gitlab的使用总结
- B. Party
- javascript中对象的深度克隆
- 根据参数提示错误信息
- 如何判定a,b,c,d四个值是否相等
- 树莓派的系统安装
- ORA-00600: internal error code, arguments: [4194], [#], [#], [], [], [], [], []
- 遗传算法入门
- Android底层开发之Audio HAL
- eclipse中设置maven离线模式