日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CodeChef March Lunchtime 2018 div2

發布時間:2024/4/14 编程问答 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CodeChef March Lunchtime 2018 div2 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

地址https://www.codechef.com/LTIME58B?order=desc&sortBy=successful_submissions

簡單做了一下,前三題比較水,第四題應該算是經典題

AChef and Friends

直接暴力枚舉即可

#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int MAXN = 1001, INF = 1e9 + 10; inline int read() {char c = getchar(); int x = 0, f = 1;while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();return x * f; } int N, ans = 0; char s[MAXN]; main() { #ifdef WIN32freopen("a.in", "r", stdin); #endifN = read();for(int i = 1; i <= N; i++) {scanf("%s", s + 1);int L = strlen(s + 1);for(int j = 1; j <= L - 1; j++) {if((s[j] == 'c' && s[j + 1] == 'h')||(s[j] == 'h' && s[j + 1] == 'e')||(s[j] == 'e' && s[j + 1] == 'f')){ans++; break;}}}printf("%d", ans); } A

BMagic Elements

維護一個所有元素的和,直接模擬即可

#include<cstdio> #include<cstring> #include<algorithm> #define int long long using namespace std; const int MAXN = 1e6 + 10, INF = 1e9 + 10; inline int read() {char c = getchar(); int x = 0, f = 1;while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();return x * f; } int N, K, ans = 0; int a[MAXN]; main() { #ifdef WIN32freopen("a.in", "r", stdin); #endifint T = read();while(T--) {N = read(); K = read();int sum = 0, ans = 0;for(int i = 1; i <= N; i++) a[i] = read(), sum += a[i];for(int i = 1; i <= N; i++) if(a[i] + K > sum - a[i])ans++;printf("%d\n", ans);} } B

CThree Integers

把式子化成$2B = A +C$的形式,不難看出改B一定是最優的。

特判一下奇偶性即可

#include<cstdio> #include<cstring> #include<algorithm> #define int long long using namespace std; const int MAXN = 1e6 + 10, INF = 1e9 + 10; inline int read() {char c = getchar(); int x = 0, f = 1;while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();return x * f; } main() { #ifdef WIN32freopen("a.in", "r", stdin); #endifint N = read();while(N--) {int A = read(), B = read(), C = read();int ans = abs(2 * B - A - C);if(ans & 1) printf("%lld\n", ans / 2 + 1);else printf("%lld\n", ans / 2);} } C

DPartitions

個人感覺是一道比較好的題

設所有元素的和為$sum$

不難發現,不論如何分,分成的段數一定是$sum$的因子

而且不論如何分,第一段一定是$1-x$(以$1$為起點)

這樣我們遇到一個因子就枚舉一邊序列暴力分割就可以

這題TM居然卡常

#include<cstdio> #include<cstring> #include<algorithm> #define int long long using namespace std; const int MAXN = 1e6 + 10, INF = 1e9 + 10; inline int read() {char c = getchar(); int x = 0, f = 1;while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();return x * f; } int a[MAXN]; char ans[MAXN]; main() { #ifdef WIN32freopen("a.in", "r", stdin); #endifint T = read();while(T--) {int N = read(), sum = 0;for(int i = 1; i <= N; i++) a[i] = read(), sum += a[i];for(int i = 1; i <= N; i++) {if(sum % i != 0) {ans[i] = '0'; continue;}int cur = 0, num = 0;for(int j = 1; j <= N; j++) {cur += a[j];if(cur == sum / i) cur = 0;else if(cur > sum / i) {ans[i] = '0'; break;}}ans[i] = (cur == 0 ? '1' : '0');}for(int i = 1; i <= N; i++) putchar(ans[i]);puts("");} } D

總結

以上是生活随笔為你收集整理的CodeChef March Lunchtime 2018 div2的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。