codeforces 1214
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的更多相关文章
- codeforces -1214 E
题目https://codeforces.com/problemset/problem/1214/E 就是得知奇数之间不产生影响,先造出一条链,再用偶数往里插就行.链要di从大到小排个序呀!! #in ...
- Codeforces 1214 F G H 补题记录
翻开以前打的 #583,水平不够场上只过了五题.最近来补一下题,来记录我sb的调试过程. 估计我这个水平现场也过不了,因为前面的题已经zz调了好久-- F:就是给你环上一些点,两两配对求距离最小值. ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
随机推荐
- laravel-admin 安装(总结)
https://www.jianshu.com/p/844b05e4c45a laravel-admin 是一个可以快速帮你构建后台管理的工具,它提供的页面组件和表单元素等功能,能帮助你使用很少的代码 ...
- Kibana将语言设置为中文
6.7以后系统开始支持中文了,修改语言只需要添加一行配置即可. 设置方法 在kibana.yml配置文件中添加一行配置 i18n.locale: "zh-CN" 修改后重启,可以看 ...
- 数据库----ORACLE和MYSQL数据库简介
一.什么是数据库? 数据库(Database---DB)按照组织.储存和管理数据的仓库.(理解以下三个概念) 数据(Data)用来描述事物的记录都可称数据,如文字音乐图像. 数据库系统(Dat ...
- 使用FastJson对实体类和Json还有JSONObject之间的转换
1. 实体类或集合转JSON串 String jsonString = JSONObject.toJSONString(实体类); 2.JSON串转JSONObject JSONObject json ...
- Eslint报错的翻译
若在git中出现这个 http://eslint.org/docs/rules/eol-last 他是提醒你:在文件末尾要求或禁止换行 比如代码如下: 若在git中出现这个 https://eslin ...
- 外贸电子商务网站之Prestashop修改顶部导航
如修改以上所示顶部导航. 如何在prestashop顶部导航栏添加链接,Module>Top horizontal menu点击进入Configure页面 1,在Settings 中看到 链接 ...
- CMake学习笔记六-引用cmake文件
include(${CMAKE_CURRENT_SOURCE_DIR}/../Share/share.cmake)
- php表单传值--GET和POST
一. 传值 1. 传值/接收方法: 1) GET(5种方式!) a) 表单Form: method = ‘get’ GET接收数据方式: b) ...
- BOM的对象总结(location,screen,navigator,history)
location对象 专门保存当前窗口正在打开的url的对象. 常用的属性有: location.href 保存了完整的url:这种方式做常用 在当前窗口打开: location.href=新url ...
- LintCode_167 链表求和
题目 你有两个用链表代表的整数,其中每个节点包含一个数字.数字存储按照在原来整数中相反的顺序,使得第一个数字位于链表的开头.写出一个函数将两个整数相加,用链表形式返回和. 样例 给出两个链表 3-&g ...