CodeChef JNTUV1(找规律)
来源:互联网 发布:java 重写string 编辑:程序博客网 时间:2024/06/18 11:42
题目大意:
给你这样一个序列3, 4, 33, 34, 43, 44, 333, 334, 343, 344, 433, 434, 443, 444, 3333, 3334, 3343, 3344……..,找到其中的规律,输入n,输出对应的数字。
解析:
可以把这个序列等价于一个二进制0, 1, 00, 01, 10, 11,模拟这个序列的生成就ok了。
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <cstdlib>using namespace std;typedef long long ll;const int INF = 0x3f3f3f3f;const int N = 105;char buf[N];int n;int main() { while(scanf("%d", &n) != EOF) { memset(buf, 0, sizeof(buf)); int bit = 2; while(n - bit > 0) { n -= bit; bit *= 2; } int end = log2(bit); for(int i = 0; i < end; i++) { buf[i] = '3'; } n--; for(int i = end-1; n; i--) { if(n & 1) { buf[i] = '4'; } n /= 2; } puts(buf); } return 0;}
0 0
- CodeChef JNTUV1(找规律)
- 【codechef】Zombinatorial(找规律)
- 【codechef】Chef and Strange Formula(找规律,灵活题)
- CodeChef SIGNWAVE (打表找规律)
- HDOJ1021(找规律)
- POJ1740(找规律)
- hdu (找规律)
- hdu4915(找规律)
- HDU5100(找规律)
- Hexagons!(找规律)
- Alarm(找规律)
- hdu6130(找规律)
- POJ 1068(找规律)
- hdu1865(高精度,找规律)
- hdu3951(博弈)找规律
- ZOJ3498 Javabeans(找规律)
- hdu 2608(找规律)
- hdu4925Apple Tree(找规律)
- hdu 5177 (1e18范围的卡特兰数)
- 蓝桥杯 黑洞数 解题报告
- Dagger——Android的依赖注入框架
- Mac Error: Disk Utility can’t repair this disk. Back up as many of your files as possible, reformat
- Bitset(十进制转二进制)
- CodeChef JNTUV1(找规律)
- 面试题1:赋值运算符函数
- 软件设计原则
- 面试题3:二维数组的查找
- 面试题4:替换空格
- java 学习之 多态
- 通过Tomcat的Http11NioProtocol源码学习Java NIO设计
- CentOS最常用命令及快捷键整理
- 传奇猎刃