【题目链接】: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;
}

【t014】拯数的更多相关文章

  1. Linux上如何查看物理CPU个数,核数,线程数

    首先,看看什么是超线程概念 超线程技术就是利用特殊的硬件指令,把两个逻辑内核模拟成两个物理芯片,让单个处理器都能使用线程级并行计算,进而兼容多线程操作系统和软件,减少了CPU的闲置时间,提高的CPU的 ...

  2. 微信小程序中利用时间选择器和js无计算实现定时器(将字符串或秒数转换成倒计时)

    转载注明出处 改成了一个单独的js文件,并修改代码增加了通用性,点击这里查看 今天写小程序,有一个需求就是用户选择时间,然后我这边就要开始倒计时. 因为小程序的限制,所以直接选用时间选择器作为选择定时 ...

  3. 数塔问题(DP算法)自底向上计算最大值

    Input 输入数据首先包括一个整数C,表示测试实例的个数,每个测试实例的第一行是一个整数N(1 <= N <= 100),表示数塔的高度,接下来用N行数字表示数塔,其中第i行有个i个整数 ...

  4. 统计iOS项目的总代码行数的方法

    打开终端, 用cd命令 定位到工程所在的目录,然后调用以下命名即可把每个源代码文件行数及总数统计出来: find . "(" -name "*.m" -or - ...

  5. 数百个 HTML5 例子学习 HT 图形组件 – 3D建模篇

    http://www.hightopo.com/demo/pipeline/index.html <数百个 HTML5 例子学习 HT 图形组件 – WebGL 3D 篇>里提到 HT 很 ...

  6. 数百个 HTML5 例子学习 HT 图形组件 – 3D 建模篇

    http://www.hightopo.com/demo/pipeline/index.html <数百个 HTML5 例子学习 HT 图形组件 – WebGL 3D 篇>里提到 HT 很 ...

  7. 数百个 HTML5 例子学习 HT 图形组件 – WebGL 3D 篇

    <数百个 HTML5 例子学习 HT 图形组件 – 拓扑图篇>一文让读者了解了 HT的 2D 拓扑图组件使用,本文将对 HT 的 3D 功能做个综合性的介绍,以便初学者可快速上手使用 HT ...

  8. 数百个 HTML5 例子学习 HT 图形组件 – 拓扑图篇

    HT 是啥:Everything you need to create cutting-edge 2D and 3D visualization. 这口号是当年心目中的产品方向,接着就朝这个方向慢慢打 ...

  9. android手机旋转屏幕时让GridView的列数与列宽度自适应

    无意中打开了一年前做过的一个android应用的代码,看到里面实现的一个小功能点(如题),现写篇文章做个笔记.当时面临的问题是,在旋转屏幕的时候需要让gridview的列数与宽度能自适应屏幕宽度,每个 ...

随机推荐

  1. Appium_Java_API

    1. driver.findElement(MobileBy.AndroidUIAutomator("邀请")).click();2. driver.findElementById ...

  2. Java Web学习总结(7)——HttpServletRequest对象

    一.HttpServletRequest介绍 HttpServletRequest对象代表客户端的请求,当客户端通过HTTP协议访问服务器时,HTTP请求头中的所有信息都封装在这个对象中,通过这个对象 ...

  3. [Firebase] Firebase Cloud Functions

    Firebase cloud functions is similar to AWS lambda or serverless. You can deploy you code which wrote ...

  4. 【微信】微信获取TOKEN,以及储存TOKEN方法,Spring quartz让Token永只是期

    官网说明 access_token是公众号的全局唯一票据,公众号调用各接口时都需使用access_token.开发人员须要进行妥善保存. access_token的存储至少要保留512个字符空间.ac ...

  5. Qt5官方demo解析集28——Extending QML - Signal Support Example

    本系列全部文章能够在这里查看http://blog.csdn.net/cloud_castle/article/category/2123873 接上文Qt5官方demo解析集27--Extendin ...

  6. 11. Spring Boot JPA 连接数据库

    转自:https://blog.csdn.net/catoop/article/details/50508397

  7. linux中软件安装方式

    通常Linux应用软件的安装包有三种: tar包,如software-1.2.3-1.tar.gz.它是使用UNIX系统的打包工具tar打包的. rpm包,如software-1.2.3-1.i386 ...

  8. android 5.x system.img 大于2G导致编译otapackage时报错怎样处理

    当system分区预制过多apk时假设img size超过2G 在make otapackage时会报例如以下错误  zipfile.LargeZipFile: Zipfile size would ...

  9. x=min(x, y)

    x = min(x, y); ⇒ 当然 y 会有多个值传递进来 minHeight = min(minHeight, h[i]); 置于循环之中,不断将当前得到的最小高度值和新加入进来的值进行比较: ...

  10. Mac 环境下svn服务器的配置

    Mac 环境下svn服务器的配置 本文目录 • 一.创建代码仓库,用来存储客户端所上传的代码 • 二.配置svn的用户权限 • 三.使用svn客户端功能 在Windows环境中,我们一般使用Torto ...