Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3396 Accepted Submission(s): 2095
4 2 3 2 3 5
1 none 3 4 5
思路:
成本为m,增价最大为n,当m<=n时,先手只要拿一次就可以赢了。当m>n时,巴什博奕m=(n+1)*r +s ,当m%(n+1)==0时,先手必输。再这种情况下,如果先手要赢,首先要拿走s个,满足(m-s)%(n+1)==0,所以只要枚举s就可以了。本题注意格式,空格不能多。很多代码完全是为了控制空格的输出。
代码:
#include <iostream> using namespace std; int m,n;//m为成本,n为最大的加价 int main() { while(cin>>m>>n) { if(m<=n)//成本小于最大报价,先手肯定赢 { cout<<m; for(int i=m+1;i<=n;i++) cout<<" "<<i; cout<<endl; continue; } if(m%(n+1)==0)//先手必输 { cout<<"none"<<endl; } else { int flag=0;//完全为了控制输出格式,空格。。。 for(int i=1;i<=n;i++)//枚举先手先报的价,不能超过n,保证(m-i)%(n+1)==0先手才能赢 { if((m-i)%(n+1)==0) { if(!flag) { cout<<i; flag=1; } else cout<<" "<<i; } } cout<<endl; } } return 0; }
[ACM] hdu 2149 Public Sale (巴什博奕),布布扣,bubuko.com
[ACM] hdu 2149 Public Sale (巴什博奕)
原文:http://blog.csdn.net/sr_19930829/article/details/22212289