当前位置:网站首页>Educational Codeforces Round 133 (Rated for Div. 2) C补题
Educational Codeforces Round 133 (Rated for Div. 2) C补题
2022-08-08 05:42:00 【一条小小yu】
比赛里不会做,感觉两个题都是dp qwq 然后果断放弃去睡大觉。
C题题目链接:
https://codeforces.com/contest/1716/problem/C
定义b[i][j],为从(i,j)出发直走到下面/上面一个格子的需要的时间。
(注意不是途中用了多少时间,而是到达目标点的时间)
转移:
for (int i = 0; i < 2; i++) {
for (int j = n - 1; j >= 0; j--) {
b[i][j] = max({
a[i ^ 1][j] + 1,
a[i][j] + 1 + 2 * (n - j) - 1,
b[i][j + 1] + 1 });
}
}最终代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
const int N=2e5+10;
int t,n;
int a[2][N],b[2][N];
void solve()
{
cin >> n;
for(int i = 0; i < 2; i++)for(int j = 0; j < n; j++) cin >> a[i][j];
a[0][0] = -1;//为了防止后面+1,所以a[0][0] = - 1
b[0][n] = b[1][n] = 0;
for (int i = 0; i < 2; i++)
{
for (int j = n - 1; j >= 0; j--)
{
b[i][j] = max(
{
a[i ^ 1][j] + 1,
a[i][j] + 1 + 2 * (n - j) - 1,
b[i][j + 1] + 1 });
}
}
int ans =INT_MAX;
int cur = 0;
for (int j = 0; j < n; j++)
{
int k = j & 1;
ans = min(ans, max(cur + 2 * (n - j) - 1, b[k][j]));
cur = max(cur, a[k][j] + 1);
cur++;//模拟
cur = max(cur, a[k ^ 1][j] + 1);
cur++;//模拟
}
cout << ans << endl;
}
signed main()
{
cin>>t;
while(t--)
{
solve();
}
return 0;
}
边栏推荐
- [Untitled] I haven't thought of a name yet
- Day7:面试必考选择题
- C语言框架FreeSwitch自定义事件介绍与使用示例
- "Public Administration" exam key points and answers
- Redis设置开机自启动
- 14.Unity2D 横版 粒子系统特效 飙血粒子+高处落地粒子+对象池管理所有粒子
- Web 攻击的日志分析:初学者指南
- 邮件钓鱼上线cobalstrike
- Week 9 10 Neural Networks
- Matlab simulation of photovoltaic mppt maximum power control based on disturbance observation method
猜你喜欢
随机推荐
Day7:面试必考选择题
Checkerboard Coloring Problem
主脑提示( Master-Mind Hints )
"Public Administration" exam key points and answers
76. 最小覆盖子串
邮件钓鱼上线cobalstrike
flex布局缺点
C语言力扣第58题之最后一个单词的长度。从后往前遍历
【leetcode】剑指 Offer(专项突击版)汇总
Style of DataGrid in wpf
TSF Microservice Governance Combat Series (2) - Service Routing
Hard Disk Basics
研发医疗器械产品需要做的测试
C language - score and loop statement
Unity-CharacterController (Character Controller)
automation tool
Tensorboard的使用 ---- SummaryWriter类(pytorch版)
Connect two tables to update the third table (updata) in postgresql
uvm简介
《动机与人格》笔记(二)——认识和理解的欲望









