zoj 1539 Lot

水题吧,算是,WA掉一次  T T。。

 

给你一个数n,有两种操作,要么取所有奇数位上的数,要么取偶数位上的数,最后到剩下三个人为止。

 

求这三个人可以有多少种取法。

 

开始理解有问题,后来用广搜了,顺利A掉。

 

搜了下,有用递归的,也有其他杂七杂八的方法的。。恩。。如果能打表我就打表了,可惜不行。。

 

#include <queue> #include <stack> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <iostream> #include <limits.h> #include <string.h> #include <algorithm> using namespace std; queue<int> q; int main() { int n; while( ~scanf("%d",&n) ) { int count = 0; if( n == 3 ) { printf("1/n"); continue; } while( !q.empty() ) q.pop(); q.push(n); while( !q.empty() ) { int n = q.front(); q.pop(); if( n < 3 ) break; if( n % 2 == 0 ) { if( n / 2 == 3 ) count += 2; q.push(n/2); q.push(n/2); } if( n % 2 == 1 ) { if( n/2 == 3 ) count++; if( n - n/2 == 3 ) count++; q.push(n/2); q.push(n-n/2); } } printf("%d/n",count); } return 0; }  

你可能感兴趣的:(zoj 1539 Lot)