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 ...
随机推荐
- Android handler.obtainMessage()
在handler.obtainMessage()的参数是这样写的: Message android.os.Handler.obtainMessage(int what, int arg1, int a ...
- struts2中token防止重复提交表单
struts2中token防止重复提交表单 >>>>>>>>>>>>>>>>>>>&g ...
- java知识积累——单元测试和JUnit(二)
首先来复习一下几个重要知识点,然后接着进行一些介绍.在上一篇文章中,我曾经贴过下面这张图片: 在Which method stubs would you like to create?这里,现在结合4 ...
- Linux/Centos下清理内存和Cache方法
Linux/Centos下释放内存和缓存方法 $ free -m 运行sync将dirty的内容写回硬盘$ sync 通过修改proc系统的drop_caches清理free的cache$ echo ...
- SFMPQ打包工具完后小结
硬盘上没有,第一次创建Archive的时候用SFileOpenArchiveForUpdate, 当打开一个已经存在archive的时候用SFileOpenArchive. MpqDeleteFile ...
- WEB-INF目录与META-INF目录的作用
/WEB-INF/web.xml Web应用程序配置文件,描述了 servlet 和其他的应用组件配置及命名规则. /WEB-INF/classes/包含了站点所有用的 class 文件,包括 ser ...
- ZJ2008树的统计(树链剖分)
type node1=record go,next:longint;end; node2=record l,r,mx,sum:longint;end; var i,x,y,n,q,tmp,cnt,sz ...
- EF4.0和EF5.0增删改查写法区别
1 public T AddEntity(T entity) 2 { 3 //EF4.0的写法 4 添加实体 5 //db.CreateObjectSet<T>().AddObject(e ...
- 64位SqlServer通过链接服务器与32位oracle通讯
在SQL SERVER里只安装了32位的oracle客户端的情况下,添加链接服务器然后执行查询会报如下信息: 原因:在64位的SQL Engine中已经不提供MSDAORA 的驱动了,可以使用Ora ...
- POI读取Word与Excel
import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileNotFoundException; ...