题目链接
个人思路
最原始的是纸张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;
}