Codeforces Round #774 (Div. 2) A-C
2022/3/6 6:16:45
本文主要是介绍Codeforces Round #774 (Div. 2) A-C,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
A
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> using namespace std; typedef long long ll; const int N=1e6+10,INF=1e8; int a[N]; int main() { int t; scanf("%d", &t); while(t--) { ll n,s; scanf("%lld%lld", &n,&s); n *= n; printf("%lld\n", s / n); } return 0; }
B
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> using namespace std; typedef long long ll; const int N=2e5+10,INF=1e8; ll a[N]; int main()//红名大佬的题解 { int t; scanf("%d", &t); while(t--) { int n,f=0; scanf("%d", &n); for (int i = 1; i <= n;i++) { scanf("%lld", &a[i]); } sort(a + 1, a + 1 + n); ll l = 2, r = n, ans = a[n] - a[1] - a[2]; while(l<r) { if(ans>0) { f = 1; break; } ans += a[--r] - a[++l]; } if(f) printf("YES\n"); else printf("NO\n"); } return 0; } /*我的题解 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> using namespace std; typedef long long ll; const int N=2e5+10,INF=1e8; ll a[N],s[N]; int main() { int t; scanf("%d", &t); while(t--) { int n; ll sum = 0; scanf("%d", &n); for (int i = 1; i <= n;i++) s[i] = 0; for (int i = 1; i <= n ;i++) { scanf("%lld", &a[i]); } sort(a + 1, a + 1 + n); for (int i = 1; i <= n;i++) { s[i] = s[i - 1] + a[i]; } int k = n / 2; if(n%2==0) { int i = n - 1,f=0; for (int j = 2; j <= k + 1; j++) { if(s[n]-s[i]<=s[j]) { if(i>k+1) i--; else { printf("NO\n"); break; } } else { printf("YES\n"); break; } } } else { if(s[n]-s[k+1]>s[k+1]) printf("YES\n"); else printf("NO\n"); } } return 0; } */
C
参考知乎,位运算的使用,对于每个数可以枚举到2的15次方,然后用n=1!+2!+3!...+t表示,最后把t拆成2的几次幂,即算一下t里有几个1加一起取最小值。
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #include<bitset> using namespace std; typedef long long ll; const int N=1e5+10,INF=1e8; ll fac[20]; int main() { int t; ll res = 1; scanf("%d", &t); for (int i = 1; i <= 15;i++) { res *= i; fac[i - 1] = res; } while (t--) { ll n; int ans = 1000; scanf("%lld", &n); for (int i = 0; i < 1 << 15; i++) { bitset<15> b(i); ll t = n; for (int j = 0; j < 15;j++) t -= fac[j] * b[j]; if(t>=0) { bitset<64> b1(t); ans = min(ans,(int)(b1.count() + b.count())); } } printf("%d\n", ans); } return 0; }
这篇关于Codeforces Round #774 (Div. 2) A-C的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-07-05feign默认connecttimeout和readtimeout是多少-icode9专业技术文章分享
- 2024-07-05idea控制台,日志太多,导致部分想看得日志被刷走 搜不到-icode9专业技术文章分享
- 2024-07-05The server selected protocol version Tls10 is not accepted by client preferences [TLs12]-icode9专业技术文章分享
- 2024-07-05怎么清理项目缓存-icode9专业技术文章分享
- 2024-07-04安装 Eyoucms详细图文教程-icode9专业技术文章分享
- 2024-07-04ueditor 复制文章时,图片的链接是一个下载图片地址,该如何处理?-icode9专业技术文章分享
- 2024-07-04怎样判断host有没有对wordpress有缓存呢-icode9专业技术文章分享
- 2024-07-04具有编译功能的系统make后,无法ssh连接-icode9专业技术文章分享
- 2024-07-04make后如何升级ssh-icode9专业技术文章分享
- 2024-07-03微信支付提示下单账户与支付账户不一致-icode9专业技术文章分享