题目:有n个海盗,分m块金子,其中他们会按一定的顺序提出自己的分配方案,如果50%以上的人赞成,则方案通过,开始分金子,如果不通过,则把提出方案的扔到海里,下一个人继续。从第n个人开始决策,问第p个人能分多少金子,或是被扔到海里
思路:
参考http://blog.csdn.net/acm_cxlove/article/details/7853916 的博客做出来的,写的很详细
代码:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<numeric>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define INF 0x3f3f3f3f
#define mm(a,b) memset(a,b,sizeof(a))
#define PP puts("*********************");
template<class T> T f_abs(T a){ return a > 0 ? a : -a; }
template<class T> T gcd(T a, T b){ return b ? gcd(b, a%b) : a; }
template<class T> T lcm(T a,T b){return a/gcd(a,b)*b;}
// 0x3f3f3f3f3f3f3f3f
//0x3f3f3f3f
int fac[15]={2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768};
void solve(int n,int m,int p){
if(n<=2*m){//金币够贿赂的情况
if(n!=p&&(n%2==p%2))
printf("1\n");
else if(n==p) printf("%d\n",m-(n-1)/2);
else printf("0\n");
return;
}
if(n==2*m+1){
if(n==p||n%2!=p%2)
printf("0\n");
else
printf("1\n");
return;
}
int t=n-2*m;
for(int i=0;i<14;i++)
if(t==fac[i]){
printf("0\n");
return;
}
for(int i=0;i<14;i++)
if(t<fac[i]){
if(2*m+fac[i-1]<p&&p<2*m+fac[i])
printf("Thrown\n");
else
printf("0\n");
return;
}
}
int main(){
// freopen("D:\\input.txt","r",stdin);
// freopen("D:\\output.txt","w",stdout);
int T,n,m,p;
scanf("%d",&T);
while(T--){
scanf("%d%d%d",&n,&m,&p);
solve(n,m,p);
}
return 0;
}