[CF1812C] Digits 题解

· · 题解

题目链接

洛谷

Codeforces

题意分析

第一行包含一个整数 t ( 1\le t\le 32 ),表示测试用例的数量。

每个测试用例有 n 行。第 i 行为一个整数 a_i ( 1\le a_i\le 9 )。

所有测试用例的 n 总和不超过 155。

题目解法

愚人节的题目没有其他技巧,就全靠猜。

我们猜测每组测试用例求的是它们的乘积,那么样例中的 3 组测试数据中 n 的大小就只有 [3,2,3] 或 [3,1,4] 两种可能,我们可以发现第二种可能和 \pi 非常相似,那我们不妨大胆假设,这 t 组测试数据中 n 的大小对应的就是 \pi 的前 32 位数字(忽略小数点),题目中还给出了一个线索:所有测试用例的 n 总和不超过 155,我们可以把 \pi 的前 32 位数字(忽略小数点)加起来,发现总和就是 155。

所以,我们只需要用一个字符串 s 记录一下 \pi 的前 32 位数字,然后每组测试数据读入 s[t] 个数字,并计算它们的乘积输出。

AC Code

/*
题目编号:
C. Digits
思路:
无
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
string s="0314159265358979323846264338327950288419716939937510";  //这里我直接用了50位
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    for (int i=1;i<=t;i++){
        int pro=1;
        for (int j=1;j<=s[i]-'0';j++){
            int temp;
            cin >> temp;
            pro *= temp;
        }
        cout << pro << endl;
    }
    return 0;
}