2015 多校联赛 ——HDU5402(模拟)
In the next line you should print a string consisting of "L","R","U" and "D", which represents the path you find. If you are in the cell (x,y),
"L" means you walk to cell (x,y−1),
"R" means you walk to cell (x,y+1),
"U" means you walk to cell (x−1,y),
"D" means you walk to cell (x+1,y).
2 3 3
3 3 3
3 3 2
RRDLLDRR
要求从左上角走到右下角的最大值。
如果n,m中有奇数则可以全部走完。否则需要在(i+j-2)%2 == 1的点中选择一个最小值绕过。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MAXN 300005
#define MIN 0
#define MAX 1000001 int main()
{
int n,m;
ll sum;
char ch;
int x;
//freopen("1007.txt","r",stdin);
while(scanf("%d%d",&n,&m) != EOF)
{
sum = 0;
int minx = 100000;
int mini=-1,minj=-1;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
{
scanf("%d",&x);
sum += x;
if((i+j-2)%2)
{
if(x < minx)
{
minx = x;
mini = i;
minj = j;
}
}
}
if(n % 2 || m % 2)
{
printf("%I64d\n",sum);
if(n % 2)
{
for(int k = 1; k <= n; k++)
{
if(k % 2)
ch = 'R';
else
ch = 'L';
for(int i = 1; i <= m-1; i++)
printf("%c",ch);
if(k != n)
printf("D");
} }
else
{
for(int k = 1; k <= m; k++)
{
if(k % 2)
ch = 'D';
else
ch = 'U';
for(int i = 1; i <= n-1; i++)
printf("%c",ch);
if(k != m)
printf("R");
}
}
}
else
{
printf("%I64d\n",sum-minx);
int k=1;
while(1)
{
if(mini%2&&k==mini) break;
if(mini%2==0&&(k+1)==mini) break;
for(int i=2; i<=m; i++)
if(k%2) printf("R");
else printf("L");
printf("D");
k++;
}
if(mini%2)
{
int cx=k;
int cy=1;
while((cy+1)!=minj)
{
printf("DRUR");
cy+=2;
}
printf("DR");
cx++;
cy++;
while(cy!=m)
{
printf("RURD");
cy+=2;
}
k+=2;
}
else
{
int cx=k;
int cy=1;
while(cy!=minj)
{
printf("DRUR");
cy+=2;
}
printf("RD");
cx++;
cy++;
while(cy!=m)
{
printf("RURD");
cy+=2;
}
k+=2;
}
for(int i=k; i<=n; i++)
{
printf("D");
for(int j=2; j<=m; j++)
if(i%2) printf("L");
else printf("R");
}
}
printf("\n");
}
return 0;
}
2015 多校联赛 ——HDU5402(模拟)的更多相关文章
- 2015 多校联赛 ——HDU5319(模拟)
Painter Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Su ...
- 2015 多校联赛 ——HDU5373(模拟)
Problem Description In this problem, we should solve an interesting game. At first, we have an integ ...
- 2015 多校联赛 ——HDU5334(构造)
Virtual Participation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- 2015 多校联赛 ——HDU5302(构造)
Connect the Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 2015 多校联赛 ——HDU5294(最短路,最小切割)
Tricks Device Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- 2015 多校联赛 ——HDU5325(DFS)
Crazy Bobo Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Tota ...
- 2015 多校联赛 ——HDU5316(线段树)
Fantasy magicians usually gain their ability through one of three usual methods: possessing it as an ...
- 2015 多校联赛 ——HDU5323(搜索)
Solve this interesting problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 2015 多校联赛 ——HDU5301(技巧)
Your current task is to make a ground plan for a residential building located in HZXJHS. So you must ...
随机推荐
- Struts2之配置文件中Action的详细配置(续)
承接上一篇 4.处理结果的配置 Action类的实例对象调用某个方法,处理完用户请求之后,将返回一个逻辑视图名的字符串.核心Filter收到返回的逻辑视图名字符串,根据struts.xml中的逻辑视图 ...
- hdu 4553 约会安排
约会安排 http://acm.hdu.edu.cn/showproblem.php?pid=4553 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- datetimepicker.js 使用笔记
1.官网地址 官网传送门 2.属性及使用示例 2.1调用 html: <input type="text" readonly class="date" ...
- 用js 获取url 参数 页面跳转 ? 后的参数
记得之前在原来的公司写过这个东西,但是还是忘记怎么接住参数了,只知道怎么把id传过去! 问了身边的大佬 他首先推荐了我一个链接是别人写好的方法 附上链接地址:http://blog.csdn.net/ ...
- :after/:before使用技巧
伪类:after/:before基本使用 div:before{ content:'';//必须要写,没写则伪元素无效 display:; position:''; ... } //在一个div子元素 ...
- .NET Core/.NET之Stream简介
之前写了一篇C#装饰模式的文章提到了.NET Core的Stream, 所以这里尽量把Stream介绍全点. (都是书上的内容) .NET Core/.NET的Streams 首先需要知道, Syst ...
- php框架中的phalcon框架的安装,及初步认识,从表单提交简单的数据到数据库中
php框架中的phalcon框架的安装,及初步认识,从表单提交简单的数据到数据库中 1.phalcon框架的安装: phalcon框架在windows本地安装可以利用wamp软件,安装之后可以查看对应 ...
- Centos7安装openvpn及客户端配置
1.openvpn介绍 VPN直译就是虚拟专用通道,是提供给企业之间或者个人与公司之间安全数据传输的隧道,使用OpenSSL加密库中的SSLv3/TLSv1协议函数库. 目前OpenVPN能在Sola ...
- 自动化服务部署(一):Linux下安装JDK
自动化测试的主要目的是为了执行回归测试.当然,为了模拟真实的用户操作,一般都是在UAT或者生产环境进行回归测试. 为了尽量避免内网和外网解析对测试结果的影响,将自动化测试服务部署在外网的服务器是比较好 ...
- (java基础)Java输入输出流及文件相关
字节流: 所有的字节输入输出都继承自InputStream和OutputStream,通常用于读取二进制数据,最基本单位为单个字节,如图像和声音.默认不使用缓冲区. FileInputStream和F ...