zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    干掉:“请停用以开发者模式运行的扩展程序”
    电脑分区
    tomcat进行远程debug
    工作流审核到最后一步迟迟不能完成
    DataGrid首次进入页面时,不加载任何数据[转]
    用Excel进行个人敏捷项目看板管理
    cnblogs的编辑器BUG反馈:发布或编辑文章完成后,页面是卡死状态的
    程序员如何优雅地挣零花钱?
    SQL Server导入数据报错"无法在只读列“Id”中插入数据",几百个表怎么批量启用'启用标识插入'选项
    SQL Server 各版本发布时间、开发代号及下载地址
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5767051.html
Copyright © 2011-2022 走看看