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. 格式化 SQL 来提高效率

    本文由 伯乐在线 - cucr 翻译,黄利民 校稿.未经许可,禁止转载!英文出处:msiman.ga.欢迎加入翻译小组. 背景 已格式化的SQL并不比未格式化SQL运行地更快.数据库可能真的不太在意你 ...

  2. es6笔记(1) 概要

    什么是ES6 ECMAScript 6.0 (简称ES6) 是继ECMAScript 5.1以后的javascript 语言的下一代标准,在2015年6月份发布. 他的目标是使javascript语言 ...

  3. Zookeeper笔记之四字命令

    Zookeeper支持一些命令用来获取服务的状态和相关信息,因为这些命令都是四个字母的,所以一般称为四字命令. 四字命令可以使用telnet或者nc向服务器提交,使用下面这个脚本可以当做是一个简易的客 ...

  4. 基于I2C总线的0.96寸OLED显示屏驱动

    资料未整理,先占位置,以后补充

  5. Python 优雅获取本机 IP 方法

    原文 见过很多获取服务器本地IP的代码,个人觉得都不是很好,例如以下这些 不推荐:靠猜测去获取本地IP方法 #!/usr/bin/env python # -*- coding: utf-8 -*- ...

  6. Babel(抽象语法树,又称AST)

    文章:https://juejin.im/post/5a9315e46fb9a0633a711f25 https://github.com/jamiebuilds/babel-handbook/blo ...

  7. 错误/异常:java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind;的解决方法

    1.异常视图 2.解决方法   SocketException(JVM_Bind):套接口异常     说明:服务器端口号被占用 了  解决方法:点击 Window-->Preferences- ...

  8. tensorflow-训练(train)/测试(test)

    一个TFRecords 文件为一个字符串序列.这种格式并非随机获取,它比较适合大规模的数据流,而不太适合需要快速分区或其他非序列获取方式. 操作组 操作 Training Optimizers,Gra ...

  9. Sublime Text 使用介绍/全套快捷键及插件推荐

    如果说Notepad++是一款不错Code神器,那么Sublime Text应当称得上是神器滴哥.Sublime Text最大的优点就是跨平台,Mac和Windows均可完美使用:其次是强大的插件支持 ...

  10. linux pwd指令C实现

    linux pwd指令C实现 研究实现pwd所需的系统调用 我们可以通过man命令和grep命令来获取我们所需要的系统调用函数信息 man chdir Linux pwd命令用于显示工作目录. 执行p ...