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.原因,工作队列被占用,只需 ...
随机推荐
- halcoN GPU
halcon18.11——DL http://www.ihalcon.com/read-11150.html 楼主# 更多发布于:2018-12-04 19:50 1. 按顺序下载安装 h ...
- 杂点-shell
使用while循环读取文件 cat file.txt |while read line do echo $line done 或者: while read line do echo $line don ...
- (函数)P1149 火柴棒等式
题解: #include<stdio.h>int a[10]={6,2,5,5,4,5,6,3,7,6};int num(int n){ ...
- 寒假day09
今天看了论文的结构,定下了毕设论文的框架,刷了剑指offer的部分算法题.
- 201503-1 图像旋转 Java
思路: 观察输入和输出可以发现,第三列输出为第一行,第二列输出为第二行,第一列输出为第三行.循环即可 import java.util.Scanner; //得分80,本题最高需要输入100W次,因为 ...
- PAT甲级——1153.Decode Registration Card of PAT(25分)
A registration card number of PAT consists of 4 parts: the 1st letter represents the test level, nam ...
- 面试必问之http以及浏览器相关知识
/** 1.HTTP以及HTTPS概念 HTTP是超文本传输协议,是一个用于传输超媒体文档的应用层协议,被用于在web浏览器和网站服务器之间,以明文方式传递信息, 不提供任何方式的饿数据加密,因此使用 ...
- oracle 学习(四)游标
显式游标 隐式游标:如果在PL/SQL程序段中使用SELECT语句进行操作,PL/SQL 会隐含的处理游标定义,即为隐式游标.这种游标不需要像显式那样声明,也不必打开关闭. CREATE OR REP ...
- Linux-sys文件系统
1.sys文件系统本质上和proc文件系统是一样的,都是虚拟文件系统.都在根目录下有个目录(一个是/proc目录,另一个是/sys目录),因此都不是硬盘中的文件,都是内核中的数据结构的可视化接口. 2 ...
- c指针(1)
#include<stdio.h> void swap(int *a,int *b); void dummy_swap(int *a,int *b); int main() { ,d=; ...