- 如果桌子上有999本书,你和另外一个人一起轮流拿,你的目的是拿到最好一本书,规则是两个人轮流拿,每人每次最少拿一本,最多拿三本.问你如何拿到最后一本书.
- #include <iostream>
-
-
using namespace std;
-
-
int fun(int & i,int & j){
-
int n;
-
int arr[5]={2,3,4,5,6};
-
for(n=1;n<5;n++){
-
if(!(i%arr[n])&&arr[n]>j){
-
return arr[n];
-
break;
-
}
-
}
-
}
-
-
int main (){
-
-
int total=999;
-
int i;
-
int j;
-
int k;
-
while(i<=999-4){
-
-
cin>>j;
-
k=fun(i,j);
-
cout<<"p1: "<<k-j<<" p2: "<<j<<endl;
-
i+=k;
-
}
-
cin>>j;
-
if(j==1)cout<<"p1: "<<4-j<<" p2: "<<j<<endl;
-
else if(j==2)cout<<"p1: "<<4-j<<" p2: "<<j<<endl;
-
else cout<<"p1: "<<4-j<<" p2: "<<j<<endl;
- }