首页 > 其他分享 >cf 602 A(进制转换)

cf 602 A(进制转换)

时间:2023-08-15 17:38:17浏览次数:27  
标签:digits 进制 602 int res printf cf ans bx


A. Two Bases



time limit per test



memory limit per test



input



output


X and Y

X represented in base bx and a number Y represented in base by. Compare those two numbers.


Input



n and bx (1 ≤ n ≤ 10, 2 ≤ bx), where n is the number of digits in the bx-based representation of X.

n space-separated integers x1, x2, ..., xn (0 ≤ xi < bx) — the digits of X. They are given in the order from the most significant digit to the least significant one.

Y in the same way: the third line contains two space-separated integers m and by (1 ≤ m ≤ 10,2 ≤ bybx ≠ by), where m is the number of digits in the by-based representation of Y, and the fourth line contains m space-separated integers y1, y2, ..., ym (0 ≤ yi < by) — the digits of Y.

X and Y


Output



Output a single character (quotes for clarity):

  • <' if X < Y
  • >' if X > Y
  • =' if X = Y


Sample test(s)



input



6 2 1 0 1 1 1 1 2 10 4 7



output



=



input



3 3 1 0 2 2 5 2 4



output



<



input



7 16 15 15 4 0 0 7 10 7 9 4 8 0 3 1 5 0



output



>


Note



X = 1011112 = 4710 = Y.

X = 1023 = 215 and Y = 245 = 1123, thus X < Y.

In the third sample, 

cf 602 A(进制转换)_sed

 and Y = 48031509. We may notice that X starts with much larger digits and bx is much larger than by, so X is clearly larger than Y.

#include <stdio.h>
using namespace std;

__int64 a[20],b[20];
__int64 res,ans;

int main()
{
    int n,m;
    res=ans=0;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
        scanf("%I64d",a+i);
    __int64 aa,bb;
    aa=1;
    for(int i=n-1;i>=0;i--)
    {
        res+=a[i]*aa;
        aa*=m;
    }
 //   printf("%I64d\n",res);
    int x,y;
    scanf("%d%d",&x,&y);
    for(int i=0;i<x;i++)
        scanf("%I64d",b+i);
    bb=1;
    for(int i=x-1;i>=0;i--)
    {
        ans+=b[i]*bb;
        bb*=y;
    }
 //   printf("%I64d\n",ans);
    if(res>ans)
        printf(">\n");
    else if(res==ans)
        printf("=\n");
    else
        printf("<\n");


    return 0;
}



标签:digits,进制,602,int,res,printf,cf,ans,bx
From: https://blog.51cto.com/u_3936220/7091373

相关文章

  • cf 598 A
    A.TrickySumtimelimitpertestmemorylimitpertestinputoutput1 to n,butyoushouldtakeallpowersoftwowithminusinthesum.n = 4 thesumisequ......
  • cf 583 B. Robot's Task(模拟)
    链接:http://codeforces.com/problemset/problem/583/B//求改变的方向次数//直接模拟题目是从1开始所以从左到右从右到左#include<stdio.h>#include<algorithm>usingnamespacestd;inta[1000+10];intvis[1000+10];intmain(){intn,t=0;scanf("%d",&n);......
  • CF杂题选刷
    CF1855BLongestDivisorsInterval对于任意一个区间\(\left[l,r\right]\),一定有\(\foralli\in\left[1,r-l+1\right]\),都\(\existsj\in\left[l,r\right]\),使得\(i\midj\)。因为模\(i\)意义下的正整数每\(i\)个一循环,由于\(i\)小于区间长度,所以在这个......
  • WCF
    WCF概念一.SOA概念面向服务的架构(SOA)是一个组件模型,它将应用程序的不同功能单元(称为服务)进行拆分,并通过这些服务之间定义良好的接口和协议联系起来。接口是采用中立的方式进行定义的,它应该独立于实现服务的硬件平台、操作系统和编程语言。这使得构建在各种各样的系统中的服......
  • 题解 CF379D New Year Letter
    思路提供一种比较容易想到的做法。拿到题看数据范围发现都很小,所以放心大胆地暴力。容易发现\(s_i\)中AC的个数等于\(s_{i-2}\)中AC的个数加\(s_{i-1}\)中AC的个数再加上两者拼接处可能有的一个AC。所以\(s_1\)和\(s_2\)从第二个字符到倒数第二个字符这之间......
  • CF1845D Rating System 题解
    题面给定一个长度为\(n\)数列\(a\),保证每项都不为\(0\)。初始时\(x=0\),然后对于\(1\lei\len\),按顺序进行如下操作:如果\(x\gek\),则\(x\rightarrow\max(k,x+a_i)\),否则\(x\rightarrowx+a_i\)。你需要求出\(k\),使得\(x\)的值尽量大。题解如果我们不考虑\(k......
  • Java入门学习——二进制、八进制、十六进制
    一、十进制转二进制的算法十进制数转二进制数:除二取余法。  二、十进制转十进制的算法三、二进制转十进制的算法    四、八进制、十六进制介绍为了便于观察和表示二进制,推出八进制和十六进制。每3位二进制作为一个单元,最小数是0(000),最大数是7(111),共8个数字,这就是......
  • CF793F Julia the snail 题解
    题意有一个长为\(n\)的杆,上面有\(m\)条绳子,每条绳子可以让蜗牛从\(l_i\)爬到\(r_i\)(中途不能离开),保证\(r_i\)各不相同。蜗牛也可以自然下落。现在有\(q\)次询问,询问\(x\)出发,途中高度不能低于\(x\)或高于\(y\),问最高能爬到的位置。\(n,m,q\leq10^5\)。题解......
  • CF1859C 题解
    思路我们实际上发现它计算的就是\(p_i\cdoti\)的和再减去一个\(p_i\cdoti\)中的最大值。那我们可以枚举这个最大值\(p_x\cdotx\),这个值就是最后和中需要删除的数值。这里我们可以使用贪心。我们可以从\(n\sim1\)枚举除\(p_i\)的每个数字需要配的数字。当然,......
  • CF1859B 题解
    题意给定\(n\)个长度为\(m\)的数组,每个数组可以向别的数组转移最多一个数字,任意一个数组都可以接受无穷多的数字,最大化每个数组的最小值之和。做法考虑贪心。我们记第\(i\)个数组的第\(j\)个数字为\(a_{i,j}\)。我们先对每一个数组按照升序进行排序,那我们最不愿意......