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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

CodeForces 448

發布時間:2025/3/16 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CodeForces 448 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

A:Rewards:

題目鏈接:http://codeforces.com/problemset/problem/448/A

題意:Bizon有a1個一等獎獎杯,a2個二等獎獎杯,a3個三等獎獎杯,b1個一等獎獎牌,b2個二等獎獎牌,b3個三等獎獎牌,和一個有n個架子的櫥柜。現在Bizon想把這些獎牌和獎杯放在櫥柜里,但是要遵循下面的規則:一個架子上不能同時放獎杯和獎牌;一個架子上的獎杯數量不能超過5個,獎牌數量不能超過10個。問能不能把這些獎杯和獎牌全部放進去。

分析:按照貪心原則,一個架子上放盡可能多的獎杯和獎牌,求出需要多少個架子,與n比較大小即可。

#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<cstdlib> #include<algorithm> using namespace std; int main() {int a1, a2, a3, b1, b2, b3, n;while(~scanf("%d%d%d%d%d%d%d",&a1, &a2, &a3, &b1, &b2, &b3, &n)){int suma = a1 + a2 + a3;int sumb = b1 + b2 + b3;int cnta = suma / 5, cntb = sumb / 10;if(suma % 5 != 0)cnta++;if(sumb % 10 != 0)cntb++;if(cnta + cntb <= n)printf("YES\n");elseprintf("NO\n");}return 0; }


B:Suffix Structures

題目鏈接:http://codeforces.com/problemset/problem/448/B

題意:給出兩個串s和t,問能不能把s變成t,如果可以,輸出變換時用的數據結構是什么?變換時可以使用兩種數據結構:1.suffix automaton,它可以刪除串中的任意一個字符;2.suffix array,它可以交換串中的任意兩個字符。如果只用到suffix automaton,輸出“automaton“;如果只用到”suffix array“,輸出”array“;如果兩種都用到,輸出”both“; 如果變不成,輸出“need tree”。

分析:直接模擬即可。

#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<string> #include<cstdlib> #include<algorithm> using namespace std; int main() {string s, t;int a[30], b[30];while(cin >> s >> t){memset(a, 0, sizeof(a));memset(b, 0, sizeof(b));if(s.length() < t.length()){cout << "need tree" << endl;continue;}int ls = s.length(), lt = t.length();if(ls == lt){for(int i = 0; i < ls; i++){a[s[i] - 'a']++;b[t[i] - 'a']++;}int flag = 1;for(int i = 0; i < 26; i++)if(a[i] != b[i]){flag = 0;break;}if(flag)cout << "array" << endl;elsecout << "need tree" << endl;}else{//cout << "s = " << s << ", t = " << t << endl;for(int i = 0; i < ls; i++)a[s[i] - 'a']++;for(int i = 0; i < lt; i++)b[t[i] - 'a']++;int flag = 1, ok = 0;for(int i = 0; i < 26; i++)if(a[i] < b[i]){flag = 0;break;}if(flag){int j, k = 0;for(int i = 0; i < ls; i++){if(s[i] == t[k])k++;if(k == lt){ok = 1;break;}} //t中的字符在s中不一定連續出現,例如ababa abb,應是 aruomaton。比賽時一直Wa在這。}if(flag && ok)cout << "automaton" << endl;else if(flag && !ok)cout << "both" << endl;elsecout << "need tree" << endl;}}return 0; }
C.Painting Fence

題目鏈接:http://codeforces.com/problemset/problem/448/C

題意:Bizon要粉刷他的柵欄,柵欄由n塊木板組成,每一塊有個高度,每次stroke時必須一直接觸著柵欄,問最少需要stroke多少次,可以把柵欄刷好。

分析:分治法。把柵欄從最低處分成左右兩部分,每一部分再這樣分下去,直到只剩下一塊木板,然后往上返回最小值即可。

#include<cstdio> #include<algorithm> using namespace std; const int MAXN = 5005; int a[MAXN]; int solve(int l, int r, int h) {int k = l, mmin = a[l];if(l > r) return 0;if(l == r) return a[l] > h;for(int i = l; i <= r; i++)if(a[i] < mmin){k = i;mmin = a[i];}return min(r-l+1, solve(l, k-1, mmin) + solve(k+1, r, mmin) + (mmin - h)); } int main() {int n;scanf("%d",&n);for(int i = 0; i < n; i++)scanf("%d",&a[i]);printf("%d\n", solve(0, n-1, 0));return 0; }#include<cstdio> #include<algorithm> using namespace std; const int MAXN = 5005; int a[MAXN]; int solve(int l, int r) {int k = l;if(l > r) return 0;for(int i = l; i <= r; i++)if(a[i] < a[k])k = i;int tmp = a[k];for(int i = l; i <= r; i++)a[i] -= tmp;return min(r-l+1, solve(l, k-1) + solve(k+1, r) + tmp); } int main() {int n;scanf("%d",&n);for(int i = 0; i < n; i++)scanf("%d",&a[i]);printf("%d\n", solve(0, n-1));return 0; }
D:Multiplication Table

題目鏈接:http://codeforces.com/problemset/problem/448/D

題意:給出一個n行m列的乘法表,第i行第j列的值為i*j,把這些值從小到大排序,問第k個數是多少。

分析:二分。

#include<iostream> using namespace std; typedef long long LL; LL solve(LL n, LL m, LL k) {LL l = 0, r = n * m;while(r - l > 1){LL mid = (r + l) / 2;LL sum = 0;for(int i = 1; i <= n; i++){LL tmp = mid / i;if(tmp > m) tmp = m;sum += tmp; //sum為不大于mid的值的個數}if(sum >= k) r = mid;else l = mid;}return r; } int main() {LL n, m, k;while(cin >> n >> m >> k){cout << solve(n, m, k) << endl;}return 0; }

E:Divisors(dfs)

題目鏈接:http://codeforces.com/problemset/problem/448/E

題意:給出一個數n,把這個數的因子從小到大寫出來,然后對這個數的因子執行k次相同的操作,問最后的結果是什么。如果結果超過100000位,只輸出前100000位。

分析:因為對每個數執行的是相同的操作,所以可以用遞歸寫,當執行到不能分解時,輸出一個數,直到執行完k次或者個數已經達到了100000個結束。

#include<iostream> #include<cmath> #include<algorithm> using namespace std; typedef __int64 LL; const int MAXN = 100000; LL divisor[MAXN], num; LL cnt = 0; void get_divisor(LL x) {num = 0;LL tmp = (LL)sqrt(x);for(int i = 1; i <= tmp; i++){if(x % i == 0){divisor[num++] = i;if(x / i != i)divisor[num++] = x / i;}}sort(divisor, divisor + num); }void dfs(LL x, LL k) {//cout << "x = " << x << ", k = " << k << endl;if(cnt >= 100000) return ;if(k == 0 || x == 1){cout << x << " ";cnt++;return ;}for(LL i = 0; i < num && divisor[i] <= x; i++){if(x % divisor[i] == 0) {dfs(divisor[i], k-1);if(cnt >= 100000) return ;}} }int main() {LL x, k;while(cin >> x >> k){get_divisor(x);dfs(x, k);cout << endl;}return 0; }

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

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

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