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. H5C3--sessionStorage和localStorage的使用

    一.sessionStorage的使用 <!DOCTYPE html> <html lang="en"> <head> <meta cha ...

  2. SSH 相关基础

    检查是否安装: sudo apt-cache policy openssh-client sudo apt-cache policy  openssh-server 也可直接用 sudo apt-ca ...

  3. 磁力搜索嗅探器装成BT

    磁力搜索嗅探器装成BT ague-dht ague-dht 是一个磁力链接嗅探器,它伪装成BT下载客服端,加入DHT网络,嗅探磁力链接.每秒发送1000条请求时,平均3秒收到1次带有infohash的 ...

  4. 【linux配置】VMware安装Redhat6.5

    VMware安装Redhat6.5 VMware安装Redhat6.5安装之前需要一些准备工作,首先,电脑上需要安装VMware(这个是废话),其次就是需要Redhat6.5的镜像文件(现在貌似都出R ...

  5. SpringBoot启动报错Failed to determine a suitable driver class

    SpringBoot启动报错如下 Error starting ApplicationContext. To display the conditions report re-run your app ...

  6. 计算机网络.{wireshark的使用实验}

    ---恢复内容开始--- 三种选择 1 2 3 端口镜像:交换机的某个端口,接受或者发送的数据给另外一个端口 ARP欺骗: ARP欺骗是利用ARP协议自身的不足进行的欺骗 1 执行ping命令, 2 ...

  7. Python 运算符括号

  8. JQuery--动画队列以及清空队列.stop()方法

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. Inno Setup生成桌面快捷方式

    在做项目的时候,需要打包成exe安装包.先前使用的是vs来打包,生成了setup.exe 和 *.msi的安装文件,不过也算顺利. 后因为要求采取 Inno Setup来打包程序,其中遇到个创建快捷方 ...

  10. springboot项目启动,但是访问报404错误

    启动类Application上加了@ComponentScan(basePackages = {})这个注解导致controller扫描不到导致的,如果加了这个注解,springboot就不会扫描Ap ...