【t014】拯数
来源:互联网 发布:c语言图书管理系统 编辑:程序博客网 时间:2024/05/23 02:07
【题目链接】:http://noi.qz5z.com/viewtask.asp?id=t014
【题意】
【题解】
这个锁的序列,如果把末尾的0去掉;然后再倒过来;那么就是这个序列对应的格雷码了;然后根据格雷码和二进制的对应关系;能够处理出对应的二进制;比如格雷码存在a数组,二进制存在b数组;则b[1] = a[1]rep1(i,2,n) b[i] = b[i-1]^a[i];然后把这个二进制转成十进制就是答案了要写高精度哦
【完整代码】
#include <cstdio>#include <algorithm>#include <iostream>#include <cmath>#include <cstring>using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define LL long long#define rep1(i,a,b) for (int i = a;i <= b;i++)#define rep2(i,a,b) for (int i = a;i >= b;i--)#define mp make_pair#define pb push_back#define fi first#define se second#define rei(x) scanf("%d",&x)#define rel(x) scanf("%lld",&x)typedef pair<int, int> pii;typedef pair<LL, LL> pll;const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };const double pi = acos(-1.0);const int N = 1100;struct abc{ int len, a[N]; abc() { memset(a, 0, sizeof a); }};int n,a[N],b[N];abc two[N], ans;abc plu(abc a, abc b){ int len = max(a.len, b.len); abc c; int x = 0; rep1(i, 1, len) { c.a[i] = a.a[i] + b.a[i] + x; x = c.a[i] / 10; c.a[i] %= 10; } while (x) { c.a[++len] = x; c.a[len] %= 10; x /= 10; } c.len = len; return c;}int main(){ //freopen("F:\\rush.txt", "r", stdin); rei(n); rep1(i, 1, n) cin >> a[i]; while (n - 1 >= 1 && a[n] == 0) n--; reverse(a + 1, a + 1 + n); b[1] = a[1]; rep1(i, 2, n) b[i] = b[i - 1] ^ a[i]; rep1(i, 1, n) a[i] = b[i]; two[0].len = 1, two[0].a[1] = 1; rep1(i, 1, n) { two[i].len = two[i - 1].len; rep1(j, 1, two[i].len) two[i].a[j] = two[i - 1].a[j]; int &len = two[i].len,x = 0; rep1(j, 1, len) { two[i].a[j] = two[i].a[j] * 2 + x; x = two[i].a[j] / 10; two[i].a[j] %= 10; } while (x > 0) { two[i].a[++len] = x; two[i].a[len] %= 10; x = x / 10; } } ans.a[1] = 0, ans.len = 1; rep2(i, n, 1) if (a[i]) ans = plu(ans, two[n - i]); rep2(i, ans.len, 1) printf("%d", ans.a[i]); puts(""); return 0;}
0 0
- 【t014】拯数
- 数
- 数
- 数
- 数
- 数
- 数
- 字符数,字节数
- 完全数、亲和数
- 字符数、字节数
- 亲和数、相亲数
- 整形数,浮点数
- 浮点数、定点数
- 三角数因子数
- 自守数,亲密数,完美数
- 【实用技巧】阅读数,分享数,浏览数
- B数 /B-数 / B+数
- 水仙花数
- 单例模式及其资源释放
- afxDump怎么用
- Oracle体系结构和启动关闭阶段
- [机器学习篇]基于Scikit learn库中KNN,SVM算法的笔迹识别
- linode上快速建立Spark源码阅读环境
- 【t014】拯数
- POJ2425(树形,无向无环图博弈) SG函数
- redis数据库
- SpringMVC文件上传下载
- spark 中 rdd to dataframe 问题
- Linux学习之I/O内存访问详解
- Hive源码调试步骤
- <Linux多线程服务端编程>学习记录
- Java 网络编程简单学习笔记1