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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

Codeforces 313

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

A. Ilya and Bank Account 水題

B. Ilya and Queries 水,維護區間和

C. Ilya and Matrix

貪心。大的明顯會被多次取。

/*** Problem:313C* Author:Shun Yao* Time:2013.5.31* Result:Accepted* Memo:greedy*/#include <cstdio> #include <algorithm> #include <functional>const long MaxN = 2000001;long n, N, a[MaxN]; long long s[MaxN], ans;int main() {static long i;scanf("%ld", &N);for (i = 1; i <= N; ++i)scanf("%ld", a + i);std::sort(a + 1, a + N + 1, std::greater<long>());s[0] = 0;for (i = 1; i <= N; ++i)s[i] = s[i - 1] + a[i];ans = 0;for (i = 1; i <= N; i <<= 2)ans += s[i];printf("%lld", ans);return 0; }

?D. Ilya and Roads

好吧,dp。。。

?狀態很好想,f[i][j]代表前i個人覆蓋了j個。

然后是g[i][j]代表覆蓋區間 i -- j 的最小cost;

轉移見code:

/*** Problem:313D* Author:Shun Yao* Time:2013.6.3* Result:Accepted* Memo:DP*/#include <cstdio>long long min(long long x, long long y) {return x < y ? x : y; }const long Maxn = 305; const long long inf = 1LL << 60;long n, m, K; long long g[Maxn][Maxn], f[Maxn][Maxn], ans;int main() {static long a, b, c, i, j, k;scanf("%ld%ld%ld", &n, &m, &K);for (i = 0; i <= n; ++i)for (j = 0; j <= n; ++j)g[i][j] = inf;for (i = 1; i <= m; ++i) {scanf("%ld%ld%ld", &a, &b, &c);g[a][b] = min(g[a][b], c);}for (i = 1; i <= n; ++i)for (j = i; j <= n; ++j)g[i][j] = min(g[i][j], g[i - 1][j]);for (i = 0; i <= n; ++i) {f[i][0] = 0;for (j = 1; j <= n; ++j)f[i][j] = inf;}for (i = 1; i <= n; ++i)for (j = 0; j <= i; ++j) {f[i][j] = f[i - 1][j];for (k = i - j + 1; k <= i; ++k)if (f[k - 1][j - (i - k + 1)] != inf && g[k][i] != inf)f[i][j] = min(f[i][j], f[k - 1][j - (i - k + 1)] + g[k][i]);}ans = inf;for (i = K; i <= n; ++i)if (ans > f[n][i])ans = f[n][i];printf("%I64d", ans == inf ? -1 : ans);return 0; }

E. Ilya and Two Numbers

貪心,構造。

/*** Problem:313E* Author:Shun Yao* Time:2013.6.15* Result:Acceped* Memo:constructive algorithms, greedy*/#include <cstring> #include <cstdio> #include <functional> #include <algorithm>#define Maxn 100005long n, m, a[Maxn], b[Maxn], c[Maxn], d[Maxn], ans[Maxn];int main() {static long i, x, l; #ifndef ONLINE_JUDGEfreopen("e.in", "r", stdin);freopen("e.out", "w", stdout); #endifmemset(a, 0, sizeof a);memset(b, 0, sizeof b);scanf("%ld%ld", &n, &m);for (i = 1; i <= n; ++i) {scanf("%ld", &x);++a[x];}for (i = 1; i <= n; ++i) {scanf("%ld", &x);++b[x];}ans[0] = 0;d[0] = 0;for (i = m - 1; i >= 0; --i) {while (b[m - 1 - i]--)c[++l] = m - 1 - i;while (a[i]--) {if (l)ans[++ans[0]] = i + c[l--];elsed[++d[0]] = i;}}for (i = 1; i <= d[0]; ++i)ans[++ans[0]] = d[i] + c[l--] - m;std::sort(ans + 1, ans + n + 1, std::greater<long>());for (i = 1; i <= n; ++i)printf("%ld ", ans[i]);return 0; }

?

轉載于:https://www.cnblogs.com/hsuppr/archive/2013/06/05/3118614.html

總結

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

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