【蓝桥备赛】纸张尺寸——简单模拟

题目链接

纸张尺寸

个人思路

最原始的是纸张A0尺寸题面中给出了,并且给出了后续纸张尺寸的计算方法,由此可依次推算出后续纸张的大小。

参考代码

Java

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String input = sc.next();
        int op = input.charAt(1) - '0';
        int l = 1189, r = 841;
        while (op > 0) {
            if (l > r) {
                l = l / 2;
            } else {
                r = r / 2;
            }
            op--;
        }
        if (l > r) {
            System.out.println(l);
            System.out.println(r);
        } else {
            System.out.println(r);
            System.out.println(l);
        }
    }
}

Cpp

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
const int N = 1e6 + 3;

char c;
int op;

int main()
{
    cin >> c >> op;
    int l = 1189, r = 841;
    while (op)
    {
        if (l > r)
        {
            l = l / 2;
        }
        else
        {
            r = r / 2;
        }
        op--;
    }
    if (l > r)
    {
        cout << l << endl
             << r;
    }
    else
    {
        cout << r << endl
             << l;
    }
    return 0;
}

Cpp打表…

题目中需求求取的范围非常小,如果实在啥也不会的话,可以自己手算出来进行处理

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
const int N = 1e6 + 3;

char c;
int op;

int main()
{
    cin >> c >> op;
    int arr[10][2] = {1189, 841, 841, 594, 594, 420, 420, 297, 297, 210, 210, 148, 148, 105, 105, 74, 74, 52, 52, 37};
    printf("%d\n%d", arr[op][0], arr[op][1]);
    return 0;
}
  • 10
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值