在家补补题

 

模拟 A - Robot Sequence

#include <bits/stdc++.h>

char str[202];

void move(int &x, int &y, char ch)  {
if (ch == 'U') x--;
if (ch == 'D') x++;
if (ch == 'L') y--;
if (ch == 'R') y++;
} int main(void) {
int n; scanf ("%d", &n);
scanf ("%s", &str);
int ans = 0;
for (int i=0; i<n; ++i) {
int x = 0, y = 0;
for (int j=i; j<n; ++j) {
move (x, y, str[j]);
if (x == 0 && y == 0) ans++;
}
}
printf ("%d\n", ans); return 0;
}

暴力 || 找规律 B - Cards

暴力即DFS也行。。。当时就if else乱写一堆过了

#include <bits/stdc++.h>

char str[202];
int col[3]; int main(void) {
int n; scanf ("%d", &n);
scanf ("%s", &str);
col[0] = col[1] = col[2] = 0;
for (int i=0; i<n; ++i) {
if (str[i] == 'R') col[0]++;
if (str[i] == 'G') col[1]++;
if (str[i] == 'B') col[2]++;
}
if (col[0] == n) puts ("R");
else if (col[1] == n) puts ("G");
else if (col[2] == n) puts ("B");
else {
if (col[0] && col[1] && col[2]) puts ("BGR");
else {
if (n == 2) {
if (col[0] == 0) puts ("R");
else if (col[1] == 0) puts ("G");
else if (col[2] == 0) puts ("B");
}
else if (col[0] == 1) {
if (col[1] == 0) puts ("GR");
if (col[2] == 0) puts ("BR");
}
else if (col[1] == 1) {
if (col[0] == 0) puts ("GR");
if (col[2] == 0) puts ("BG");
}
else if (col[2] == 1) {
if (col[0] == 0) puts ("BR");
if (col[1] == 0) puts ("BG");
}
else puts ("BGR");
}
} return 0;

暴力 C - Block Towers

直接枚举答案,同时记录能整除2,整除2和3,只能整除3的个数,当遇到满足条件的就是最优。二分也行。。

#include <bits/stdc++.h>

const int N = 4e6 + 5;

int main(void)  {
int n, m; scanf ("%d%d", &n, &m);
int best = 4000000;
int c1 = 0, c2 = 0, c3 = 0;
for (int i=2; i<=4000000; ++i) {
if (i % 2 == 0) c1++;
if (i % 2 == 0 && i % 3 == 0) c2++;
if (i % 2 != 0 && i % 3 == 0) c3++;
if (c1 >= n && c2 >= m - c3 && c1 - (m - c3) >= n) {
best = i; break;
}
}
printf ("%d\n", best); return 0;
}

暴力+概率 D - Jerry's Protest

题意:已知结果两胜一负,问总和小于后者的概率。

分析:预处理出任意两个数字相减的差的方案数,那么前两次在正数选,后者只要能使得总和小的可以处理前缀和,O (1),总复杂度 O (n ^ 2)。

#include <bits/stdc++.h>

const int N = 2e3 + 5;

int a[N];
int cnt[10005];
int sum[5005]; int main(void) {
int n; scanf ("%d", &n);
for (int i=1; i<=n; ++i) scanf ("%d", &a[i]);
for (int i=1; i<=n; ++i) {
for (int j=1; j<=n; ++j) {
if (i == j) continue;
cnt[5000+a[i]-a[j]]++;
}
}
for (int i=1; i<=5000; ++i) {
sum[i] = sum[i-1] + cnt[i];
}
double ans = 0;
for (int i=5001; i<=9999; ++i) {
if (!cnt[i]) continue;
for (int j=5001; j<=9999; ++j) {
if (!cnt[j]) continue;
int c = 15000 - (i + j) - 1;
if (c < 1 || c > 4999 || !sum[c]) continue;
ans += 1.0 * cnt[i] * cnt[j] * sum[c];
}
}
double div = 1.0 * (n * (n - 1) / 2);
ans = ans / div / div / div;
printf ("%.8f\n", ans); return 0;
}

三分 + 贪心 E - Simple Skewness

题意:选取一个子集使得平均数-中位数最大

分析:首先个数是奇数,如果是偶数,去掉中间较大的数,差会变大(?)。然后排序后,枚举中位数的位置,三分长度,因为差的分布是单峰,选的数字使差尽可能大,右边选择最后几个,左边选取靠近中位数的几个。

#include <bits/stdc++.h>

typedef long long ll;
const int N = 2e5 + 5;
struct Pair {
ll a; int b;
bool operator < (const Pair &rhs) const {
return a * rhs.b < rhs.a * b;
}
};
int a[N];
ll sum[N];
int n, bi, bl;
Pair best; Pair get(int id, int len) {
ll val = sum[id] - sum[id-len-1];
val += sum[n] - sum[n-len];
Pair cur = Pair {val, 2 * len + 1};
cur.a -= 1ll * a[id] * cur.b;
if (best < cur) {
best = cur;
bi = id; bl = len;
}
return cur;
} int main(void) {
scanf ("%d", &n);
for (int i=1; i<=n; ++i) {
scanf ("%d", a + i);
}
std::sort (a+1, a+1+n);
for (int i=1; i<=n; ++i) {
sum[i] = sum[i-1] + a[i];
}
bi = 1; bl = 0;
best = Pair {0, 1};
for (int i=1; i<=n; ++i) {
int low = 0, high = std::min (i - 1, n - i);
while (low + 3 < high) {
int mid1 = (2 * low + high) / 3;
int mid2 = (low + 2 * high) / 3;
Pair v1 = get (i, mid1);
Pair v2 = get (i, mid2);
if (v1 < v2) low = mid1;
else high = mid2;
}
for (int j=low; j<=high; ++j) get (i, j);
}
std::vector<int> ans;
for (int i=bi-bl; i<=bi; ++i) {
ans.push_back (a[i]);
}
for (int i=n-bl+1; i<=n; ++i) {
ans.push_back (a[i]);
}
printf ("%d\n", ans.size ());
for (int i=0; i<ans.size (); ++i) {
if (i > 0) putchar (' ');
printf ("%d", ans[i]);
}
puts (""); return 0;
} 

DP F - Group Projects

题意:n个数字分组,求每组最大值-最小值的和小于k的方案数

分析:明显的DP,复杂度肯定是 O (n ^ 2 * k),难在状态的转移。dp[i][j][k] 考虑前i个数字,open(只知道最小值,最大值未知)了j组,当前累计和为k的方案数。那么open的几组暂时由a[i]"托管",之前是a[i-1]“托管”,那么前后转移累加j * (a[i] - a[i-1]),a[i]有好几种选择,可以close一个组,选择一个组自己为最大值,j - 1;可以多一个组,自己为最小值,j+1;还可以进入某一个组(自己不是最大值)或者自己一个数字成为一个组(不算open)。

#include <bits/stdc++.h>

const int N = 2e2 + 5;
const int K = 1e3 + 5;
const int MOD = 1e9 + 7;
int a[N];
int dp[2][N][K]; void add(int &x, int y) {
x += y;
if (x >= MOD) x %= MOD;
} int main(void) {
int n, m; scanf ("%d%d", &n, &m);
for (int i=1; i<=n; ++i) scanf ("%d", a + i);
std::sort (a+1, a+1+n);
int now = 0;
dp[now][0][0] = 1;
for (int i=1; i<=n; ++i) {
now ^= 1;
memset (dp[now], 0, sizeof (dp[now]));
for (int j=0; j<i; ++j) {
for (int k=0; k<=m; ++k) {
if (!dp[now^1][j][k]) continue;
int &x = dp[now^1][j][k];
int s = k + j * (a[i] - a[i-1]);
if (s > m) continue;
add (dp[now][j][s], 1ll * x * (j + 1) % MOD);
add (dp[now][j+1][s], x);
if (j) add (dp[now][j-1][s], 1ll * x * j % MOD);
}
}
}
int ans = 0;
for (int i=0; i<=m; ++i) add (ans, dp[now][0][i]);
printf ("%d\n", ans); return 0;
}

  

8VC Venture Cup 2016 - Elimination Round的更多相关文章

  1. 8VC Venture Cup 2016 - Elimination Round D. Jerry's Protest 暴力

    D. Jerry's Protest 题目连接: http://www.codeforces.com/contest/626/problem/D Description Andrew and Jerr ...

  2. 8VC Venture Cup 2016 - Elimination Round (C. Block Towers)

    题目链接:http://codeforces.com/contest/626/problem/C 题意就是给你n个分别拿着2的倍数积木的小朋友和m个分别拿着3的倍数积木的小朋友,每个小朋友拿着积木的数 ...

  3. codeforces 8VC Venture Cup 2016 - Elimination Round C. Lieges of Legendre

    C. Lieges of Legendre 题意:给n,m表示有n个为2的倍数,m个为3的倍数:问这n+m个数不重复时的最大值 最小为多少? 数据:(0 ≤ n, m ≤ 1 000 000, n + ...

  4. 8VC Venture Cup 2016 - Elimination Round F - Group Projects dp好题

    F - Group Projects 题目大意:给你n个物品, 每个物品有个权值ai, 把它们分成若干组, 总消耗为每组里的最大值减最小值之和. 问你一共有多少种分组方法. 思路:感觉刚看到的时候的想 ...

  5. 8VC Venture Cup 2016 - Elimination Round G. Raffles 线段树

    G. Raffles 题目连接: http://www.codeforces.com/contest/626/problem/G Description Johnny is at a carnival ...

  6. 8VC Venture Cup 2016 - Elimination Round F. Group Projects dp

    F. Group Projects 题目连接: http://www.codeforces.com/contest/626/problem/F Description There are n stud ...

  7. 8VC Venture Cup 2016 - Elimination Round E. Simple Skewness 暴力+二分

    E. Simple Skewness 题目连接: http://www.codeforces.com/contest/626/problem/E Description Define the simp ...

  8. 8VC Venture Cup 2016 - Elimination Round C. Block Towers 二分

    C. Block Towers 题目连接: http://www.codeforces.com/contest/626/problem/C Description Students in a clas ...

  9. 8VC Venture Cup 2016 - Elimination Round B. Cards 瞎搞

    B. Cards 题目连接: http://www.codeforces.com/contest/626/problem/B Description Catherine has a deck of n ...

随机推荐

  1. qt编译mysql插件

    安装MySQL,C:\Program Files (x86)\MySQL\MySQL Server 5.7,然后把include和lib文件夹拷贝到C盘,因为qmake不允许路径中有空格!!! 安装Q ...

  2. 解决springmvc 前台取不到值

    查看web.xml 如果为web-app_2_3.xsd  spring不支持 修改项目为web-app_2_4.xsd

  3. iOS开发如何学习前端

    原文链接 前端大概三大块. HTML CSS JavaScript 基本上每个概念在iOS中都有对应的.HTML请想象成只能拉Autolayout或者设置Frame的ViewController.好比 ...

  4. fork与vfork的区别与联系

    fork()与vfock()都是创建一个进程,那他们有什么区别呢?总结有以下三点区别: 1. fork ():子进程拷贝父进程的数据段,代码段 vfork ( ):子进程与父进程共享数据段 2. fo ...

  5. debug与release

    因为在Debug中有ASSERT断言保护,所以要崩溃,而在Release优化中就会删掉ASSERT,所以会出现正常运行. void func() {    char b[2]={0};    strc ...

  6. C++11的模板新特性-变长参数的模板

    这个特性很赞,直接给例子吧,假如我要设计一个类,CachedFetcher内部可能使用std::map也可能使用std::unordered_map,也可能是其它的map,怎么设计呢?没有C++11变 ...

  7. ASP.NET Web API中使用GZIP 或 Deflate压缩

    对于减少响应包的大小和响应速度,压缩是一种简单而有效的方式. 那么如何实现对ASP.NET Web API 进行压缩呢,我将使用非常流行的库用于压缩/解压缩称为DotNetZip库.这个库可以使用Nu ...

  8. Delphi中的基础数据类型

    参考http://www.cnblogs.com/del/archive/2007/12/04/982167.html 在学习之初,在这么多的数据类型中,最好记住这五种标准数据类型(整型.实型.字符型 ...

  9. sort函数用法

    原文链接:http://blog.csdn.net/csust_acm/article/details/7326418 sort函数的用法 做ACM题的时候,排序是一种经常要用到的操作.如果每次都自己 ...

  10. python中如何用dis模块来查看py的汇编代码?

    之前测试不成功,用导入dis的方式. 但如何在命令行里加入 -m dis,就会OK啦. python -m dis test.py #coding: utf8 x = [1, 2, 3] for i ...