第十三届蓝桥杯 Java C组省赛 C 题——纸张尺寸(AC)

1.纸张尺寸

1.题目描述

在 ISO 国际标准中定义了 A0 纸张的大小为 1189mm × 841mm, 将 A0 纸 沿长边对折后为 A1 纸, 大小为 841mm × 594mm, 在对折的过程中长度直接取 下整 (实际裁剪时可能有损耗)。将 A1 纸沿长边对折后为 A2 纸, 依此类推。

输入纸张的名称, 请输出纸张的大小。

2.输入格式

输入一行包含一个字符串表示纸张的名称, 该名称一定是 A0、A1、A2、 A3、A4、A5、A6、A7、A8、A9 之一。

3.输出格式

输出两行,每行包含一个整数,依次表示长边和短边的长度。

4.样例输入

A1

5.样例输出

841
594

6.原题链接

纸张尺寸

2.解题思路

签到题,根据题意模拟即可,注意每次折半选的是较长的一边。

3.Ac_code

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int, int> PII;
#define pb(s) push_back(s);
#define SZ(s) ((int)s.size());
#define ms(s,x) memset(s, x, sizeof(s))
#define all(s) s.begin(),s.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const int N = 200010;


void solve()
{
	std::vector<PII> a(10);
	a[0] = {1189, 841};
	for (int i = 1; i < 10; ++i) {
		int l = a[i - 1].first, r = a[i - 1].second;
		if (l > r) {
			a[i].first = l / 2;
			a[i].second = r;
		} else {
			a[i].first = r / 2;
			a[i].second = l;
		}
	}
	string s;
	cin >> s;
	int x = s[1] - '0';
	int l = a[x].first, r = a[x].second;
	if(l>r){
		cout<<l<<'n';
		cout<<r<<'n';
	}else{
		cout<<r<<'n';
		cout<<l<<'n';
	}
}
int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t = 1;
	while (t--)
	{
		solve();
	}
	return 0;
}

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇

)">
下一篇>>