Codeforces 602A Two Bases 【水题】

本文介绍了一种方法,用于比较两个使用不同基数表示的数的大小,通过将它们转换为十进制进行比较。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Two Bases
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations.

You're given a number X represented in base bx and a number Y represented in base by. Compare those two numbers.

Input

The first line of the input contains two space-separated integers n and bx (1 ≤ n ≤ 102 ≤ bx ≤ 40), where n is the number of digits in the bx-based representation of X.

The second line contains 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.

The following two lines describe Y in the same way: the third line contains two space-separated integers m and by (1 ≤ m ≤ 10,2 ≤ by ≤ 40bx ≠ 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.

There will be no leading zeroes. Both X and Y will be positive. All digits of both numbers are given in the standard decimal numeral system.

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

In the first sample, X = 1011112 = 4710 = Y.

In the second sample, X = 1023 = 215 and Y = 245 = 1123, thus X < Y.

In the third sample,  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.



题意:给定两个不同进制数,判断大小。


水题,转化为十进制比较就可以了。


AC代码:


#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#define INF 0x3f3f3f
#define eps 1e-8
#define MAXN (1000000+10)
#define MAXM (100000)
#define Ri(a) scanf("%d", &a)
#define Rl(a) scanf("%lld", &a)
#define Rf(a) scanf("%lf", &a)
#define Rs(a) scanf("%s", a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%.2lf\n", (a))
#define Pl(a) printf("%lld\n", (a))
#define Ps(a) printf("%s\n", (a))
#define W(a) while(a--)
#define CLR(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define LL long long
#define lson o<<1, l, mid
#define rson o<<1|1, mid+1, r
#define ll o<<1
#define rr o<<1|1
using namespace std;
int main()
{
    int n, m, b1, b2;
    LL A = 0, B = 0;
    Ri(n); Ri(b1);
    for(int i = 0; i < n; i++)
    {
        int a; Ri(a);
        A = A * b1 + a;
    }
    Ri(m); Ri(b2);
    for(int i = 0; i < m; i++)
    {
        int a; Ri(a);
        B = B * b2 + a;
    }
    if(A > B)
        printf(">\n");
    else if(A == B)
        printf("=\n");
    else
        printf("<\n");
    return 0;
}


### 如何在 Codeforces 上找到数学相关的Codeforces 是一个非常受欢迎的在线编程竞赛平台,其中包含了大量涉及不同算法和数据结构类型的目。为了更高效地查找特定主(如数学类)的相关目,可以采用以下方法: #### 方法一:通过标签筛选 Codeforces 的每道目都会被打上相应的标签,这些标签可以帮助用户快速定位到感兴趣的领域。对于数学类目,可以通过访问 Codeforces 目列表页面并利用过滤功能来实现目标[^1]。 具体步骤如下: 1. 打开 Codeforces 官网 (https://codeforces.com/) 并进入 **Problems** 页面。 2. 使用左侧栏中的 “Tags” 过滤器选择与数学相关的标签,例如 `math` 或者 `number theory`。 3. 应用过滤条件后即可看到符合条件的所有目。 这种方法的优点在于简单直观,适合初学者或者希望浏览广泛范围内的数学目的选手。 #### 方法二:借助第三方工具或脚本自动化检索 如果想要更加精确地获取某些难度级别下的数学问,则可能需要编写一些辅助程序来进行批量处理。比如使用 Python 编写的网络爬虫可以从网站提取所需信息,并按照自定义标准分类整理[^3]。 下面展示一段用于抓取指定类别下样本输入输出的小型示例代码片段: ```python from bs4 import BeautifulSoup as soup import requests def fetch_codeforces_problem(tag='math', count=5): url = f'https://codeforces.com/problemset?tags={tag}' response = requests.get(url) page_soup = soup(response.text, "html.parser") problems = [] problem_entries = page_soup.select('.problems tr[data-index]') for entry in problem_entries[:count]: title = entry.find('a').text.strip() link = 'https://codeforces.com' + entry.find('a')['href'] # Fetch sample input/output if necessary. prob_response = requests.get(link) prob_page = soup(prob_response.text, "html.parser") inputs = prob_page.find_all(name="div", attrs={"class": "input"}) outputs = prob_page.find_all(name="div", attrs={"class": "output"}) samples = [ ("Input", "\n".join([str(pre.contents[0]) for pre in inp.find_all("pre")])), ("Output", "\n".join([str(pre.contents[0]) for pre in outp.find_all("pre")])) ] for inp,outp in zip(inputs,outputs)] problems.append({ 'Title':title, 'Link':link, 'Samples':samples }) return problems # Example usage: print(fetch_codeforces_problem()) ``` 此函数会返回前几个带有给定标签的问及其基本详情,包括链接以及部分测试案例的数据表示形式。 #### 方法三:参与专训练营或比赛 除了单独练习之外,还可以参加专注于某一技能提升的比赛活动,像 CF Round 中经常会有专门针对某种技巧设计的一系列挑战项目,在实战环境中锻炼自己的能力往往事半功倍[^2]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值