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. 浅谈 js 对象 toJSON 方法

    前些天在<浅谈 JSON.stringify 方法>说了他的正确使用姿势,今天来说下 toJSON 方法吧.其实我觉得这货跟 toString 一个道理,他是给 stringify 方法字 ...

  2. 总有一些实用javascript的元素被人遗忘在角落-slice

    slice() 方法可从已有的数组中返回选定的元素. 好吧,我承认我竟然把它忘了! 这次我在回顾一下它 语法 arrayObject.slice(start,end) 数组.slice(起始,结束) ...

  3. XHR工厂的实现

    ajax这种常见的开发模式已经遍布我们日常的开发之中了,ajax本质还是采用一种轮询的模式,就是隔一段时间去发送一次http请求,获取数据,然后显示在页面之上,当然,ajax比起新兴的WebScoke ...

  4. [机器学习&数据挖掘]朴素贝叶斯数学原理

    1.准备: (1)先验概率:根据以往经验和分析得到的概率,也就是通常的概率,在全概率公式中表现是“由因求果”的果 (2)后验概率:指在得到“结果”的信息后重新修正的概率,通常为条件概率(但条件概率不全 ...

  5. 【问题收集·中级】关于指示器自定义图片与UUID

    博友问题: 大哥 求教一下 iOS7 能否获取到 uuid 大哥 忙不忙 iOS的加载的时候 动态旋转效果 是 图片 嘛 ? 我的回答 05:43:34hud指示器我用的是这个MBProgressHU ...

  6. spfa求图的最大流

    题目链接: https://vjudge.net/contest/255738#problem/B AC代码: #include <iostream> #include<vector ...

  7. 微信小程序实现首页图片多种排版布局!

    先来个效果图: 使用技术主要是flex布局,绝对定位布局,小程序前端页面开发,以及一些样式! 直接贴代码,都有详细注释,熟悉一下,方便以后小程序开发! wxml: <view class='in ...

  8. nagios报警延迟的解决--flapping state

    这个问题是在测试中发现的.因为要在服务器上布置nagios用来监控oracle,可是发现手动shutdown数据库后能够很快报警,但是再startup后就不是很及时,有时会延迟很久.经过研究发现了这个 ...

  9. Linux环境下段错误的产生原因及调试方法小结【转】

    转自:http://www.cnblogs.com/panfeng412/archive/2011/11/06/2237857.html 最近在Linux环境下做C语言项目,由于是在一个原有项目基础之 ...

  10. sync 解释

    sync命令用于强制被改变的内容立刻写入磁盘,更新超块信息. 在Linux/Unix系统中,在文件或数据处理过程中一般先放到内存缓冲区中,等到适当的时候再写入磁盘,以提高系统的运行效率.sync命令则 ...