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,根据这个不停的去做就好了。

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

代码

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 3e6+7;
  4. string s1,s2;
  5. string ans;
  6. int a[maxn],b[maxn];
  7. int c[maxn];
  8. int main(){
  9. cin>>s1>>s2;
  10. reverse(s1.begin(),s1.end());
  11. reverse(s2.begin(),s2.end());
  12. for(int i=0;i<s1.size();i++)
  13. a[i]=s1[i]-'0';
  14. for(int i=0;i<s2.size();i++)
  15. b[i]=s2[i]-'0';
  16. for(int i=0;i<maxn;i++){
  17. c[i]=c[i]+a[i]+b[i];
  18. while(c[i]>=2){
  19. c[i]-=2;
  20. c[i+2]++;
  21. c[i+3]++;
  22. }
  23. }
  24. int flag = 0;
  25. for(int i=maxn-1;i>=0;i--){
  26. if(c[i])flag = 1;
  27. if(flag)cout<<c[i];
  28. }
  29. if(flag==0)cout<<"0";
  30. cout<<endl;
  31. }

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. ML—R常用多元统计分析包(持续更新中……)

    基本的R包已经实现了传统多元统计的很多功能,然而CRNA的许多其它包提供了更深入的多元统计方法,下面要综述的包主要分为以下几个部分: 1) 多元数据可视化(Visualising multivaria ...

  2. 华中邀请赛现场赛F题 Seats

    题目链接:http://acm.whu.edu.cn/land/problem/detail?problem_id=1552 解题报告:题目意思应该很清楚,就是有n个人,分别属于7个班级,然后他们坐成 ...

  3. 第12月第29天 cocos quick manual

    1. Example: $ cd cocos2d-x $ ./setup.py $ source FILE_TO_SAVE_SYSTEM_VARIABLE $ cocos new MyGame -p ...

  4. Verilog笔记.三段式状态机

    之前都是用的一段式状态机,逻辑与输出混在一起,复杂点的就比较吃力了. 所以就开始着手三段式状态机. 组合逻辑与时序逻辑分开,这样就能简单许多了. 但是两者在思考方式上也有着很大的区别. 三段式,分作: ...

  5. 勒索软件Locky、Tesalcrypt等使用了新的工具躲避检测

    勒索软件Locky.Tesalcrypt等使用了新的工具躲避检测 今天我们发现Locky勒索软件家族使用一种新的工具来躲避检测,并且可能已经感染了很多节点. 自从我们通过AutoFocus智能威胁分析 ...

  6. Demo003 最大连续子数组问题(《算法导论》4.1-5)

    问题 问题描述  给定n个整数(可能为负数)组成的数组,要求一个数组连续下标和的最大值,数组的元素可正.可负.可为零.  数组中连续的一个或多个整数组成一个子数组,每个子数组都有一个和.求所有子数组的 ...

  7. SqlServer 中查询子节对应的上级自定义函数

    CREATE FUNCTION [dbo].[FN_TopGetOrgByUserName] ( @UserName NVARCHAR(128) ) RETURNS @showOrg TABLE(id ...

  8. html屏幕旋转事件监听

    近期做微信服务号开发,在做图片展示的时候需要横竖屏的检测实现图片大小不同的展示. 添加屏幕旋转事件侦听,可随时发现屏幕旋转状态(左旋.右旋还是没旋). 摘自:http://bbs.phonegap10 ...

  9. 【LOJ】#2568. 「APIO2016」烟花表演

    题解 这个听起来很毒瘤的想法写起来却非常休闲,理解起来可能很费劲 例如,我们首先到猜到答案是个下凸包 然后是不是要三分???然而并不是orz 我们通过归纳证明这个下凸包的结论来总结出了一个算法 也就是 ...

  10. linux学习笔记-4.系统命令

    1.查看主机名 hostname 2.修改主机名(重启后无效) hostname hadoop 3.修改主机名(重启后永久生效) vi /ect/sysconfig/network 4.修改IP(重启 ...