BJTUOJ 1653 Wizard of Odds 思维, 码力
题目链接: http://citel.bjtu.edu.cn/boj/problem.php?id=1653
题目描述: 自己看吧, 懒得写了
解题思路: 就是问一个10进制的数, 和一个2^k进制的数字谁大, 因为我觉得最快就是log2(n)了, 但是这个10进制的数是一个大数, 所以只能用字符串处理, 所以说这道题的关键就是用字符串模拟出十进制转二进制
------------------------------------分割线---------------------------------
黑魔法......用double 表示长整数.......加上一个eps确保精度.......
代码: 这个代码没有AC
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <algorithm> using namespace std; const int MAXN = 105; char s1[MAXN]; char s2[MAXN]; int s3[MAXN]; int ans[MAXN]; int done; int cnt; int len1; int ok( int * temp ) { for( int i = 0; i < len1; i++ ) { if( temp[i] != 0 ) return 0; } return 1; } void div2( int * temp, int & mod ) { int flag = 0; for( int i = 0; i < len1; i++ ) { if( flag ) temp[i] += 10; if( temp[i] % 2 ) flag = 1; else flag = 0; temp[i] = temp[i] / 2; } mod = flag; } void solve( int * temp ) { if( done ) return; if( ok(temp) ) { done = 1; return; } int mod = 0; div2(temp, mod); ans[cnt++] = mod; solve(temp); } int main() { while( scanf( "%s%s", s1, s2 ) != EOF ) { memset(s3, 0, sizeof(s3)); memset(ans, 0, sizeof(ans)); done = 0; cnt = 0; len1 = (int)strlen(s1); int len2 = (int)strlen(s2); if( len2 >= 4 ) { cout << "Your wish is granted!" << endl; continue; } int num2 = atoi(s2); for( int i = 0; i < len1; i++ ) { s3[i] = (int)s1[i]-48; } solve(s3); // for( int i = cnt-1; i >= 0; i-- ) { // cout << ans[i] << " "; // } // cout << endl; // cout << cnt-1 << " " << num2 << endl; if( cnt > num2+1 ) { cout << "You will become a flying monkey!" << endl; } else if( cnt < num2+1 ) { cout << "Your wish is granted!" << endl; } else { int flag = 1; for( int i = 1; i < cnt-1; i++ ) { if( ans[i] != 0 ) { flag = 0; break; } } if( !flag ) { cout << "You will become a flying monkey!" << endl; } else { cout << "Your wish is granted!" << endl; } } } }
AC 代码
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <algorithm> #include <cmath> using namespace std; int main() { double n, k; while( cin >> n >> k ) { if( pow(2., k)+0.3 >= n ) { cout << "Your wish is granted!" << endl; } else { cout << "You will become a flying monkey!" << endl; } } return 0; }
思考: 我好像像个傻逼一样了......这题应该这么做?
感觉自己像个智障, 这个黑魔法我确实没有想到, 但是正常按我的做法也是能够做出来的啊, 码力不够
posted on 2017-07-30 12:46 FriskyPuppy 阅读(311) 评论(0) 编辑 收藏 举报