Codeforces 375
A
7的所有的余数都可以用1,6,8,9排列得到,然后搞一下就可以了。
B
可以用类似于单调队列的东西搞。具体看代码:
/*
* Problem: B. Maximum Submatrix 2
* Author: Shun Yao
* Note: 题目要求交换行,我写的交换列。于是把矩阵转换一下就可以。
*/ #include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <time.h> #include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#include <bitset>
#include <utility>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> //using namespace std; const int MAXN = 5010, MAXM = 5010; int n, m, a[MAXN][MAXM], f[MAXN][MAXM];
char s[MAXN][MAXM]; int main(/*int argc, char **argv*/) {
int i, j, k, l, ans; // freopen("B.in", "r", stdin);
// freopen("B.out", "w", stdout); scanf("%d%d", &n, &m);
for (i = 1; i <= n; ++i)
scanf(" %s", s[i] + 1);
ans = 0;
for (i = 1; i <= n; ++i) {
a[0][i] = i;
f[0][i] = 0;
}
for (i = 1; i <= m; ++i) {
l = 0;
for (j = 1; j <= n; ++j) {
k = a[i - 1][j];
if (s[k][i] == '1') {
f[i][k] = f[i - 1][k] + 1;
a[i][++l] = k;
ans = std::max(ans, f[i][k] * l);
} else
f[i][k] = 0;
}
for (j = 1; j <= n; ++j)
if (f[i][j] == 0)
a[i][++l] = j;
}
printf("%d", ans); fclose(stdin);
fclose(stdout);
return 0;
}
C
题目中实际上有提示,用dp[i][j][k]表示在(i, j),过所有object的射线的奇偶性为k的最小步数。
/*
* Problem: C. Circling Round Treasures
* Author: Shun Yao
*/ #include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <time.h> #include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <vector>
#include <bitset>
#include <utility>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> //using namespace std; const int MAXN = 22, MAXM = 22, dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}; int n, m, a[MAXN][MAXM], sum[333], f[MAXN][MAXM][333];
char s[MAXN][MAXM]; class Data {
public:
int x, y, k;
Data(int X, int Y, int K) : x(X), y(Y), k(K) {}
} ; std::queue<Data> q; int main(/*int argc, char **argv*/) {
int bomb, object, tl, i, j, k, x, y, trea[10], treasure[10], sx, sy, xx, yy, kk, ans; scanf("%d%d", &n, &m);
for (i = 1; i <= n; ++i)
scanf(" %s", s[i] + 1);
bomb = 0;
object = 0;
tl = 0;
for (i = 1; i <= n; ++i)
for (j = 1; j <= m; ++j) {
switch (s[i][j]) {
case 'B':
++object;
bomb += 1 << (object - 1);
for (k = 1; k <= i; ++k)
a[k][j] += 1 << (object - 1);
break;
case 'S':
s[i][j] = '.';
sx = i;
sy = j;
break;
case '.':
break;
case '#':
break;
default:
++tl;
++object;
trea[s[i][j] - '0'] = 1 << (object - 1);
for (k = 1; k <= i; ++k)
a[k][j] += 1 << (object - 1);
}
}
for (i = 1; i <= tl; ++i)
scanf("%d", &treasure[i]);
for (i = 0; i < 1 << object; ++i)
if ((i & bomb) == 0)
for (j = 1; j <= tl; ++j)
if (i & trea[j])
sum[i] += treasure[j];
//bfs-----------------------------------------------------------------------
memset(f, -1, sizeof f);
f[sx][sy][0] = 0;
q.push(Data(sx, sy, 0));
ans = 0;
while (!q.empty()) {
x = q.front().x;
y = q.front().y;
k = q.front().k;
q.pop();
if (x == sx && y == sy)
ans = std::max(ans, sum[k] - f[x][y][k]);
for (i = 0; i < 4; ++i) {
xx = x + dx[i];
yy = y + dy[i];
if (xx < 1 || xx > n || yy < 1 || yy > m || s[xx][yy] != '.')
continue;
kk = k;
if (i == 0)
kk ^= a[xx][yy];
if (i == 1)
kk ^= a[x][y];
if (f[xx][yy][kk] == -1) {
f[xx][yy][kk] = f[x][y][k] + 1;
q.push(Data(xx, yy, kk));
}
}
}
printf("%d", ans); fclose(stdin);
fclose(stdout);
return 0;
}
D
启发式合并平衡树 或者 莫队算法(其实dfs后分块做也可以)。
E
官方给的是线性规划。dp也可以过。
Codeforces 375的更多相关文章
- Codeforces 375 D Tree and Queries
Discription You have a rooted tree consisting of n vertices. Each vertex of the tree has some color. ...
- Codeforces Round #375 (Div. 2) - D
题目链接:http://codeforces.com/contest/723/problem/D 题意:给定n*m小大的字符矩阵.'*'表示陆地,'.'表示水域.然后湖的定义是:如果水域完全被陆地包围 ...
- Codeforces Round #375 (Div. 2) - C
题目链接:http://codeforces.com/contest/723/problem/C 题意:给定长度为n的一个序列.还有一个m.现在可以改变序列的一些数.使得序列里面数字[1,m]出现次数 ...
- Codeforces Round #375 (Div. 2) - B
题目链接:http://codeforces.com/contest/723/problem/B 题意:给定一个字符串.只包含_,大小写字母,左右括号(保证不会出现括号里面套括号的情况),_分隔开单词 ...
- Codeforces Round #375 (Div. 2) - A
题目链接:http://codeforces.com/contest/723/problem/A 题意:在一维坐标下有3个人(坐标点).他们想选一个点使得他们3个到这个点的距离之和最小. 思路:水题. ...
- Codeforces Round #375 (Div. 2) F. st-Spanning Tree 生成树
F. st-Spanning Tree 题目连接: http://codeforces.com/contest/723/problem/F Description You are given an u ...
- Codeforces Round #375 (Div. 2) E. One-Way Reform 欧拉路径
E. One-Way Reform 题目连接: http://codeforces.com/contest/723/problem/E Description There are n cities a ...
- Codeforces Round #375 (Div. 2) D. Lakes in Berland 贪心
D. Lakes in Berland 题目连接: http://codeforces.com/contest/723/problem/D Description The map of Berland ...
- Codeforces Round #375 (Div. 2) B. Text Document Analysis 模拟
B. Text Document Analysis 题目连接: http://codeforces.com/contest/723/problem/B Description Modern text ...
随机推荐
- 尝鲜delphi开发android/ios_环境搭建
Delphi这又老树发新枝了,开始做终端程序开发了,这个东西的准确名字是:RAD Studio XE5,可以使用delphi和c++ builder进行终端开发. 我尽可能讲啰嗦一些,免得回头被人问. ...
- 网站TCP链接暴增
昨天上线后,TCP链接暴增,红点增多. 问题在查.其中有一部分,多线程修改,突破了线程数 64的限制.线程内,会发起网络请求. 怀疑是热点之一.其他的部分也有修改,也被怀疑.准备下次,2部分分开上线. ...
- 无法生成临时类(result=1)。 error CS0229: “DCSoftDotfuscate.aam.a”与“DCSoftDotfuscate.aam.a()”之间存在二义性
对于错误无法生成临时类(result=1).error CS0229: “DCSoftDotfuscate.aam.a”与“DCSoftDotfuscate.aam.a()”之间存在二义性 出现这个错 ...
- 转 Android中进入系统设置界面
Android软件时,常常需要打开系统设置或信息界面,来设置相关系统项或查看系统的相关信息,这时我们就可以使用以下语句来实现:(如打开“无线和网络设置”界面) Intent intent = new ...
- 函数fsp_header_init
/**********************************************************************//** Initializes the space he ...
- 函数flst_remove
移除 node, node->prev直接指向node->next /*********************************************************** ...
- CSS强制英文换行
1. word-break:break-all;只对英文起作用,以字母作为换行依据 2. word-wrap:break-word; 只对英文起作用,以单词作为换行依据 3. white-space: ...
- [转]SQL、LINQ、Lambda
原文链接:http://www.cnblogs.com/mr-hero/p/3532631.html SQL LinqToSql Lambda 1. 查询Student表中的所有记录的Snam ...
- Woobuntu woobuntu_build.sh hacking
# Woobuntu woobuntu_build.sh hacking # 说明: # 有时候因为一些需求,我们需要定制一些系统,包括Ubuntu系统,于是 # 我们自然需要知道如何去解包一个Ubu ...
- 【MySQL for Mac】在Mac终端导入&导出.sql文件
导入 打开终端输入:(前提是已经配置过MySQL环境变量) mysql -u root -p create database name; use name; source 『将.sql文件直接拖拽至终 ...