题意,给一个两行m列的矩阵,要求遍历每一个点并且每一个点只能遍历一遍,并且每个点在开始的ai,j时间内都会锁住不能访问,要求最短时间

思路:稍加思索就能发现,对于一个只有两行的图来说,只有两种方式能遍历全图,且只访问每一个点一遍,分别是蛇形从小到大按列遍历,和按行遍历。由于该题给出的列数较多,我们按列来看,遍历的方式一定是从按列转向按行的(即使全是蛇形遍历,最后也会有一个竖向的按行遍历过程),因此,我们可以枚举分界点来找到最小值

于是我们发现了一个严酷的问题,如果对于每一个分界点都进行依次按行遍历的话,n^2的复杂度必然会导致超时,于是我们考虑预处理出所有分界点后按行遍历所需要的时间数,然后再枚举分界点。

于是我们发现仍有两种情况1.按行遍历不被卡,为a[i][j]+(n-i)*2或(n-i)*2-1的时间,或者被卡,从大到小按列取a[1-j][i]+1,dp[j][i+1]+1的最大值

最后再枚举分界点的时候需注意终点的列数如果是奇数,那么终点就在第一行,如果是偶数,那就在第二行。因此使用预处理出的按行遍历的dp值时需要注意奇偶。然后就是需要用一个变量记录枚举到i位置时的即使后面不卡也需要的最大时取max

#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<bitset>
#include<cmath>
#include<array>
#include<atomic>
#include<sstream>
#include<stack>
#include<iomanip>
//#include<bits/stdc++.h>//#define int ll
#define pb push_back
#define endl '\n'
#define x first
#define y second
#define Endl endl
#define pre(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,b,a) for(int i=b;i>=a;i--)
#define si(x) scanf("%d", &x);
#define sl(x) scanf("%lld", &x);
#define ss(x) scanf("%s", x);
#define YES {puts("YES");return;}
#define NO {puts("NO"); return;}
#define all(x) x.begin(),x.end()using namespace std;typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<int, PII> PIII;
typedef pair<char, int> PCI;
typedef pair<int, char> PIC;
typedef pair<double, double> PDD;
typedef pair<ll, ll> PLL;
const int N = 1000020, M = 2 * N, B = N, MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };
int n, m, k;
int a[3][N];
int dp[3][N];ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lowbit(ll x) { return x & -x; }
ll qmi(ll a, ll b, ll mod) {ll res = 1;while (b) {if (b & 1) res = res * a % mod;a = a * a % mod;b >>= 1;}return res;
}inline void init() {}void slove()
{cin >> n;pre(i, 1, 2)pre(j, 1, n)cin >> a[i][j];a[1][1] = -1;dp[1][n + 1] = 0;dp[2][n + 1] = 0;rep(i, n, 1)pre(j, 1, 2)dp[j][i] = max(max(a[j][i] + (n - i+1) * 2, a[3 - j][i] + 1), dp[j][i + 1] + 1);int ans = INF, cur = 0;pre(i, 1, n){k = i & 1 ? 1 : 2;ans = min(ans, max(cur,dp[k][i]));cur = max(cur, a[k][i] + (n - i + 1) * 2);cur = max(cur, a[3 - k][i] + (n - i + 1) * 2 - 1);}cout << ans << endl;}signed main()
{int _;si(_);//_ = 1;init();while (_--){slove();}return 0;
}

