1 条题解
-
0
自动搬运
来自洛谷,原作者为

oldnet
去cn看主页||私信壶关||> 最后在线时间:2025年8月24日20时5分 < 由 exOIso 发送激光||拒绝接龙搬运于
2025-08-24 22:41:23,当前版本为作者最后更新于2023-04-22 12:35:40,作者可能在搬运后再次修改,您可在原文处查看最新版自动搬运只会搬运当前题目点赞数最高的题解,您可前往洛谷题解查看更多
以下是正文
A 平方和。
我们可以直接从 一个一个枚举。枚举一个数时要首先数位分离,如果这个数字某一位是 或 或 或 ,则把答案加上这个数的平方。
题目核心代码:
while(n){ if(n%10==2||n%10==0||n%10==1||n%10==9){ sum+=a*a; } n/=10; }最终答案。
2658417853B 数列求值。
直接按题意模拟即可。
核心代码:
int a, b, c, d; a = b = 1; c = 3; for(int i = 4; i < 20190324; i++) { d = (a + b + c) % 10000; a = b; b = c; c = d; }最终答案。
4659C 最大降雨量

为了方便理解,假设每一周都是递增,且每一周的中位数都是递增。
要找中位数的中位数,那么必须红色区域(要求的)要小于绿色区域。而每行的绿色区域要小于同一行的黄色区域。因为红色区域是在这 个格子中最小的一个,根据贪心策略,答案就是 。
D 迷宫
思路: 直接 bfs 搜一遍。
核心代码:
while(!q.empty()) { node now = q.front(); q.pop(); for(int k = 0; k < 4; k++) { int x = now.x + delta[k][0], y = now.y + delta[k][1]; if(x < 0 || y < 0 || x >= n || y >= m || vis[x][y] || map[x][y]) continue; vis[x][y] = 1, way[x][y] = k; node tmp = {x, y}; q.push(tmp); } } int x = n - 1, y = m - 1, num = 0; while(x != 0 || y != 0) { int k = way[x][y]; ans[num++] = cc[k]; x -= delta[k][0], y -= delta[k][1]; } num--; do { cout << ans[num]; } while(num--);答案:
DDDDRRURRRRRRDRRRRDDDLDDRDDDDDDDDDDDDRDDRRRURRUURRDDDDRDRRRRRRDRRURRDDDRRRRUURUUUUUUULULLUUUURRRRUULLLUUUULLUUULUURRURRURURRRDDRRRRRDDRRDDLLLDDRRDDRDDLDDDLLDDLLLDLDDDLDDRRRRRRRRRDDDDDDRRE RSA 解密
核心代码:
void getPrime(int n) { for(int i=2; i<=n; ++i) { if(!notPrime[i]) sushu[cnt++] = i; for(int j=0; j<cnt&&1ll*i*sushu[j]<=n; ++j) { notPrime[i*sushu[j]] = true; if(i%sushu[j]==0) break; } } for(int i=0; i<20; ++i) cout<<sushu[i]<<" "; cout<<endl; } void fenjie(LL x) { cout<<x<<" = 1"; for(int i=0; i<cnt&&sushu[i]<=x/sushu[i]; ++i) { while(x%sushu[i]==0) { cout<<" * "<<sushu[i]; x /= sushu[i]; } } if(x>1) cout<<" * "<<x; cout<<endl; } void BF(LL x) { cout<<x<<" = "; for(LL i=1e8+1; i<x; i+=2) { if(x%i==0) cout<<i<<" * ",x/=i; } cout<<x<<endl; } void exgcd(LL a,LL b,LL &d,LL &x,LL &y) { if(b==0) { d = a; x = 1; y = 0; return; } exgcd(b,a%b,d,y,x); y -= (a/b)*x; } LL rev(LL t,LL m) { LL d,x,y; exgcd(t,m,d,x,y); return (x%m+m)%m; } LL fast_product(LL a,LL b,LL mod) { LL ans = 0; while(b) { if(b&1) ans = (ans+a)%mod; a = (a+a)%mod; b>>=1; } return ans; } LL fast_pow(LL a,LL b,LL mod) { LL ans = 1; while(b) { if(b&1) ans = fast_product(ans,a,mod); a = fast_product(a,a,mod); b>>=1; } return ans; } int main() { BF(n); LL y = (p-1)*(q-1); LL e = rev(d,y); LL answer = fast_pow(c,e,n);答案:
579706994112328949最终代码
#include<iostream> using namespace std; int main() { string ans [] = { "2658417853", "4659", "34", "DDDDRRURRRRRRDRRRRDDDLDDRDDDDDDDDDDDDRDDRRRURRUURRDDDDRDRRRRRRDRRURRDDDRRRRUURUUUUUUULULLUUUURRRRUULLLUUUULLUUULUURRURRURURRRDDRRRRRDDRRDDLLLDDRRDDRDDLDDDLLDDLLLDLDDDLDDRRRRRRRRRDDDDDDRR", "579706994112328949", }; char T; cin >> T; cout << ans[T - 'A'] << endl; return 0; }直接把答案套进题目中的代码。 收工。
- 1
信息
- ID
- 7882
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者