135 - ZOJ Monthly, August 2014

A:构造问题,推断序列奇偶性。非常easy发现最小值不是1就是0。最大值不是n就是n - 1,注意细节去构造就可以

E:dp。dp[i][j]表示长度i,末尾状态为j的最大值,然后每一个位置数字取与不取,不断状态转移就可以

G:就一个模拟题没什么好说的

H:dfs,每次dfs下去,把子树宽度保存下来,然后找最大值,假设有多个。就是最大值+cnt宽度

I:构造,假设r * 2 > R,肯定无法构造。剩下的就二分底边。按等腰三角形去构造就可以

代码:

A:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std; int n; void print(int n) {
if (n == 3) {
printf("3 1 2");
return;
}
if (n % 2) {
int len = (n - 3) / 2;
printf("%d %d", n, n - len);
for (int i = n - 1; i > n - len; i--)
printf(" %d %d", i, i - len);
printf(" 3 1 2");
}
else {
int len = n / 2;
printf("%d %d", n, n - len);
for (int i = n - 1; i > n - len; i--)
printf(" %d %d", i, i - len);
}
} void print2(int n) {
print(n - 2);
printf(" %d %d", n - 1, n);
} void solve() {
if (n == 1) {
printf("1 1\n1\n1\n");
return;
}
if (n == 2) {
printf("1 1\n1 2\n2 1\n");
return;
}
if (n == 3) {
printf("0 2\n3 1 2\n1 2 3\n");
return;
}
if (n % 2 == 0) {
if (n / 2 % 2) {
printf("1 %d\n", n - 1);
print2(n); printf("\n");
print2(n - 1);
printf(" %d\n", n);
}
else {
printf("0 %d\n", n);
print(n); printf("\n");
print(n - 1); printf(" %d\n", n);
}
}
else {
if ((n + 1) / 2 % 2) {
printf("1 %d\n", n);
print(n - 2); printf(" %d %d\n", n - 1, n);
print(n - 1); printf(" %d\n", n);
}
else {
printf("0 %d\n", n - 1);
print(n); printf("\n");
print2(n - 1); printf(" %d\n", n);
}
}
} int main() {
while (~scanf("%d", &n)) {
solve();
}
return 0;
}

E:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std; const int INF = 0x3f3f3f3f;
int t, n; map<int, int> dp[2];
map<int, int>::iterator it; int lowbit(int x) {
return (x&(-x));
} int solve() {
dp[0].clear();
int pre = 1, now = 0;
int num;
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &num);
num /= 2;
swap(pre, now);
dp[now].clear();
for (it = dp[pre].begin(); it != dp[pre].end(); it++) {
int s = it->first;
if (dp[now].count(s) == 0) dp[now][s] = dp[pre][s];
else dp[now][s] = max(dp[now][s], dp[pre][s]);
int next;
if (s % num) {
next = num;
if (dp[now].count(next) == 0) dp[now][next] = dp[pre][s] + num * 2;
else dp[now][next] = max(dp[now][next], dp[pre][s] + num * 2);
}
else {
next = s + num;
int add = (s % lowbit(next) * 2 + num) * 2;
if (dp[now].count(next) == 0) dp[now][next] = dp[pre][s] + add;
else dp[now][next] = max(dp[now][next], dp[pre][s] + add);
}
}
}
int ans = 0;
for (it = dp[now].begin(); it != dp[now].end(); it++)
ans = max(ans, it->second);
return ans;
} int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
printf("%d\n", solve());
}
return 0;
}

G:

