D

比赛的时候居然看漏了条件。。。

若在(x, y)格子,那么只能移动到(x+1, y)或(x, y+1)

这样的话就好做了,直接dp,然后统计每一种路径长度经过的点数。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset> using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define pb(x) push_back(x)
#define cls(x, val) memset(x, val, sizeof(x))
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define inc(i, l, r) for(int i=l; i<=r; i++)
const int inf = 0x3f3f3f3f;
const int maxn = 1e6+10;
char a[maxn], b[maxn];
int n, m;
bool vis[maxn], vis1[maxn]; void bfs(int x, int y, bool *vis){
vis[x*m+y] = true;
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if(a[i*m+j] == '#') continue;
if(i>=1&&vis[(i-1)*m+j]) vis[i*m+j] = true;
if(j>=1&&vis[i*m+j-1]) vis[i*m+j] = true;
}
}
} void bfs1(int x, int y, bool *vis){
vis[x*m+y] = true;
for(int i=n-1; i>=0; i--){
for(int j=m-1; j>=0; j--){
if(a[i*m+j] == '#') continue;
if(i<n-1&&vis[(i+1)*m+j]) vis[i*m+j] = true;
if(j<m-1&&vis[i*m+j+1]) vis[i*m+j] = true;
}
}
} int diag[maxn]; int main(){
ios::sync_with_stdio(false);
scanf("%d%d", &n, &m);
for(int i=0; i<n; i++){
scanf("%s", b);
for(int j=0; j<m; j++)
a[i*m+j]=b[j];
}
bfs(0, 0, vis);
// for(int i=0; i<n; i++){
// for(int j=0; j<m; j++){
// cout<<vis[i*m+j]<<" ";
// }
// cout<<endl;
// }
bfs1(n-1, m-1, vis1);
// for(int i=0; i<n; i++){
// for(int j=0; j<m; j++){
// cout<<vis1[i*m+j]<<" ";
// }
// cout<<endl;
// }
if(vis[(n-1)*m+m-1]==false) {
printf("0\n");
return 0;
}
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if(vis[i*m+j]&&vis1[i*m+j]){
//路径长度为i+j经过的点数
diag[i+j]++;
}
}
} for(int i=1; i<n+m-2; i++){
if(diag[i] == 1){
printf("%d\n", 1);
return 0;
}
}
printf("%d\n", 2);
return 0; }

E 构造

构造一棵树,使得2i与2i-1两个节点之间的权重为di.

codeforces 1214的更多相关文章

  1. codeforces -1214 E

    题目https://codeforces.com/problemset/problem/1214/E 就是得知奇数之间不产生影响,先造出一条链,再用偶数往里插就行.链要di从大到小排个序呀!! #in ...

  2. Codeforces 1214 F G H 补题记录

    翻开以前打的 #583,水平不够场上只过了五题.最近来补一下题,来记录我sb的调试过程. 估计我这个水平现场也过不了,因为前面的题已经zz调了好久-- F:就是给你环上一些点,两两配对求距离最小值. ...

  3. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  4. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  5. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  6. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  7. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  8. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  9. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. hdu 3068 最长回文(manacher入门)

    最长回文 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  2. 性能监控工具Munin

    实际场景 公司产品需要观察Ubuntu主机性能,以衡量客户现场的产品是否能满足高频使用需求 选型 在比较了诸多工具之后,考虑时间成本因素,用了比较简单的Munin 安装步骤 1. apt-get in ...

  3. python mooc 3维可视化<第一周第二&三单元>

    小结: 创建 数据对象 structuredGrid grid 使用contourfilter con PolyDataMapper m Actor a 使用 MaskPoint3D mask gly ...

  4. iOS开发——你真的会用SDWebImage?

    http://www.cocoachina.com/ios/20160503/16064.html 本文授权转载,作者:hosea_zhou(简书) SDWebImage作为目前最受欢迎的图片下载第三 ...

  5. js自定义滚动条

    今天听到别人说自定义滚动条,所以就在吃饭的时间写了个 html部分 <div class="out" id="out"> <div class ...

  6. css 不大常见的属性(不断更新中...)

    1 英语或数字强制换行 word-break:break-all; 2 使用具有回弹效果的滚动, 当手指从触摸屏上移开,内容会继续保持一段时间的滚动效果 -webkit-overflow-scroll ...

  7. linux 添加文字、图形、线条、箭头的 截图

    1.deepin-screenshot 截图 软件包里搜索deepin-screenshot 支持添加文字.图形.线条.箭头的功能 2.字体发虚 Linux mint 开始菜单等字体不清晰 在软件管理 ...

  8. kubernetes1.4新特性:支持两种新的卷插件

    背景介绍 在Kubernetes中卷的作用在于提供给POD持久化存储,这些持久化存储可以挂载到POD中的容器上,进而给容器提供持久化存储. 从图中可以看到结构体PodSpec有个属性是Volumes, ...

  9. linux 下配置多个tomcat同时运行

    一个服务器上内存通常有2G或者更多,一个tomcat 运行管理这么多内存有点力不从心,并且貌似一个进程所能建立的线程数量是有限的,于是我们想要在一个服务器上运行多个tomcat.如下是摘抄自:http ...

  10. Unrecognised tag: 'build'

    [ERROR] [ERROR] Some problems were encountered while processing the POMs:[ERROR] Malformed POM H:\ec ...