Problem A. A + B

题目连接:

http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c7022&all_runs=1&action=140

Description

Kastus recently got to know about complex numbers. But from all real numbers he was interested only

in integers, so he decided to learn only numbers of the form a + bi where i

2 = −1, a and b are integers

(he had no idea that he was not the first who got interested in these numbers and that they are called

Gaussian integers).

It would be nice if Kastus knew how to represent such numbers in computer memory. . . He is already

familiar with some number systems, for example binary and negabinary. He decided that a pair of integers

is not an option. One number should look like one number. Kastus had been thinking long and hard what

to do, and finally saw an elegant solution: take a number system in base i − 1 and the digits 0 and 1. In

other words, the expression

a + bi = dn−1 . . . d1d0i−1

means that

a + bi = (i − 1)n−1

· dn−1 + . . . + (i − 1)1

· d1 + (i − 1)0

· d0.

For example, 1101i−1 = (i − 1)3 + (i − 1)2 + (i − 1)0 = 3.

Kastus proved that any Gaussian integer can be represented using this notation in the only way (if it has

no leading zeros). In addition, he noticed that all the numbers having no more than n significant digits

form a dragon curve when he marked them on the complex plane.

Now he is interested in a new simple question: how to make the usual arithmetic operations with the

numbers written in this notation. He decided to start with addition, despite the fact that subtraction can

not be expressed through addition, whereas addition is expressed through subtraction. But even with this

simple question he needs help!

Input

Each of two lines contains one number written in base i − 1 with no more than 1 000 000 digits. The

numbers don’t have leading zeros.

Output

Output the sum of the two given numbers in the same notation.

Sample Input

1100

1101

Sample Output

111010001

Hint

题意

定义了一个复数进制,然后给你俩复数进制表示的复数,求这俩复数相加后的复数进制表示方法

题解:

我们观察得知,其实(i-1)3+(i-1)2 = 2,那么就表示2 = 1100,根据这个不停的去做就好了。

这道题感觉智商被压制了。。。。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e6+7;
string s1,s2;
string ans;
int a[maxn],b[maxn];
int c[maxn];
int main(){
cin>>s1>>s2;
reverse(s1.begin(),s1.end());
reverse(s2.begin(),s2.end());
for(int i=0;i<s1.size();i++)
a[i]=s1[i]-'0';
for(int i=0;i<s2.size();i++)
b[i]=s2[i]-'0';
for(int i=0;i<maxn;i++){
c[i]=c[i]+a[i]+b[i];
while(c[i]>=2){
c[i]-=2;
c[i+2]++;
c[i+3]++;
}
}
int flag = 0;
for(int i=maxn-1;i>=0;i--){
if(c[i])flag = 1;
if(flag)cout<<c[i];
}
if(flag==0)cout<<"0";
cout<<endl;
}

Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem A. A + B的更多相关文章

  1. Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem K. UTF-8 Decoder 模拟题

    Problem K. UTF-8 Decoder 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c702 ...

  2. Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem I. Alien Rectangles 数学

    Problem I. Alien Rectangles 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c ...

  3. Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem H. Parallel Worlds 计算几何

    Problem H. Parallel Worlds 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c7 ...

  4. Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem F. Turning Grille 暴力

    Problem F. Turning Grille 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c70 ...

  5. Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem C. Cargo Transportation 暴力

    Problem C. Cargo Transportation 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed ...

  6. Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem G. k-palindrome dp

    Problem G. k-palindrome 题目连接: http://opentrains.snarknews.info/~ejudge/team.cgi?SID=c75360ed7f2c7022 ...

  7. 2010 NEERC Western subregional

    2010 NEERC Western subregional Problem A. Area and Circumference 题目描述:给定平面上的\(n\)个矩形,求出面积与周长比的最大值. s ...

  8. 2009-2010 ACM-ICPC, NEERC, Western Subregional Contest

    2009-2010 ACM-ICPC, NEERC, Western Subregional Contest 排名 A B C D E F G H I J K L X 1 0 1 1 1 0 1 X ...

  9. 【GYM101409】2010-2011 ACM-ICPC, NEERC, Western Subregional Contest

    A-Area and Circumference 题目大意:在平面上给出$N$个三角形,问周长和面积比的最大值. #include <iostream> #include <algo ...

随机推荐

  1. bzoj千题计划247:bzoj4903: [Ctsc2017]吉夫特

    http://uoj.ac/problem/300 预备知识: C(n,m)是奇数的充要条件是 n&m==m 由卢卡斯定理可以推出 选出的任意相邻两个数a,b 的组合数计算C(a,b)必须是奇 ...

  2. Java SSM框架之MyBatis3(四)MyBatis之一对一、一对多、多对多

    项目搭建Springboot 1.5  pom.xml <?xml version="1.0" encoding="UTF-8"?> <pro ...

  3. Java Web之路(二)Servlet之HttpServletResponse和HttpServletRequest

    HttpServletResponse 1.告诉服务器应用使用UTF-8解析文本的两种方式,告诉客户端要使用什么编码 response.setHeader("content-type&quo ...

  4. SQL Server 的字段不为NULL时唯一

    CREATE UNIQUE NONCLUSTERED INDEX 索引名称ON 表名(字段) WHERE 字段 is not null SQL Server 2008+ 支持

  5. [整理]x=x++和x=++x

    最近看java面试题,再次遇到x=x++,之前一直按照C语言中对自增运算符++的解释去理解.殊不知自己犯了严重的错误. (1)不同的语言的编译器,会导致相同的代码最终执行的结果不确定; (2)而且就算 ...

  6. javascript柯里化

    function curry(fn){ var slice = Array.prototype.slice; var arr = slice.call(arguments,1); return fun ...

  7. Docker学习笔记一 概念、安装、镜像加速

    本文地址:https://www.cnblogs.com/veinyin/p/10406378.html  Docker 是一个容器,可以想象成一个轻便的虚拟机,但不虚拟硬件和操作系统. 优点:启动快 ...

  8. ZYNQ. DMA基本用法

    DMA环路测试 vivadoblock zynq7 + dma +fifo sdk 中可以导入 demo demo 中 默认都是 一个字节8bit数据 的测试程序. 如果是其他长度的数据,不仅要修改数 ...

  9. mac 安装gevent报错

    运行pip install gevent报错 错误信息如下 xcrun: error: invalid active developer path (/Library/Developer/Comman ...

  10. 推荐一些socket工具,TCP、UDP调试、抓包工具 (转载)

    还记得我在很久很久以前和大家推荐的Fiddler和Charles debugger么?他们都是HTTP的神器级调试工具,非常非常的好用.好工具能让你事半功倍,基本上,我是属于彻头彻尾的工具控. 假如有 ...