#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std; const int N = 55;
const int d[8][2] = {{1, 0}, {1, 1}, {1, -1}, {0, 1}, {0, -1}, {-1, 0}, {-1, 1}, {-1, -1}}; typedef pair<int, int> pii; int t;
int n, m, f, k;
int g[N][N];
int gg[N][N];
char str[55];
vector<pii> go[1005]; void solve() {
for (int ti = 1; ti <= f; ti++) {
memset(gg, 0, sizeof(gg));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (g[i][j] == 1) {
for (int k = 0; k < 8; k++) {
int xx = i + d[k][0];
int yy = j + d[k][1];
if (xx <= 0 || xx > n || yy <= 0 || yy > m) continue;
gg[xx][yy]++;
}
}
}
} for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
if (g[i][j] == 2) continue;
else if (g[i][j] == 0) {
if (gg[i][j] == 3) g[i][j] = 1;
}
else {
if (gg[i][j] < 2 || gg[i][j] > 3) g[i][j] = 0;
}
}
for (int i = 0; i < go[ti].size(); i++) {
g[go[ti][i].first][go[ti][i].second] = 2;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (g[i][j] == 2) printf("X");
else printf("%d", g[i][j]);
}
printf("\n");
}
} int main() {
scanf("%d", &t);
while (t--) {
scanf("%d%d%d%d", &n, &m, &f, &k);
for (int i = 1; i <= f; i++)
go[i].clear();
for (int i = 1; i <= n; i++) {
scanf("%s", str + 1);
for (int j = 1; j <= m; j++) {
g[i][j] = str[j] - '0';
}
}
int ti, x, y;
while (k--) {
scanf("%d%d%d", &ti, &x, &y);
go[ti].push_back(make_pair(x, y));
}
solve();
}
return 0;
}

H:

#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std; const int N = 10005; int n;
vector<int> g[N]; int dfs(int u) {
int sz = g[u].size();
vector<int> save;
for (int i = 0; i < sz; i++)
save.push_back(dfs(g[u][i]));
sort(save.begin(), save.end());
sz = save.size();
int cnt = 0;
int ans = 1;
for (int i = sz - 1; i >= 0; i--) {
if (i != sz - 1 && save[i] != save[i + 1]) break;
ans = save[i] + cnt;
cnt++;
}
return ans;
} int main() {
while (~scanf("%d", &n)) {
for (int i = 1; i <= n; i++)
g[i].clear();
int v;
for (int i = 2; i <= n; i++) {
scanf("%d", &v);
g[v].push_back(i);
}
printf("%d\n", dfs(1));
}
return 0;
}

I:

#include <cstdio>
#include <cstring>
#include <cmath> double r, R; double h, x; double cal(double a) {
double d = a / 2;
h = sqrt(R * R - d * d) + R;
x = sqrt(h * h + d * d);
return a * x * x / (2 * R * (a + x + x));
} void solve() {
double lx = 0, rx = sqrt(3.0) * R;
double mid;
for (int i = 0; i < 1000; i++) {
mid = (lx + rx) / 2;
double tmp = cal(mid);
if (tmp > r) rx = mid;
else lx = mid;
}
cal((lx + rx) / 2);
printf("%.10lf %.10lf %.10lf\n", mid, x, x);
} int main() {
while (~scanf("%lf%lf", &r, &R)) {
if (r * 2 > R) printf("NO Solution!\n");
else solve();
}
return 0;
}

