Western Subregional of NEERC, Minsk, Wednesday, November 4, 2015 Problem A. A + B
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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 2010 NEERC Western subregional
2010 NEERC Western subregional Problem A. Area and Circumference 题目描述:给定平面上的\(n\)个矩形,求出面积与周长比的最大值. s ...
- 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 ...
- 【GYM101409】2010-2011 ACM-ICPC, NEERC, Western Subregional Contest
A-Area and Circumference 题目大意:在平面上给出$N$个三角形,问周长和面积比的最大值. #include <iostream> #include <algo ...
随机推荐
- bzoj千题计划228:bzoj2095: [Poi2010]Bridges
http://www.lydsy.com/JudgeOnline/problem.php?id=2095 二分答案,判断是否存在混合图的欧拉回路 如果只有一个方向的风力<=mid,这条边就是单向 ...
- [整理]Git使用文章整理
http://pcottle.github.io/learnGitBranching/ http://www.ruanyifeng.com/blog/2012/07/git.html
- BZOJ1009 GT考试
1009: [HNOI2008]GT考试 Time Limit: 1 Sec Memory Limit: 162 MB Description 阿申准备报名参加GT考试,准考证号为N位数X1X2.. ...
- 20155314 2016-2017-2 《Java程序设计》第5周学习总结
20155314 2016-2017-2 <Java程序设计>第5周学习总结 教材学习内容总结 理解异常架构 牚握try...catch...finally处理异常的方法 会用throw, ...
- shell 判断路径
判断路径 ];then echo "找到了123" if [ -d /root/Desktop/text ] then echo "找到了text" else ...
- linux - JDK 环境
JDK安装 vi /etc/profile # 添加环境变量 export JAVA_HOME=/usr/local/jdk1.8.2_45 export CLASSPATH=.:$JAVA_HOME ...
- java future 并发简单实现
List<Future<>> futures = new ArrayList<>();List<T> t= new ArrayList<>( ...
- C# sha256 加密算法
C# 非对称加密 public string sha256(string data) { byte[] bytes = Encoding.UTF8.GetBytes(data); byte[] has ...
- 【并行计算】用MPI进行分布式内存编程(一)
通过上一篇关于并行计算准备部分的介绍,我们知道MPI(Message-Passing-Interface 消息传递接口)实现并行是进程级别的,通过通信在进程之间进行消息传递.MPI并不是一种新的开发语 ...
- react-native 报错
报错信息: java.lang.RuntimeException: Unable to load script from assets 'index.android.bundle'. Make sur ...