Sequence (opentrains)
来源:互联网 发布:智能后视镜安装软件 编辑:程序博客网 时间:2024/06/10 21:55
这是一道找规律的题目
题意是生成一个序列,后一个数是前一个数的两倍,再通过每一位数进行排序生成的新的一个数
一开始想如果出现了5,那么极有可能生成0,使得新的数的位数减少,所以可能存在一个循环节,然后我通过打表出前1000个数,很容易就找到规律
代码:
#include <bits/stdc++.h>using namespace std;int a[10], b[1000][10], t, n, m;const int mo = 2147483600;int main() { //freopen("c.out","w",stdout); freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); scanf("%d", &n); m = n; a[1] = 1; memset(b, 0, sizeof(b)); b[1][1] = 1; for (int x = 1; x <= 1000; x++) { /*if (x) { //for (int i = 0; i < 9; i++) printf("%d,", a[i]); //printf("%d",a[9]); for (int i = 1; i <= 9; i++) for (int j = 1; j <= a[i]; j++) printf("%d", i); printf("\n"); }*/ t = 0; for (int i = 9; i >= 1; i--) if (a[i]) { if (i >= 5) { b[x+1][(i*2+1)%10] += a[i]-1; if (t) b[x+1][(i*2+1)%10]++; else b[x+1][(i*2)%10]++; } else { b[x+1][(i*2)%10] += a[i]-1; if (t) b[x+1][(i*2+1)%10]++; else b[x+1][(i*2)%10]++; } t = (i*2)/10; } if (t) b[x+1][1]++; for (int i = 0; i <= 9; i++) a[i] = b[x+1][i]; } n = m; if (n > 1000) n = (n-37)%6+37; for (int i = 1; i <= 9; i++) for (int j = 1; j <= b[n][i]; j++) printf("%d", i); printf("\n");}
阅读全文
0 0
- Sequence (opentrains)
- Selection (opentrains)
- Bubble (opentrains)
- Maze (opentrains)
- Tree packing opentrains
- Blobs' Exhibition opentrains
- sequence
- SEQUENCE
- Sequence
- sequence
- sequence
- Sequence
- sequence
- sequence
- sequence
- Sequence
- Sequence
- Sequence
- AndroidStudio上传自己的项目到Bintray jCenter远程仓库!
- 动态规划
- 看阮一峰ES6 笔记
- 输入外挂
- java泛型详解
- Sequence (opentrains)
- javascript 对json数据排序
- 原生js分页效果
- springboot全局异常捕获
- hadoop伪分布式安装
- 中国河流名称代码解释
- 序列化
- HDU-Balala Power!
- 计算机领域兴趣