The 2014 ACM-ICPC Asia Mudanjiang Regional Contest(2014牡丹江区域赛)
The 2014 ACM-ICPC Asia Mudanjiang Regional Contest
没去现场。做的网络同步赛。感觉还能够,搞了6题
A:这是签到题,对于A堆除掉。假设没剩余在减一。B堆直接除掉 + 1就能够了
B:二分贪心,二分长度。然后会发现本质上是在树上最长链上找两点,那么有二分出来的长度了,就从两端分别往里移动那么长,那两个位置就是放置位置。然后在推断一下就能够了
D:概率DP。首先知道放一个棋子。能够等价移动到右上角区域,那么就能够dp[x][y][k],表示已经完毕x行y列。已经放了k个棋子,那么棋盘被划分成4个区域。利用这个区域能够算概率,然后去转移就可以
H:字符串处理,先hash掉,记录每一个hash值相应的l,r区间。离线处理完每次询问输出就能够了,注意细节
I:签到题,注意0的时候是等于0就能够了
K:贪心,假设数字个数不够。在前面补是最优的。然后从左往右扫描一遍,每次遇到1个星号要扣掉两个数字,假设没有,这须要交换操作。交换肯定和最后面的数字交换是最优的,最后还要考虑一种特殊情况。就是没有交换,而且最后还有数字,这时候要加入一个星号
代码:
A:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int N = 55;
int t, n, m; int a, b, suma, sumb; int main() {
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &m);
suma = sumb = 0;
for (int i = 0; i < n - 1; i++) {
scanf("%d", &a);
suma += a;
}
for (int i = 0; i < m; i++) {
scanf("%d", &b);
sumb += b;
}
int l, r;
l = suma / (n - 1) - (suma % (n - 1) == 0);
r = sumb / m + 1;
if (l > r) swap(l, r);
printf("%d %d\n", l, r);
}
return 0;
}
B:
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std; const int N = 200005; struct Edge {
int u, v;
Edge() {}
Edge(int u, int v) {
this->u = u;
this->v = v;
}
} E[N * 2]; int first[N], next[N * 2], en; void add_Edge(int u, int v) {
E[en] = Edge(u, v);
next[en] = first[u];
first[u] = en++;
} const int INF = 0x3f3f3f3f;
int t, n, vis[N], f[N], u1, u2, Q[N * 2]; int bfs(int root) {
int head = 0, rear = 0;
vis[root] = 0;
Q[rear++] = root;
f[root] = 0;
int u;
while (head < rear) {
u = Q[head++];
for (int i = first[u]; i + 1; i = next[i]) {
Edge e = E[i];
int v = e.v;
if (vis[v] > vis[u] + 1) {
vis[v] = vis[u] + 1;
f[v] = u;
Q[rear++] = v;
}
}
}
return u;
} bool judge(int len) {
memset(vis, INF, sizeof(vis));
u1 = bfs(1);
for (int i = 0; i < len; i++) {
if (f[u1] == 0) {
u2 = u1 % n + 1;
return true;
}
u1 = f[u1];
}
memset(vis, INF, sizeof(vis));
u2 = bfs(u1);
for (int i = 0; i < len; i++) {
if (f[u2] == 0) return true;
u2 = f[u2];
}
bfs(u2);
for (int i = 1; i <= n; i++)
if (vis[i] > len) return false;
return true;
} int main() {
scanf("%d", &t);
while (t--) {
en = 0;
memset(first, -1, sizeof(first));
scanf("%d", &n);
int u, v;
for (int i = 1; i < n; i++) {
scanf("%d%d", &u, &v);
add_Edge(u, v);
add_Edge(v, u);
}
if (n == 2) {
printf("0 1 2\n");
continue;
}
int l = 0, r = n;
while (l < r) {
int mid = (l + r) / 2;
if (judge(mid)) r = mid;
else l = mid + 1;
}
judge(l);
if (u1 == u2) u2 = u2 % n + 1;
printf("%d %d %d\n", l, u1, u2);
}
return 0;
}
D:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int N = 55;
int t, n, m;
double dp[N][N][N * N]; int main() {
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &m);
memset(dp, 0, sizeof(dp));
dp[0][0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
for (int k = max(i, j); k <= i * j; k++) {
double p1 = (i * j - (k - 1)) * 1.0;
double p2 = (n - i + 1) * j;
double p3 = i * (m - j + 1);
double p4 = (n - i + 1) * (m - j + 1);
dp[i][j][k] = dp[i][j][k - 1] * p1 + dp[i - 1][j][k - 1] * p2 + dp[i][j - 1][k - 1] * p3 + dp[i - 1][j - 1][k - 1] * p4;
dp[i][j][k] /= (n * m - (k - 1));
}
}
}
double ans = 0;
for (int i = max(n, m); i <= n * m; i++)
ans += dp[n][m][i] * i - dp[n][m][i - 1] * i;
printf("%.12lf\n", ans);
}
return 0;
}
H:
#include <cstdio>
#include <cstring>
#include <map>
using namespace std; #define MP(a,b) make_pair(a,b) typedef unsigned long long ull;
const ull x = 123;
const int N = 200005;
typedef pair<int, int> pii; char str[N], q[N];
map<ull, pii> g; int t, u, k, lens; int build(ull st) {
int flag = 1;
while (u < lens) {
if (str[u] == '{') {
flag = 0;
u++;
}
if (str[u] == '}') {
u++;
return u;
}
ull nt = st;
while (str[u] != ':' && str[u] != ',' && str[u] != '}')
nt = nt * x + str[u++];
if (str[u] == ':') {
int l = ++u;
int r = build(nt * x + '.');
g[nt] = MP(l, r);
}
if (str[u] == '}') {
if (!flag)
u++;
return u;
}
if (str[u] == ',') {
if (flag) return u;
u++;
}
}
} int main() {
scanf("%d", &t);
while (t--) {
u = 0;
g.clear();
scanf("%s", str);
lens = strlen(str);
build(0);
scanf("%d", &k);
while (k--) {
scanf("%s", q);
ull tmp = 0;
int len = strlen(q);
for (int i = 0; i < len; i++)
tmp = tmp * x + q[i];
if (!g.count(tmp)) {
printf("Error!\n");
continue;
}
int l = g[tmp].first, r = g[tmp].second;
for (int i = l; i < r; i++)
printf("%c", str[i]);
printf("\n");
}
}
return 0;
}
I:
#include <cstdio>
#include <cstring>
#include <cmath> int t, n;
char str[10]; double solve(int x) {
if (x == 0) return 0;
double sb = x * 1.0 / 100;
if (str[0] == 'b') return sb * log2(sb);
if (str[0] == 'n') return sb * log(sb);
if (str[0] == 'd') return sb * log10(sb);
} int main() {
scanf("%d", &t);
while (t--) {
scanf("%d%s", &n, str);
double ans = 0;
int x;
for (int i = 0; i < n; i++) {
scanf("%d", &x);
ans += solve(x);
}
printf("%.12lf\n", -ans);
}
return 0;
}
K:
#include <cstdio>
#include <cstring>
#include <map>
using namespace std; #define MP(a,b) make_pair(a,b) typedef unsigned long long ull;
const ull x = 123;
const int N = 200005;
typedef pair<int, int> pii; char str[N], q[N];
map<ull, pii> g; int t, u, k, lens; int build(ull st) {
int flag = 1;
while (u < lens) {
if (str[u] == '{') {
flag = 0;
u++;
}
if (str[u] == '}') {
u++;
return u;
}
ull nt = st;
while (str[u] != ':' && str[u] != ',' && str[u] != '}')
nt = nt * x + str[u++];
if (str[u] == ':') {
int l = ++u;
int r = build(nt * x + '.');
g[nt] = MP(l, r);
}
if (str[u] == '}') {
if (!flag)
u++;
return u;
}
if (str[u] == ',') {
if (flag) return u;
u++;
}
}
} int main() {
scanf("%d", &t);
while (t--) {
u = 0;
g.clear();
scanf("%s", str);
lens = strlen(str);
build(0);
scanf("%d", &k);
while (k--) {
scanf("%s", q);
ull tmp = 0;
int len = strlen(q);
for (int i = 0; i < len; i++)
tmp = tmp * x + q[i];
if (!g.count(tmp)) {
printf("Error!\n");
continue;
}
int l = g[tmp].first, r = g[tmp].second;
for (int i = l; i < r; i++)
printf("%c", str[i]);
printf("\n");
}
}
return 0;
}
The 2014 ACM-ICPC Asia Mudanjiang Regional Contest(2014牡丹江区域赛)的更多相关文章
- hdu 5016 点分治(2014 ACM/ICPC Asia Regional Xi'an Online)
Mart Master II Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- The 2014 ACM-ICPC Asia Mudanjiang Regional Contest
The 2014 ACM-ICPC Asia Mudanjiang Regional Contest A.Average Score B.Building Fire Stations C.Card G ...
- HDU 5000 2014 ACM/ICPC Asia Regional Anshan Online DP
Clone Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/65536K (Java/Other) Total Submiss ...
- ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków
ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik’s Rect ...
- 2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred)
2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred) easy: ACE ...
- The 2014 ACM-ICPC Asia Mudanjiang Regional Contest 【部分题解】
2014牡丹江亚洲区域赛邀请赛 B题:图论题目 题解:这里 K题:想法题 分析:两种变化.加入和交换.首先:星号是n的话最少须要的数字是n+1,那么能够首先推断数字够不够,不够的话如今最前面添数字,假 ...
- 2014 ACM/ICPC Asia Regional Shanghai Online
Tree http://acm.hdu.edu.cn/showproblem.php?pid=5044 树链剖分,区间更新的时候要用on的左++右--的标记方法,要手动扩栈,用c++交,综合以上的条件 ...
- HDU 5029 Relief grain(离线+线段树+启发式合并)(2014 ACM/ICPC Asia Regional Guangzhou Online)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5029 Problem Description The soil is cracking up beca ...
- 2014 ACM/ICPC Asia Regional Guangzhou Online
Wang Xifeng's Little Plot http://acm.hdu.edu.cn/showproblem.php?pid=5024 预处理出每个点八个方向能走的最远距离,然后枚举起点,枚 ...
随机推荐
- 关于使用 autoFac 的注入方法
1.使用 NUGET 安装 Autofac 2.需要引用Autofac ASP.NET MVC 5 Integration 这个扩展包. 但有时候在NuGet中找不到 该包 需要使用“程序要控制器控 ...
- 携程transform放大效果
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- jquery插件集合
jQuery由美国人John Resig创建,至今已吸引了来自世界各地的众多javascript高手加入其team. jQuery是继prototype之后又一个优秀的Javascrīpt框架.其经典 ...
- python学习笔记(6)——for...in &while
for x in ...循环就是把每个元素代入变量x,然后执行缩进块的语句. 注意:python中的格式也起到语法规则的作用,缩进块就是一个例 求和问题,比较异同 1/sum= ,,,,,,,,,]: ...
- CAD与用户交互在图面上选择一个实体(com接口VB语言)
主要用到函数说明: IMxDrawUtility::GetEntity 与用户交互到在图面上选择一个实体,详细说明如下: 参数 说明 [out] IMxDrawPoint** pPickPoint 返 ...
- 08Webpage Form
Webpage Form 表单(form)在网页中主要负责数据采集功能.一个表单有三个基本组成部分: 表单标签:这里面包含了处理表单数据所用CGI程序的URL以及数据提交到服务器的方法. 表单域:包含 ...
- spring源码下载链接
http://www.blogjava.net/zhyiwww/archive/2014/10/17/418809.html
- 20.IO流部分笔记
20.IO流部分笔记 2018/09/06 1.IO流 1.1 创建字节输出流对象,如果没有就自动创建一个 FileOutputStram fos = new FileOutputStram(&qu ...
- 洛谷——P2094 运输
P2094 运输 题目描述 现在已知N件商品,和搬运它们其中每一件的费用.现在搬家公司老板Mr.sb决定让我们每次任意选取2件商品.然后这2件商品只算一件商品的费用.但是这个商品的搬运费用是将选出的2 ...
- springBoot启动及发布
1.在项目编辑器(IDEA)中启动 运行springBoot项目Application类中main方法,这两个按钮都可以.如下图: 当然还有我们配置的启动按钮,这是最常用的启动方式,不再赘述,如下图: ...