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千题计划213:bzoj2660: [Beijing wc2012]最多的方案
http://www.lydsy.com/JudgeOnline/problem.php?id=2660 很容易想到是先把n表示成最大的两个斐波那契数相加,然后再拆分这两个斐波那契数 把数表示成斐波那 ...
- html之div始终停留在屏幕中间部分
需求: 使得某一个div始终停留在屏幕中间 实现: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...
- Spring Mvc + Maven + BlazeDS 与 Flex 通讯 (七)
BlazeDS 说明 BlazeDS是由Adobe开源的基于amf协议的,用于解决flex与java通讯的组件; 基于传统的文本协议的XML传输方式,在抽象层方面会有很大的压力,特别在需要序列化与反序 ...
- Python网络通信 (一)
ISO(国际标准化组织)--->网络体系结构标准 OSI模型 OSI 七层模型 应用层 :提供用户服务,具体内容由特定程序规定 表示层 :提供数据的压缩解压和加密等 会话层 :建立程序级的连接, ...
- 001_shell经典案例
一. 二. -n, --numeric-sort compare according to string numerical value -k, --key=KEYDEF sort via a key ...
- 【Android开发】之Fragment重要函数讲解
上一节我们讲到了Fragment的生命周期(都是基于android.support.v4.app包下的Fragment),学习之后相信大家对它的生命周期有了很深入的了解了,如果还有不懂得,可以再看一下 ...
- poj2049
优先队列广搜,有人说用SPFA,不知道怎么做的 #include <cstdio> #include <queue> #include <cmath> #inclu ...
- poj1142
分解质因数 #include <iostream> #include <cmath> using namespace std; int sum(int n) { ; ) { a ...
- MySQL 获得当前日期时间\时间戳 函数
MySQL 获得当前日期时间 函数 1.1 获得当前日期+时间(date + time)函数:now() mysql> select now(); +———————+ | now() | +—— ...
- Matplotlib安装感想
刚刚安装完numpy,看完书又涉及到matplotlib,哎,安装它浪费了我很多时间,但收获很多呀 下面介绍一下具体的安装过程: (1)http://matplotlib.org/downloads. ...