Codeforces edu C. Robot in a Hallway相关推荐

  1. codeforces 1716 C Robot in a Hallway

    input: 4 3 0 0 1 4 3 2 5 0 4 8 12 16 2 6 10 14 18 4 0 10 10 10 10 10 10 10 2 0 0 0 0 output: 5 19 17 ...

  2. cf Educational Codeforces Round 133 C. Robot in a Hallway

    原题: There is a grid, consisting of 2 rows and m columns. The rows are numbered from 1 to 2 from top ...

  3. C. Robot in a Hallway Educational Codeforces Round 133 (Rated for Div. 2)dp

    dp问题 There is a grid, consisting of 22 rows and mm columns. The rows are numbered from 11 to 22 from ...

  4. 【细节很多的dp】Educational Codeforces Round 133 (Rated for Div. 2) C. Robot in a Hallway

    参考题解 题意: 有一个 2 2 2 行, m m m 列的方格,初始在 ( 1 , 1 ) (1,1) (1,1),每个格子有一个开放时间,开放时间后才能到达,每个格子只能被到达一次,你可以任意选择 ...

  5. Codeforces 583 DIV2 Robot's Task 贪心

    原题链接:http://codeforces.com/problemset/problem/583/B 题意: 就..要打开一个电脑,必须至少先打开其他若干电脑,每次转向有个花费,让你设计一个序列,使 ...

  6. CodeForces - 589J Cleaner Robot

    J. Cleaner Robot time limit per test2 seconds memory limit per test512 megabytes inputstandard input ...

  7. 【Codeforces 922D】Robot Vacuum Cleaner

    [链接] 我是链接,点我呀:) [题意] 让你把n个字符串重新排序,然后按顺序连接在一起 使得这个组成的字符串的"sh"子序列最多 [题解] /** 假设A的情况好于B* 也就对应 ...

  8. CodeForces - 1252K Addition Robot(线段树维护矩阵)

    题目链接:点击查看 题目大意:给出一个只由 A 和 B 组成的字符串 s ,需要完成 m 次操作,每次操作分为两种类型: 1 l r :将 [ l , r ] 内的字符串 A 变成 B,B 变成 A ...

  9. CodeForces 589J Cleaner Robot

    题目链接 题意:一个机器人打扫卫生,URDL代表初始时机器人面对的方向上右下左. ' . ' 代表可以打扫的, ' * ' 代表家具,如果机器人遇到家具就顺时针转90度,问机器人能打扫多少面积. 题解 ...

最新文章

  1. 腾讯3366小游戏站算法被破解
  2. 学习笔记84—[深度学习]神经网络反向传播(BackPropagation)
  3. linux中如何在文件中查找文件,linux下find(文件查找)命令的用法总结
  4. mysql取固定前缀的表_mysql删除指定前缀的表
  5. Spring boot上传文件(图片)到阿里云OSS(直接上传到应用服务器)
  6. iOS的一些小技巧[转]
  7. C标准预定义实用的宏
  8. java连接mysql并在textarea输出_Java面试宝典Java IO篇
  9. 向日葵能自动连接服务器吗,向日葵远程控制是如何设置连接的
  10. 如何在html中加入下划线,文档中加入下划线
  11. 【系】微信小程序云开发实战坚果商城-云开发之分类数据实现
  12. IDEA必用插件 - 变量名中文转英文API注释翻译:Translation
  13. 解决方法:CC2640R2F从7x7改成5x5封装,主机连接失败
  14. 为什么有的域名需要加WWW才能访问?
  15. select2 取值 遍历 设置默认值
  16. 英特尔Thunderbolt(雷电)控制器驱动
  17. BATCH 批处理(一)
  18. 黑客入门常用的8种工具
  19. 如何将html文件发送邮件,怎么给邮件发送HTML
  20. C# 反射 实例化类

热门文章

  1. JS/Jquery常用代码
  2. Games104 Lecture 8 游戏引擎的动画技术基础
  3. UpdateData
  4. fastboot wairting for device fastboot模式下 电脑无法识别
  5. wooyun常见ssrf总结+常见ssrf绕过姿势
  6. 计算机开机主机不停地重启,电脑开机几秒自动重启停不下来,这是怎么回事?...
  7. w10计算机配置在哪,Win10怎么看电脑配置?Win10系统电脑配置查看方法图解
  8. python长整型怎么用_Python整型:布尔型、标准整型、长整型操作实例
  9. 企业网站的搜索引擎优化
  10. SDCC 2016大数据架构峰会·杭州站启航,首批过半讲师和议题公布