Codeforces1301D Time to Run
(搬运一下部分官方题解)
Description
或者洛谷link
到时候就有中文翻译了,不过这个题机翻没毛病
Solution
首先这是一道模拟题……
不要管题目中的循环移动的问题,直接按照怎么着走能走最长
其实比较直观的就是一直走到右边,然后向下,再到左边……
到最低行最后一个的时候就原路返回(我比赛的时候真么想的)
但是我们就忽略掉了纵着来的路径
所以我们在非首行中应该把上下的路径补掉
就是把 \((L/R)\) 改成 \(UD(L/R)\)
然后还得每一行进行原路返回(就是每一次都从最左边进入下一行)
如果所有的这些路径个数加起来都不够,就 \(puts("NO")\)
这个题细节还是比较多……
Code
#include<bits/stdc++.h>
using namespace std;
#define int long long
namespace yspm{
inline int read()
{
int res=0,f=1; char k;
while(!isdigit(k=getchar())) if(k=='-') f=-1;
while(isdigit(k)) res=res*10+k-'0',k=getchar();
return res*f;
}
const int N=1e5+10;
vector<pair<int,string> > vec1,vec2;
int n,m,k,sum,now; string tmp;
inline void fix(vector<pair<int,string> >&vec)
{
vec2=vec; vec.clear(); int sz=vec2.size();
for(int i=0;i<sz;++i) if(vec2[i].first) vec.push_back(vec2[i]); return ;
}
signed main()
{
n=read(); m=read(); k=read();
for(int i=1;i<=n;++i)
{
vec1.push_back(make_pair(m-1,"R"));
if(i==1) vec1.push_back(make_pair(m-1,"L"));
else vec1.push_back(make_pair(m-1,"UDL"));
if(i==n) vec1.push_back(make_pair(n-1,"U"));
else vec1.push_back(make_pair(1,"D"));
}
int sz=vec1.size(); for(int i=0;i<sz;++i){sum+=vec1[i].first*vec1[i].second.size();}
if(sum<k) return puts("NO"),0;
while(sum>k)
{
tmp=vec1.back().second; now=vec1.back().first*vec1.back().second.size();
vec1.pop_back(); sum-=now;
if(sum>=k) continue; now=k-sum;
if(now/tmp.size()>0) vec1.push_back(make_pair(now/tmp.size(),tmp));
tmp.resize(now%tmp.size());
if(tmp.size()>0) vec1.push_back(make_pair(1,tmp));
sum=k;
} puts("YES"); fix(vec1);
sz=vec1.size(); printf("%lld\n",sz);
for(int i=0;i<sz;++i) printf("%lld %s\n",vec1[i].first,vec1[i].second.c_str());
return 0;
}
}
signed main(){return yspm::main();}
Codeforces1301D Time to Run的更多相关文章
- can't run roscore 并且 sudo 指令返回 unable to resolve host
I'm using ubuntu14 LTS. Problems: 1. When run roscore, got a mistake and an advice to ping the local ...
- DotNet Run 命令介绍
前言 本篇主要介绍 asp.net core 中,使用 dotnet tools 运行 dotnet run 之后的系统执行过程. 如果你觉得对你有帮助的话,不妨点个[推荐]. 目录 dotnet r ...
- 布里斯班Twilight Bay Run半程马拉松
自从8月3日跑了半马以后,又一鼓作气报了11月份的西昌马拉松.与第一次马拉松的只求完赛目标不同,第二次当然想取得一个更好的成绩.所以8月份练的比较猛,基本上是练2.3天休息一天,周么还要拉个长于21公 ...
- SVN:Previous operation has not finished; run 'cleanup' if it was interrupted
异常处理汇总-开发工具 http://www.cnblogs.com/dunitian/p/4522988.html cleanup failed to process the following ...
- linux 环境下运行STS时 出现must be available in order to run STS
linux 环境下运行ECLIPSE时 出现 “ A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be avai ...
- 0040 Java学习笔记-多线程-线程run()方法中的异常
run()与异常 不管是Threade还是Runnable的run()方法都没有定义抛出异常,也就是说一条线程内部发生的checked异常,必须也只能在内部用try-catch处理掉,不能往外抛,因为 ...
- jBPM4.4 no jBPM DB schema: no JBPM4_EXECUTION table. Run the create.jbpm.schema target first in the install tool.
jBPM4.4 no jBPM DB schema: no JBPM4_EXECUTION table. Run the create.jbpm.schema target first in the ...
- .NET跨平台之旅:探秘 dotnet run 如何运行 .NET Core 应用程序
自从用 dotnet run 成功运行第一个 "Hello world" .NET Core 应用程序后,一直有个好奇心:dotnet run 究竟是如何运行一个 .NET Cor ...
- 【svn】在提交文件是报错:previous operation has not finished;run 'cleanup' if it was interrupted
1.svn在提交文件是报错:previous operation has not finished;run 'cleanup' if it was interrupted2.原因,工作队列被占用,只需 ...
随机推荐
- 18 12 2 数据库 sql 的增删改查
---恢复内容开始--- 1 开始进入MySQL 的安装 https://www.cnblogs.com/ayyl/p/5978418.html 膜拜大神的博客 2 默认安装的时候 m ...
- SpringCloud学习之Stream消息驱动【自定义通道】(十一)
如果不清楚本篇内容的,请务必先去看完上一篇再看本篇,否则阅读起来可能会有部分障碍和困难: 上一篇文章<SpringCloud学习之Stream消息驱动[默认通道](十)>我们简单用自定义通 ...
- js正则 -180 到180 小数点后无限位
正则 -180 到180 小数点后无限位/^0$|^-?0\.\d*[1-9]$|^-?[1-9](\.\d*[1-9])?$|^-?[1-9]\d(\.\d*[1-9])?$|^-?1[0-7]\d ...
- delphi内嵌汇编
{ 前面知道了一个汇编的赋值指令(MOV), 再了解一个加法指令(ADD), 就可以做个例子了. 譬如: ADD AX,BX; 这相当于 Delphi 中的 AX := AX + BX; 另外提前来个 ...
- PAT Advanced 1053 Path of Equal Weight (30) [树的遍历]
题目 Given a non-empty tree with root R, and with weight Wi assigned to each tree node Ti. The weight ...
- tensorflow 分布式训练
TF实现分布式流程 1.创建集群 ClusterSpec & Server cluster = tf.train.ClusterSpec({"ps": ps_hosts, ...
- [CISCN2019 华北赛区 Day2 Web1]Hack World
知识点:题目已经告知列名和表明为flag,接下来利用ascii和substr函数即可进行bool盲注 eg: id=(ascii(substr((select(flag)from(flag)),1,1 ...
- 面试准备 css 书写顺序及原理
书写顺序 (1)定位属性:position display float left top right bottom overflow clear z-index (2)自身属性: ...
- 用Axure画原型图有感
感觉前端做UE非常有优势啊- 但是在制作的时候,似乎陷入了误区: (1)只求原型图的漂亮,色彩丰富,忽略了其本质作用,是用来整理逻辑,画出逻辑流程的. (2)一开始就追求交互,高保真的原型,忽视了细节 ...
- Luogu P3031 高于中位数
定义序列\(x_i = f([H_i >=x])\;\;\;\;其中f(0) = -1,f(1) = 1\),那么区间[i,j]满足条件当且仅当sum_j-sum_{i-1} > 0,即s ...