1 条题解

  • 0
    @ 2025-8-24 22:42:05

    自动搬运

    查看原文

    来自洛谷,原作者为

    avatar Loser_Syx
    不可逆の方が美しいから

    搬运于2025-08-24 22:42:05,当前版本为作者最后更新于2023-01-08 21:05:15,作者可能在搬运后再次修改,您可在原文处查看最新版

    自动搬运只会搬运当前题目点赞数最高的题解,您可前往洛谷题解查看更多

    以下是正文


    问题 A

    思路:很简单,只要用 % 取余就可以了。

    code:

    #include <bits/stdc++.h>
    using namespace std;
    int main(){
        cout << 2021 % 20; 
        return 0;
    }
    

    答案为 11

    问题 B

    思路:

    按照题目所给的公式,进行计算,由于题目说输出后五位, 所以我们每次乘完取余都需要 mod\bmod 100000100000

    code:

    #include <bits/stdc++.h>
    using namespace std;
    int main(){
    	int ans = 1;
    	for(int i = 2021; i >= 1; i -= 2){
    		ans *= i;
    		ans %= 100000;
    	}
    	cout << ans;
    	return 0;
    }
    

    答案是 5937559375

    问题 C

    思路:

    直接暴力枚举出所有可能,枚举成边长 20212021 的正方形就行了, 因为边长为 20222022 时, 1×2022>20211 \times 2022 > 2021, 已经不可能了,再去判断 n×mn \times m 是否 2021\leq 2021,如果是,则 ans+1+1

    code

    #include <bits/stdc++.h>
    using namespace std;
    int main(){
    	int ans = 0;
    	for(int i = 1; i <= 2021; i++){
    		for(int j = 1; j <= 2021; j++){
    			if(i * j <= 2021){
    				ans++;
    			}
    		}
    	}
    	cout << ans;
    }
    

    答案是 1569815698

    问题 D

    思路:

    五重暴力枚举,时间复杂度飘上天,但是这是提交答案题,不用管它,算出来填上去就行了!!! (然后我就为此废了 11 小时的时间, 吓得我以为我的代码废了)。

    code:

    #include <bits/stdc++.h>
    using namespace std;
    int main(){
    	long long ans = 0;//不开longlong见祖宗
    	for(int a = 1; a <= 2021; a++){
    		for(int b = 1; b <= 2021; b++){
    			for(int c = 1; c <= 2021; c++){
    				for(int d = 1; d <= 2021; d++){
    					for(int e = 1; e <= 2021; e++){
    						if(a+b+c+d+e==2021){//暴力枚举
    							ans++;
    						}
    					}
    				}
    			}
    		}
    	}
    	cout << ans;
    }
    

    时间复杂度实在太高,必须得想一些优化的办法,这时就有一种新的方法:

    20212021 拆分成 2021202111,则两个 11 之间有 20202020 种方法种放置可能。问题中将 20212021 分解成五个正整数的和也就是在 20202020 种可能中选取 44 种放置方式,即可用组合数表示为 C20204C^4_{2020}

    code:

    #include <bits/stdc++.h>
    using namespace std;
    int main(){
    	long long ans = 1;
    	for(int i = 2020; i >= 2017; i--){
    		ans *= i;
    	}
    	cout << ans / (4 * 3 * 2 * 1);
    }
    

    得到得数 691677274345691677274345

    问题 E

    思路就是使用最小生成树和并查集,找到答案。

    由于代码长度问题,就不贴了。

    答案是 40464046

    最后再把输入输出的模板套上去,就能 AC 了!!!

    • 1

    信息

    ID
    7929
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者