Gym 101503C Twisting the Number(思维+枚举)
来源:互联网 发布:神仙道心动网络 编辑:程序博客网 时间:2024/06/04 00:39
题目大意:
有一个整数
所以
现在给你一个
解题思路:
首先我们对于给定的
设有
那么我们只需要枚举
代码:
#include <iostream>#include <string.h>#include <string>#include <algorithm>#include <stdio.h>#include <stdlib.h>#include <math.h>#include <map>using namespace std;typedef long long LL;const LL INF = 2e18;const int MAXN = 1e6+5;const double PI = acos(-1);const double eps = 1e-8;const LL MOD = 1e9+7;LL get1(string s){ if(s[0] == '0') return INF; LL ans = 0; int len = s.length(); for(int i=0; i<len; i++) if(s[i] == '1') ans += (1LL<<(len-1-i)); return ans;}string get2(LL n){ string s = ""; while(n){ s += ((n&1)+'0'); n>>=1; } for(int i=0; i<s.length()/2; i++) swap(s[i],s[s.length()-i-1]); return s;}LL cal(LL n){ string s = get2(n); string s1 = ""; s1 += s[0]; LL ans = n; int len = s.length(); for(int i=1; i<len; i++){ string s2 = s.substr(i); s2 += s1; ans = min(ans, get1(s2)); s1 += s[i]; } return ans;}int main(){ LL n; while(cin>>n){ LL ans = cal(n); string s = get2(n); int len = s.length(); for(int i=1; i<len-1; i++){ if(s[i] == '1'){ string s1 = s.substr(0,i)+'0'; string s2 = get2((1LL<<(len-i-1))-1); s1 += s2; LL tmp = cal(get1(s1)); ans = max(ans, tmp); } } printf("%lld\n",ans); } return 0;}
阅读全文
0 0
- Gym 101503C Twisting the Number(思维+枚举)
- Gym 100379C Fibonacci number’s ratio (the hard version) (特征方程)
- GYM 100801C Concatenation【思维】
- Gym 101615C 【数学思维】
- 思维-Gym
- Gym 101138C Stickmen【枚举+排列组合】
- POJ2965 The Pilots Brothers' refrigerator(枚举+思维题)
- GYM 101147 C.The Wall(二分匹配-hungary)
- codeforces gym 101142 F(思维)
- GYM Amman 17 J. Spilt the String 模拟,枚举
- GYM 100030 E.Tests Preparation(枚举)
- GYM 100182 G.Pool Table(枚举)
- GYM 101128 H.Sheldon Numbers(枚举)
- GYM 100712 G.Heavy Coins(枚举)
- GYM 100883 J.palprime(枚举)
- GYM 101086 F.Hey JUDgE(枚举)
- gym 101196E Red Rover(枚举)
- GYM 101128 C.Canvas Painting【思维+优先队列】
- 关于音乐播放器-不定时更新
- error C2065:未申明的标识符
- jstl标签的使用
- mysql基础知识
- @Inject源码翻译
- Gym 101503C Twisting the Number(思维+枚举)
- webpack
- C-单向链表的基本操作
- 如何在j2ee项目中处理高并发量访问?
- Android 7.0 虚拟按键(NavigationBar)源码分析 之 View的创建流程
- 树莓派安装Ubuntu core
- Redis存取List对象的实践
- 使用 Anaconda 管理 Python 环境
- SpO2、SaO2、PaO2、低氧血症概念及标准的总结