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 ...
随机推荐
- managedQuery和query的区别,
我们都知道在Android系统中,SQLite数据库的相关操作方式被封装为内容提供Content Provider,可以帮助那些不会SQL语言的开发者快速实现Android平台上的数据库操作,但是平时 ...
- apache缓存
http://www.t086.com/article/4256 http://www.360doc.com/content/09/0928/13/41237_6551659.shtml
- QTP鼠标点击和浏览器事件的动态切换
今天在群里有人问到一个问题,我觉得应该会有很多人会碰到,今天根据自己的思路把这个解决方案整理出来,供自己和大家参考 需求描述: 当输入一个身份证号码的时候,这个号码所对应的数据会被加载到所属的省和市的 ...
- vs2012 arcgis engine 10 丢失arcgis模板
1.Visual Studio 2012环境下安装ArcGIS Engine 10 Visual Studio 2012环境下安装ArcObject SDK for the Microsoft .Ne ...
- Codeforces Round #207 (Div. 2)C
读错题意了..线段树延迟标记 白刷这么多线段树 #include <iostream> #include<cstdio> #include<cstring> #in ...
- 基于XMPP的即时通信系统的建立(三)— 程序设计概览
XMPP与HTTP的比较 XMPP的优势 1. 推送数据 HTTP只能从服务器哪里请求数据,除非服务器正在响应客户端请求,否则不能向客户端发送数据.但XMPP连接是双向的,任何一方在任何时候都 ...
- 《分销系统-原创第一章》之“多用户角色权限访问模块问题”的解决思路( 位运算 + ActionFilterAttribute )
此项目需求就是根据给用户分配的权限,进行相应的权限模块浏览功能,因为项目不是很大,所以权限没有去用一张表去存,我的解决思路如下,希望大家给点建议. 数据库用户表结构如下: 数据库表梳理: BankUs ...
- hdu 4614 Vases and Flowers(线段树:成段更新)
线段树裸题.自己写复杂了,准确说是没想清楚就敲了. 先是建点为已插花之和,其实和未插花是一个道理,可是开始是小绕,后来滚雪球了,跪了. 重新建图,分解询问1为:找出真正插画的开始点和终止点,做成段更新 ...
- java读取照片信息 获取照片拍摄时的经纬度
项目结构 源码:ImageInfo.zip 第一步:添加需要的架包metadate-extractor.jar 架包下载地址:https://code.google.com/p/metadata-ex ...
- ffmpeg+rtsp+dss
1. push stream to dss ffmpeg -f mpegts -re -i film.v -c:v libx264 -s 352x288 -aspect 4:3 -b:v 300k - ...