135 - ZOJ Monthly, August 2014的更多相关文章

  1. 浙大月赛ZOJ Monthly, August 2014

    Abs Problem Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge Alice and Bob is playing a ga ...

  2. ZOJ Monthly, August 2014

    A Abs Problem http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5330 找规律题,构造出解.copyright@ts ...

  3. ZOJ Monthly, November 2014

    做了一次月赛,没想到这么难,加上后来补上的题目也只有3个题.第一名也只有4个题啊啊啊啊~.其中两道还是水题.留坑慢慢补上来. 3832 Tilt Cylinder 给定如图所示有盖圆柱体,R,H,水面 ...

  4. ZOJ Monthly, June 2014 月赛BCDEFGH题题解

    比赛链接:点击打开链接 上来先搞了f.c,,然后发现状态不正确,一下午都是脑洞大开,, 无脑wa,无脑ce...一样的错犯2次.. 硬着头皮搞了几发,最后20分钟码了一下G,不知道为什么把1直接当成不 ...

  5. 记次浙大月赛 134 - ZOJ Monthly, June 2014

    链接 虽做出的很少,也记录下来,留着以后来补..浙大题目质量还是很高的 B 并查集的一些操作,同类和不同类我是根据到根节点距离的奇偶判断的,删点是直接新加一个点,记得福大月赛也做过类似的,并差集的这类 ...

  6. 137 - ZOJ Monthly, November 2014 - J Poker Face

    Poker Face Time Limit: 2 Seconds      Memory Limit: 65536 KB As is known to all, coders are lack of ...

  7. ZOJ Monthly, June 2014 解题报告

    A.Another Recurrence Sequence problemId=5287">B.Gears 题目大意:有n个齿轮,一開始各自为一组.之后进行m次操作,包含下面4种类型: ...

  8. ZOJ 4010 Neighboring Characters(ZOJ Monthly, March 2018 Problem G,字符串匹配)

    题目链接  ZOJ Monthly, March 2018 Problem G 题意  给定一个字符串.现在求一个下标范围$[0, n - 1]$的$01$序列$f$.$f[x] = 1$表示存在一种 ...

  9. ZOJ 4009 And Another Data Structure Problem(ZOJ Monthly, March 2018 Problem F,发现循环节 + 线段树 + 永久标记)

    题目链接  ZOJ Monthly, March 2018 Problem F 题意很明确 这个模数很奇妙,在$[0, mod)$的所有数满足任意一个数立方$48$次对$mod$取模之后会回到本身. ...

随机推荐

  1. Unity 碰撞检测

    武器与怪物的碰撞 目前来说有三种思路,其实前两种算变种了: 1.动画关键帧回调 + 范围检测.http://blog.csdn.net/u013700908/article/details/52888 ...

  2. web自动化测试:watir+minitest(二)

    环境搭建: 我已经安装了一台全新的win7虚拟机.下面将开始搭建watir环境. 安装包清单. 安装ruby.执行rubyinstaller-2.2.4-x64.exe 选择语言: 勾选添加到环境变量 ...

  3. [LOJ#2328]「清华集训 2017」避难所

    [LOJ#2328]「清华集训 2017」避难所 试题描述 "B君啊,你当年的伙伴都不在北京了,为什么你还在北京呢?" "大概是因为出了一些事故吧,否则这道题就不叫避难所 ...

  4. 省选算法学习-dp优化-四边形不等式

    嗯......四边形不等式的确长得像个四边形[雾] 我们在dp中,经常见到这样一类状态以及转移方程: 设$dp\left[i\right]\left[j\right]$表示闭区间$\left[i,j\ ...

  5. Ionic2 调用自定义插件之研究

    cordova机制我在此就不提了,我们使用Typescript调用cordova plugin就如同调用第三方库是一个道理,那么这里就少不了书写declare文件,下面我就把几种封装调用的几种方式介绍 ...

  6. Codeforces Round #361 (Div. 2) B bfs处理

    B. Mike and Shortcuts time limit per test 3 seconds memory limit per test 256 megabytes input standa ...

  7. Cookies设置,获取,删除

    之前的博客,整理了下Session的存储方式和原理http://www.cnblogs.com/chinaagan/p/3200456.html. 本篇再次整理下Cookies的使用和原理. 参考博客 ...

  8. 33个好用的图片轮显 jquery图片轮显

    原文发布时间为:2011-05-28 -- 来源于本人的百度文章 [由搬家工具导入] 我个人还是喜欢 jquery.recycle,比较通用。因为由美工设计好的轮显结构,如果套用下面,就感觉不是很方便 ...

  9. [LeetCode] Populating Next Right Pointers in Each Node 深度搜索

    Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *nex ...

  10. [LeetCode] Minimum Depth of Binary Tree 二叉树最小深度

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...