zoukankan      html  css  js  c++  java
  • FZU 2102 Solve equation 多进制计算

    Solve equation
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

    Description

    You are given two positive integers A and B in Base C. For the equation:

    A=k*B+d

    We know there always existing many non-negative pairs (k, d) that satisfy the equation above. Now in this problem, we want to maximize k.

    For example, A="123" and B="100", C=10. So both A and B are in Base 10. Then we have:

    (1) A=0*B+123

    (2) A=1*B+23

    As we want to maximize k, we finally get one solution: (1, 23)

    The range of C is between 2 and 16, and we use 'a', 'b', 'c', 'd', 'e', 'f' to represent 10, 11, 12, 13, 14, 15, respectively.

    Input

    The first line of the input contains an integer T (T≤10), indicating the number of test cases.

    Then T cases, for any case, only 3 positive integers A, B and C (2≤C≤16) in a single line. You can assume that in Base 10, both A and B is less than 2^31.

    Output

    For each test case, output the solution “(k,d)” to the equation in Base 10.

    Sample Input

    3
    2bc 33f 16
    123 100 10
    1 1 2
    

    Sample Output

    (0,700)
    (1,23)
    (1,0)

    每一位的数要乘进制 不要只是乘了10

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    #include <queue>
    #include <vector>
    #include <iomanip>
    #include <math.h>
    #include <map>
    using namespace std;
    #define FIN     freopen("input.txt","r",stdin);
    #define FOUT    freopen("output.txt","w",stdout);
    #define INF     0x3f3f3f3f
    #define INFLL   0x3f3f3f3f3f3f3f
    #define lson    l,m,rt<<1
    #define rson    m+1,r,rt<<1|1
    typedef long long LL;
    typedef pair<int,int> PII;
    
    const int MAXN = 1000 + 5;
    
    char A[MAXN];
    char B[MAXN];
    
    int getnum(char a){
       if(a >= '0' && a <= '9')  return a - '0';
       else return a - 'a' + 10;
    }
    
    int main()
    {
        //FIN
        int T, C;
        scanf("%d", &T);
        while(T--){
            scanf("%s%s", A, B);
            scanf("%d", &C);
            int lenA = strlen(A);
            int lenB = strlen(B);
            int numA = 0, numB = 0;
            for(int i = 0;i < lenA; i ++){
                numA = numA * C + getnum(A[i]);
            }
            for(int i = 0;i < lenB; i ++){
                numB = numB * C + getnum(B[i]);
            }
            //cout<<numA<<"       "<<numB<<endl;
            int d = numA % numB;
            int k = numA / numB;
            printf("(%d,%d)
    ", k, d);
        }
    
    }
    

      

  • 相关阅读:
    Swift
    Swift
    Swift
    Mac
    Mac
    Sqlite数据库 找不到请求的 .Net Framework Data Provider。可能没有安装
    Couchbase的web管理员后台 查看缓存提示警告 Warning: Editing of document with size more than 2.5kb is not allowed的解决方法
    转:asmx迷10分钟升级成wcf熟手指南
    .net4.0下 解决asp.net中“从客户端中检测到有潜在危险的Request.Form值”的错误
    Windows系统下Memcached缓存系列二:CouchbaseClient(c#客户端)的详细试用,单例模式
  • 原文地址:https://www.cnblogs.com/Hyouka/p/5790896.html
Copyright © 2011-2022 走看看