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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

牛客练习赛13

發(fā)布時間:2025/3/21 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 牛客练习赛13 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題解:出現(xiàn)了最多次數(shù)的只可能是4或者7

1 #pragma warning(disable:4996) 2 #include<queue> 3 #include<cstdio> 4 #include<bitset> 5 #include<cstring> 6 #include<iostream> 7 #include<algorithm> 8 using namespace std; 9 10 int cnt1, cnt2, len; 11 12 int main() 13 { 14 char s[100]; 15 scanf("%s", s); 16 len = strlen(s); 17 cnt1 = cnt2 = 0; 18 for (int i = 0; i < len; i++) { 19 if (s[i] == '4') cnt1++; 20 if (s[i] == '7') cnt2++; 21 } 22 if (cnt1 == 0 && cnt2 == 0) printf("-1\n"); 23 else if (cnt1 >= cnt2) printf("4\n"); 24 else printf("7\n"); 25 }

題解:先構(gòu)造出在1e10范圍內(nèi)的幸運數(shù),然后分段討論。

1 #pragma warning(disable:4996) 2 #include<queue> 3 #include<cstdio> 4 #include<bitset> 5 #include<cstring> 6 #include<iostream> 7 #include<algorithm> 8 using namespace std; 9 typedef long long ll; 10 11 const int maxn = 2000; 12 13 ll cnt = 0; 14 ll a[maxn]; 15 16 void DFS(ll x, int d) { 17 a[cnt++] = x; 18 if (d == 9) return; 19 DFS(x * 10 + 4, d + 1); 20 DFS(x * 10 + 7, d + 1); 21 } 22 23 void Inite() { 24 DFS(0, 0); 25 sort(a, a + cnt); 26 a[cnt++] = 4444444444; 27 } 28 29 int main() 30 { 31 Inite(); 32 ll l, r; 33 while (scanf("%lld%lld", &l, &r)!=EOF) { 34 ll ans = 0, pos = 0; 35 while (l <= r) { 36 while (a[pos] < l) pos++; 37 ans += (min(a[pos], r) - l + 1)*a[pos]; 38 l = a[pos] + 1; 39 } 40 printf("%lld\n", ans); 41 } 42 }

題解:注意到兩種情況,447,4在偶數(shù)的位置上。477,4在奇數(shù)的位置上。剩下的直接改就行。

1 #pragma warning(disable:4996) 2 #include<queue> 3 #include<cstdio> 4 #include<bitset> 5 #include<cstring> 6 #include<iostream> 7 #include<algorithm> 8 using namespace std; 9 10 const int maxn = 1e5 + 5; 11 12 int n, k; 13 char s[maxn]; 14 15 int main() 16 { 17 while (scanf("%d%d", &n, &k) != EOF) { 18 scanf("%s", s + 1); 19 int l = strlen(s+1); 20 for (int i = 1; i < l; i++) { 21 if (s[i] == '4' && s[i + 1] == '7') { 22 //if (i == 1) { s[i + 1] = '4'; k--; continue; } 23 if (i & 1) { 24 if (i + 1 != l && s[i + 2] == '7') { 25 if (k & 1) s[i + 1] = '4'; 26 break; 27 } 28 else s[i + 1] = '4'; 29 } 30 else { 31 if (i - 1 != 0 && s[i - 1] == '4') { 32 if ((k & 1)) s[i] = '7'; 33 break; 34 } 35 else s[i] = '7'; 36 } 37 k--; 38 } 39 } 40 printf("%s\n", s + 1); 41 } 42 return 0; 43 }

?

轉(zhuǎn)載于:https://www.cnblogs.com/zgglj-com/p/8593432.html

《新程序員》:云原生和全面數(shù)字化實踐50位技術專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結(jié)

以上是生活随笔為你收集整理的牛客练习赛13的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。