Codeforces 1204C
题意略。
思路:我的想法是逐步地找出这个序列中的重要点,我要判断当前这个点能不能删去,就要看上一个重要点和当前这个点 i 在序列中的下一个点 i + 1之间的距离
是否是最短距离,如果是,那么我们就可以化简掉当前这个点(当然,上一个重要点不能和下一个点 i + 1是同一个点)。
还有一种做法是判断三个连续的点,如果第一个点和第三个点之间没有直接的边相连,那么第二个点一定会通过,也就是说会被化简掉。

代码如下:
#include<bits/stdc++.h>
using namespace std;
const int maxn = ;
const int maxn1 = 1e6 + ;
const int F = 0x3f;
const int INF = 0x3f3f3f3f; char graph[maxn][maxn];
int path[maxn1],dp[maxn][maxn],n,m; int main(){
scanf("%d",&n);
for(int i = ;i <= n;++i) scanf("%s",graph[i] + );
for(int i = ;i <= n;++i){
for(int j = ;j <= n;++j){
dp[i][j] = graph[i][j] == '' ? : INF;
}
}
scanf("%d",&m);
for(int i = ;i < m;++i) scanf("%d",&path[i]);
for(int k = ;k <= n;++k){
for(int i = ;i <= n;++i){
for(int j = ;j <= n;++j){
dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j]);
}
}
}
int temp,last = ,cnt = ;
for(int i = ;i < m - ;++i){
int len = (i + ) - last;
if(dp[path[last]][path[i + ]] == len && path[last] != path[i + ]) path[i] = -;
else{
last = i;
++cnt;
}
}
++cnt;
printf("%d\n",cnt);
for(int i = ;i < m;++i){
if(path[i] == -) continue;
printf("%d%c",path[i],i == m - ? '\n' : ' ');
}
return ;
}
Codeforces 1204C的更多相关文章
- codeforces 1204C Anna, Svyatoslav and Maps(floyd+dp)
题目链接:http://codeforces.com/problemset/problem/1204/C 给定一组序列,P1,P2,P3...Pm,这是一组合法路径的序列,即任意的Pi和Pi+1之间有 ...
- [最短路,floyd] Codeforces 1204C Anna, Svyatoslav and Maps
题目:http://codeforces.com/contest/1204/problem/C C. Anna, Svyatoslav and Maps time limit per test 2 s ...
- 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 ...
随机推荐
- ArcGIS API For JavaScript 开发(二)基础地图
有了开发环境,接下来的就是实践了,实践是检验真理的唯一标准! 多多练习,不要觉得自己能够想的出来就万事大吉了,还是得动手做才是最好的检验自己的能力. 基础地图,本节将通过arcgis api for ...
- Docker 工作原理及容器化简易指南
Docker 非常棒! 它使软件开发者无需担心配置和依赖性,在任何地方打包,发送和运行他们的应用程序.而在与 Kubernetes 相结合后,它使应用集群部署和管理变得更方便.这使得 Docker 深 ...
- iframe插入视频自动播放代码
<iframe marginwidth=0 marginheight=0 src='http://www.wsview.com/yzplayerAction!play2.action?autoP ...
- Java--重载与重写的区别
1.重写必须继承,重载不用.2.重写的方法名,参数数目相同,参数类型兼容,重载的方法名相同,参数列表不同.3.重写的方法修饰符大于等于父类的方法,重载和修饰符无关.4.重写不可以抛出父类没有抛出的一般 ...
- 优化 Ubuntu
优化Ubuntu 1. 更换 apt 源 echo 'deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe mul ...
- Centos7 安装Homestead环境2
历史命令, -- :: cd /etc/yum.repos.d/ -- :: wget http://download.virtualbox.org/virtualbox/rpm/rhel/virtu ...
- 《SQL错题》
(选择一项) A: B: C: D: 正确答案是 D (选择一项) A: B: C: D: 正确答案是 A (选择一项) 8 A: B: C: ...
- bean的创建(五)第五部分 属性填充
AbstractAutowireCapableBeanFactory.populateBean protected void populateBean(String beanName, RootBea ...
- python传递参数
1.脚本 # -*- coding: utf-8 -*- from sys import argvscript, first,second = argv #将命令中输入的参数解包后传递给左边 age ...
- .net持续集成测试篇之Nunit常见断言
系列目录 Nunit测试基础之简单断言 在开始本篇之前需要补充一些内容,通过前面搭建Nunit测试环境我们知道要使一个方法成为单元测试方法首先要在此方法所在类加上TestFixture注解,并且在该方 ...