Codeforces 313
生活随笔
收集整理的這篇文章主要介紹了
Codeforces 313
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
A. Ilya and Bank Account 水題
B. Ilya and Queries 水,維護(hù)區(qū)間和
C. Ilya and Matrix
貪心。大的明顯會(huì)被多次取。
/*** 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。。。
?狀態(tài)很好想,f[i][j]代表前i個(gè)人覆蓋了j個(gè)。
然后是g[i][j]代表覆蓋區(qū)間 i -- j 的最小cost;
轉(zhuǎn)移見(jiàn)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
貪心,構(gòu)造。
/*** 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; }?
轉(zhuǎn)載于:https://www.cnblogs.com/hsuppr/archive/2013/06/05/3118614.html
總結(jié)
以上是生活随笔為你收集整理的Codeforces 313的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Python-02-基础知识
- 下一篇: Django--Forms组件使用