D. Good Trip
1.C. Insert and Equalize2.C. Removal of Unattractive Pairs3.D. Jumping Through Segments4.E. Good Triples5.F. Shift and Reverse6.D. Yet Another Monster Fight7.A. Constructive Problems8.C. Game with Multiset9.A. Rating Increase10.B. Swap and Delete11.A. Problemsolving Log12.B. Preparing for the Contest13.C. Quests14.D. Three Activities15.E2. Game with Marbles (Hard Version)16.cf刷题有感17.A. Anonymous Informant18.A. Forked!19.B. Make Almost Equal With Mod20.C. Heavy Intervals21.D. Split Plus K22.A. 202323.B. Two Divisors24.C. Training Before the Olympiad25.D. Mathematical Problem26.F. Greetings27.C. Partitioning the Array28.G. Bicycles29.E. Eat the Chip30.G. Lights31.D. Array Repetition32.D. Berserk Monsters33.E. Increasing Subsequences34.D. Very Different Array35.G. Mischievous Shooter36.B. Plus-Minus Split37.B. A Balanced Problemset38.C. Did We Get Everything Covered39.D. Find the Different Ones!40.C. Grouping Increases
41.D. Good Trip
42.C. Physical Education Lesson43.E. Final Countdown44.D. Divisible Pairs45.G. Vlad and Trouble at MIT46.A. Brick Wall47.B. Minimize Inversions48.C. XOR-distance49.A. Moving Chips50.B. Monsters Attack!51.C. Find B52.D. Slimes53.C. Turtle Fingers: Count the Values of k54.D. Turtle Tenacity: Continual Mods55.D. Vlad and Division56.C. LR-remainders57.D. Lonely Mountain Dungeons题解
1.把分数中的除法用乘以逆元表示,在求模运算里的除法都可以用乘以逆元代替(如果除法的结果为整数),但是这里规定了可以用其表示,那就用其表示
2.读题
code
#include<bits/stdc++.h>
int mod=1e9+7; // 确保 mod 是一个整数
using namespace std;
// 快速幂函数,计算 base 的 exponent 次幂,模 mod
long long qpow(long long base, long long exponent, long long mod) {
long long result = 1;
base = base % mod; // 确保 base 小于 mod
while (exponent > 0) {
if (exponent % 2 == 1) {
result = (result * base) % mod;
}
base = (base * base) % mod;
exponent >>= 1; // exponent /= 2
}
return result;
}
int main() {
int t;
cin >> t;
while (t--) {
int n, m, k;
long long sum = 0; // 使用长整型避免潜在的溢出
cin >> n >> m >> k;
for (int i = 1; i <= m; i++) {
int x, y;
long long z; // 使用长整型避免潜在的溢出
cin >> x >> y >> z;
sum = (sum + z) % mod;
}
long long p = (long long)n * (n - 1) % mod; // 使用长整型避免潜在的溢出
long long ans = 0;
p = 2 * qpow(p, mod - 2, mod) % mod; // 使用 qpow 计算逆元
while (k--) {
ans = (ans + sum * p % mod) % mod;
sum = (sum + m * p % mod) % mod;
}
cout << ans << endl;
}
return 0;
}
合集:
codeforces
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~