zoukankan      html  css  js  c++  java
  • 1010. Radix (25)

    1010. Radix (25)

    时间限制
    400 ms
    内存限制
    65536 kB
    代码长度限制
    16000 B
    判题程序
    Standard
    作者
    CHEN, Yue

    Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is "yes", if 6 is a decimal number and 110 is a binary number.

    Now for any pair of positive integers N1 and N2, your task is to find the radix of one number while that of the other is given.

    Input Specification:

    Each input file contains one test case. Each case occupies a line which contains 4 positive integers:
    N1 N2 tag radix
    Here N1 and N2 each has no more than 10 digits. A digit is less than its radix and is chosen from the set {0-9, a-z} where 0-9 represent the decimal numbers 0-9, and a-z represent the decimal numbers 10-35. The last number "radix" is the radix of N1 if "tag" is 1, or of N2 if "tag" is 2.

    Output Specification:

    For each test case, print in one line the radix of the other number so that the equation N1 = N2 is true. If the equation is impossible, print "Impossible". If the solution is not unique, output the smallest possible radix.

    Sample Input 1:
    6 110 1 10
    
    Sample Output 1:
    2
    
    Sample Input 2:
    1 ab 1 2
    
    Sample Output 2:
    Impossible



    #include<iostream>
    #include<stdio.h>
    #include<string.h>
    #define ll long long int
    using namespace std;
    char A[11];
    char B[11];
    ll c,d;
    ll least,most;
    ll q;
    ll changeChar(char a)//换成数字
    {
        if(a>='0'&&a<='9')
            return a-'0';
        else
            return a-'a'+10;
    }
    ll changint(char a[] ,ll b)//得到一直到的值;
    {
        ll n1=strlen(a);
        ll k=1;
        ll sum=0;
        for(ll i=n1-1;i>=0;i--)
        {
           ll n=changeChar(a[i]);
            sum=n*k+sum;
            k=k*b;
    
        }
        return sum;
    }
    ll panduan(char a[])//判断至少是多少位;
    {
        ll n=strlen(a);
        ll low=0;
    
        for(ll i=n-1;i>=0;i--)
        {
             ll p=changeChar(a[i]);
            if(p>low)
                low=p;
        }
        return low+1;
    }
    int compare(char a[],ll w,ll q)
    {
        ll n1=strlen(a);
        ll k=1;
        ll sum=0;
        for(ll i=n1-1;i>=0;i--)
        {
            ll n=changeChar(a[i]);
            sum=n*k+sum;
            k=k*w;
            if(sum>q)
                return 1;
    
        }
          if(sum>q)
                return 1;
        if(sum<q)
            return -1;
        return 0;
    
    }
    ll erfen(char a[],ll l,ll r,ll q )
    {
    
        while(l<r)
        {
             ll now =(l+r)/2;
            int flag=compare(a,now,q);
            if(flag==0)
            {
              return now;
            }
            else if(flag==1)
            {
                r=now;
            }
            else if(flag==-1)
            {
                l=now;
            }
    
    
        }
        return -1;
    }
    
    
    int main()
    {
        cin>>A;
        cin>>B;
        cin>>c;
        cin>>d;
    
    
    
      if(c==1)
      {
           q=changint(A,d);
          least=panduan(B);
          most=(q+1>least+1)?q+1:least+1;
          ll res = erfen(B,least,most,q);
             if(res==-1)
                 cout<<"Impossible"<<endl;
             else
                 cout<<res<<endl;
    
    
      }
      else
      {
    
           q=changint(B,d);
          least=panduan(A);
          most=(q+1>least+1)?q+1:least+1;
          ll res = erfen(A,least,most,q);
             if(res==-1)
                 cout<<"Impossible"<<endl;
             else
                 cout<<res<<endl;
    
      }
    
    
    
        return 0;
    }

    给你 4个数==ABCD 

    A B 是2个数;

    c是1 D就是a的进制;

    2 就是 D 就是b的进制

    求另一个进制


    提交代码

  • 相关阅读:
    制作IOS 后台极光推送时,遇到的小问题
    如何实现IOS_SearchBar搜索栏及关键字高亮
    使用WKWebView替换UIWebView,并且配置网页打电话功能
    [Creating an image format with an unknown type is an error] on cordova, ios 10
    面向对象语言还需要指针么?
    推荐一个简单好用的接口——字典序列化
    ITTC数据挖掘系统(六)批量任务,数据查看器和自由文档
    java的LINQ :Linq4j简明介绍
    别语言之争了,最牛逼的语言不是.NET,也不是JAVA!
    ITTC数据挖掘平台介绍(五) 数据导入导出向导和报告生成
  • 原文地址:https://www.cnblogs.com/2014slx/p/7868982.html
Copyright © 2011-2022 走看看