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. ASP.NET记录错误日志的方式

    程序记录错误日志是一种看起来对一般用户没什么作用,但对程序开发者用处很大的东西,它能查出错误或异常的程序马迹.那么,常用的记录错误日志的方式有哪些呢? 大多数情况下使用的是 1.直接记录为txt/xm ...

  2. 从Dying gasp功能看Linux的响应速度(zhuan)

    转自https://blog.csdn.net/qq_20405005/article/details/77967358 前一阵子在做dying gasp功能测试,过程中恰好测试到了Linux的响应速 ...

  3. WPF的EventAggregator的发布和订阅

    EventAggregator是Prism中专门处理ViewModel与ViewModel之间事件传递的类对象,它提供了针对事件的发布方法和订阅方法,所以可以非常方便的来管理事件.下面分几步来实现相关 ...

  4. C#使用redis学习笔记

    1.官网:http://redis.io/(英)  http://www.redis.cn/(中) 2.下载:https://github.com/dmajkic/redis/downloads(Wi ...

  5. 拓展中国剩余定理(exCRT)摘要

    清除一个误区 虽然中国剩余定理和拓展中国剩余定理只差两个字,但他俩的解法相差十万八千里,所以会不会CRT无所谓 用途 求类似$$\begin{cases}x \equiv b_{1}\pmod{a_{ ...

  6. 转载:Linux批量远程管理主机命令_pssh用法详解

    原文:http://www.linuxidc.com/Linux/2011-12/49635p2.htm (一) 使用前提 中心主机连接远程主机可以通过ssh密钥无密码连接 (二) 命令格式 pssh ...

  7. 重温CSS之文档结构

    我们来看看几个基本的HTML页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "h ...

  8. list 复制

    a=[1,2,3] b=a #b值改变,a也会改变 b[0]=90 print(a) [90,2,3] b=list(a) #这样修改b,a的值就不会改变

  9. C# 各版本新特性

    C# 2.0 泛型(Generics) 泛型是CLR 2.0中引入的最重要的新特性,使得可以在类.方法中对使用的类型进行参数化. 例如,这里定义了一个泛型类: class MyCollection&l ...

  10. tensorflow函数(2)

    并行计算能让代价大的算法计算加速执行,TensorFlow也在实现上对复杂操作进行了有效的改进.大部分核相关的操作都是设备相关的实现,比如GPU.下面是一些重要的操作/核: 操作组 操作 Maths ...