(搬运一下部分官方题解)

Description

link

或者洛谷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的更多相关文章

  1. 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 ...

  2. DotNet Run 命令介绍

    前言 本篇主要介绍 asp.net core 中,使用 dotnet tools 运行 dotnet run 之后的系统执行过程. 如果你觉得对你有帮助的话,不妨点个[推荐]. 目录 dotnet r ...

  3. 布里斯班Twilight Bay Run半程马拉松

    自从8月3日跑了半马以后,又一鼓作气报了11月份的西昌马拉松.与第一次马拉松的只求完赛目标不同,第二次当然想取得一个更好的成绩.所以8月份练的比较猛,基本上是练2.3天休息一天,周么还要拉个长于21公 ...

  4. 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 ...

  5. 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 ...

  6. 0040 Java学习笔记-多线程-线程run()方法中的异常

    run()与异常 不管是Threade还是Runnable的run()方法都没有定义抛出异常,也就是说一条线程内部发生的checked异常,必须也只能在内部用try-catch处理掉,不能往外抛,因为 ...

  7. 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 ...

  8. .NET跨平台之旅:探秘 dotnet run 如何运行 .NET Core 应用程序

    自从用 dotnet run 成功运行第一个 "Hello world" .NET Core 应用程序后,一直有个好奇心:dotnet run 究竟是如何运行一个 .NET Cor ...

  9. 【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.原因,工作队列被占用,只需 ...

随机推荐

  1. CNN:卷积输出分辨率计算

    卷积是CNN非常核心的操作,CNN主要就是通过卷积来实现特征提取的,在卷积操作的计算中会设计到几个概念:步长(strides).补充(padding).卷积核(kernel)等,那卷积的输出分辨率计算 ...

  2. 百度网盘下载神器 PanDownload v2.0.9(破解版、不限速)

    一直用这个软件来下载百度网盘的东西,不限速,贼爽.  链接:https://pan.baidu.com/s/1UjF47YWd2v9x52c5sjhutQ 提取码:v9pe 也可以直接到官网下载:ht ...

  3. M内核迎来大BOSS,ARM发布Cortex-M55配NPU Ethos-U55 ,带来无与伦比的性能提升

    说明: 全球顶级嵌入式会展Embedded Word2020这个月底就开了,各路厂家都将拿出看家本领. 先回顾下去年的消息: 1.去年年初的时候ARM发布Armv8.1-M架构,增加了Arm Heli ...

  4. org.springframework.dao.CannotAcquireLockException异常分析

    错误信息如下: 2017-09-27 16:27:16.153 - [com.ldyun.base.service.impl.BaseRetailOrderServiceImpl] - 新增零售商品订 ...

  5. Microsoft SQL server Management Studio工具报错“应用程序的组件中发生了无法处理的异常”

    解决办法 打开目录: C:\Documents and Settings\Administrator\Application Data\Microsoft\Microsoft SQL Server\1 ...

  6. Idea Spring工程不识别注解

    如图所示 Idea工具报出很多注解不识别,开始怀疑是 工具问题,重装Idea.配置lombak都不行,切换分支发现正常,一定是合入代码修改啥了,一行行比对,果然是这行 import org.sprin ...

  7. 苹果下架2.5万赌博APP!一场净化风暴正在迅速成型

    当下智能手机发展得如火如荼,但对于大众来说,体验终究还是要落到包罗万千的APP上.APP身为智能手机的灵魂,全面渗入了大众的工作.生活.娱乐.学习等多个方面.每一个APP的背后,其实都在打开着一扇通往 ...

  8. symmetry methods for differential equations,exercise 1.4

    tex文档: \documentclass[a4paper, 12pt]{article} % Font size (can be 10pt, 11pt or 12pt) and paper size ...

  9. JVM探秘:jmap生成内存堆转储快照

    本系列笔记主要基于<深入理解Java虚拟机:JVM高级特性与最佳实践 第2版>,是这本书的读书笔记. jmap 命令用来生成内存堆转储快照,一般称为heapdump或dump文件. 除了使 ...

  10. ruoyi ShiroUtils

    package com.ruoyi.framework.util; import org.apache.shiro.SecurityUtils; import org.apache.shiro.cry ...