SMU Summer 2023 Contest Round 2
SMU Summer 2023 Contest Round 2
A. Treasure Hunt
当\(x1 - x2\)的差值与\(y1-y2\)的差值都能被\(x,y\)整除时,且商之和为2的倍数就一定可以到达
#include<bits/stdc++.h> #define endl '\n' #define int long long #define inf 0x3f3f3f3f using namespace std; const int N = 2e5 + 10, mod = 1e18; int n,m,t,k; void solve(){ int x1,y1,x2,y2,x,y; cin >> x1 >> y1 >> x2 >> y2 >> x >> y; int dx = x2 - x1, dy = y2 - y1; if(dx % x == 0 && dy % y == 0 && ((dx / x + dy / y) % 2 == 0)){ cout << "YES" << endl; }else cout << "NO" << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr); int Ke_scholar = 1; // cin >> Ke_scholar; while(Ke_scholar--) solve(); return 0; } /* */
B. Makes And The Product
对数组排序,显然前三个的积一定是最小的.
取前三个值为\(a1,a2,a3\),因为三种结果都只看\(a3\)的关系,记\(sum\)为\(a3\)的数量.
结果分三种情况 (实际上应该是四种,不过有两组重复了:
- \(a1 = a2 = a3\) 时,说明三个是一样的,只需要在\(sum\)中任取三个即可,即\(C_{sum}^{3}\),也可以用公式\(\frac{sum * (sum - 1) * (sum - 2)}{6}\).
- \(a1 = a2 < a3\) 或者 $a1 < a2 < a3 $ 时,这两种都是一样的,因为前两个都是必须选,然后再从 \(sum\) 中选一个,答案就是 \(sum\) .
- \(a1 < a2 = a3\)时,则\(a1\)必选,然后\(a2,a3\)再从\(sum\)中任选两个即可,即\(C_{sum} ^ {2}\),也可以用公式\(\frac{sum * (sum - 1)}{2}\).
#include<bits/stdc++.h> #define endl '\n' #define int long long #define inf 0x3f3f3f3f using namespace std; const int N = 2e5 + 10, mod = 1e18; map<int, int > mp; int n,m,t,k; void solve(){ cin >> n; vector<int> a(n); for(auto &i : a) cin >> i; sort(a.begin(), a.end()); int a1 = a[0],a2 = a[1],a3 = a[2]; int sum = 0; for(int i = 0;i < n;i ++){ sum += (a[i] == a3); } int ans = 0; if(a1 == a2 && a2 == a3){ ans = sum * (sum - 1) * (sum - 2) / 6; }else if(a1 == a2 && a2 < a3 || a1< a2 && a2 < a3){ ans = sum; }else if(a1 < a2 && a2 == a3){ ans = sum * (sum - 1)/ 2; } cout << ans << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr); int Ke_scholar = 1; // cin >> Ke_scholar; while(Ke_scholar--) solve(); return 0; } /* */
C. Really Big Numbers
由于给定的大数在答案中是单调递增的,所以我们可以对答案进行二分,二分的左边界就是满足条件的最小的大数,这个数到\(n\)之间的都算大数,若左边界大于了n说明没有满足条件的
#include<bits/stdc++.h> #define endl '\n' #define int long long using namespace std; int n,m,t,k; void solve(){ int s; cin >> n >> s; auto get = [&](int x){ int res = 0; while(x){ res += x % 10; x /= 10; } return res; }; int ans = 0, l = 1, r = 1e18; while(l <= r){ int mid = (l + r) >> 1; if(mid - get(mid) >= s){ r = mid - 1; // cout << mid << endl; }else l = mid + 1; } cout << (l > n ? 0 : n - l + 1) << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr); int Ke_scholar = 1; // cin >> Ke_scholar; while(Ke_scholar--) solve(); return 0; } /* */
本文作者:Ke_scholar
本文链接:https://www.cnblogs.com/Kescholar/p/17545069.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
分类:
标签:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架