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. vmware安装centos7 安装redis windows7访问redis

    1.在windows7中安装vmware 2.在vmware中安装centos7 3.禁用centos7自带的firewalld.service 4.安装iptables防火墙 5.安装Redis 3 ...

  2. arp_ignore和arp_announce内核参数

    arp_announce : INTEGER 对网络接口上本地IP地址发出的ARP报文作出相应级别的限制. 0:本机所有IP地址都向任何一个接口通告ARP报文. 1:尽量仅向该网卡回应与该网段匹配的A ...

  3. 地理课(geography)

    地理课(geography) 题目描述 地理课上,老师给出了一个巨大的地图,由于世界日新月异,会有一些道路在某一时刻被删除,也会有一些道路在某一时刻被修建.这里的道路均为双向的. 老师认为,有一些城市 ...

  4. Codeforces Round #364 (Div. 2) A 水

    A. Cards time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

  5. python3的cookielib

    http://stackoverflow.com/questions/8405096/python-3-2-cookielib

  6. BZOJ2916 [Poi1997]Monochromatic Triangles 数论

    答案等于总三角形数-不合法数 一个不合法三角形一定存在两个顶点,在这个三角形中这个顶点的角的两边不同色 #include<cstring> #include<cmath> #i ...

  7. regression

    单变量线性回归univariate linear regression 代价函数square error cost function : \(J(\theta)=\frac{1}{2m}\sum_{i ...

  8. 【BZOJ4300】绝世好题(二进制,DP)

    题意: n<=100000,ai<=2*10^9 思路:按二进制逐位考虑,只要有至少1位取and后为1就可以接下去 设dp[i]为第i位取and之后为1的最长的序列长度,意会一下 #inc ...

  9. MSClass (Class Of Marquee Scroll通用不间断滚动JS封装类) Ver 1.65

    原文发布时间为:2010-02-07 -- 来源于本人的百度文章 [由搬家工具导入] http://www.popub.net/script/MSClass.html/*MSClass (Class ...

  10. bzoj 2844 albus就是要第一个出场 异或和出现次数 线性基

    题目链接 题意 给定\(n\)个数,将其所有的子集(\(2^n\)个)的异或和按升序排列.给出一个询问\(q\),问\(q\)在该序列中第一次出现位置的下标(下标从\(1\)开始). 题解 结论 记其 ...