题意
略。
思路
比赛的时候其实已经意识到是一个构造题了。
蓝儿m,n都是偶数的时候搞崩了。sad。。
m,n有一个是奇数不说了,可以走完所有。
两个都是偶数的时候,我们就去找一个最小的值且它的位置坐标和是奇数,然后就绕开这个走。其他都可以走完辣。
参考code:
/*
#pragma warning (disable: 4786)
#pragma comment (linker, "/STACK:0x800000")
*/
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iterator>
#include <utility>
using namespace std;
template< class T > T _abs(T n)
{
return (n < 0 ? -n : n);
}
template< class T > T _max(T a, T b)
{
return (!(a < b) ? a : b);
}
template< class T > T _min(T a, T b)
{
return (a < b ? a : b);
}
template< class T > T sq(T x)
{
return x * x;
}
template< class T > T gcd(T a, T b)
{
return (b != 0 ? gcd<T>(b, a%b) : a);
}
template< class T > T lcm(T a, T b)
{
return (a / gcd<T>(a, b) * b);
}
template< class T > bool inside(T a, T b, T c)
{
return a<=b && b<=c;
}
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define F(i, n) for(int (i)=0;(i)<(n);++(i))
#define rep(i, s, t) for(int (i)=(s);(i)<=(t);++(i))
#define urep(i, s, t) for(int (i)=(s);(i)>=(t);--(i))
#define repok(i, s, t, o) for(int (i)=(s);(i)<=(t) && (o);++(i))
#define MEM0(addr) memset((addr), 0, sizeof((addr)))
#define MP(x, y) make_pair(x, y)
#define REV(s, e) reverse(s, e)
#define SET(p) memset(pair, -1, sizeof(p))
#define CLR(p) memset(p, 0, sizeof(p))
#define MEM(p, v) memset(p, v, sizeof(p))
#define CPY(d, s) memcpy(d, s, sizeof(s))
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define SZ(c) (int)c.size()
#define PB(x) push_back(x)
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pii pair< int, int >
#define psi pair< string, int >
#define ls u << 1
#define rs u << 1 | 1
#define lson l, mid, u << 1
#define rson mid, r, u << 1 | 1
#define debug(x) cout << #x << " = " << x << endl
const int N = 110, M = 510;
const double PI = acos(-1.0);
const int maxn = 110;
const int maxm = maxn * maxn;
const int inf = 1 << 29;
const ll mod = 3221225473;
const double eps = 1e-10;
ll t,m,n,a[maxn][maxn],sum,x,y;
void get(){
x = 1;y = 2;
rep(i,1,n){
rep(j,1,m){
if( ((i + j) & 1) && a[x][y] > a[i][j]) x = i,y = j;
}
}
}
int main(){
READ("in.txt");
while(scanf("%lld%lld",&n,&m)!=EOF){
sum = 0;
rep(i,1,n){
rep(j,1,m){
scanf("%lld",&a[i][j]);
sum += a[i][j];
}
}
if(n & 1 || m & 1){
printf("%lld\n", sum);
if(n & 1){
rep(i,1,n){
rep(j,1,m-1){
if(i & 1) printf("R"); else printf("L");
}
if(i < n) printf("D"); else printf("\n");
}
}else{
rep(i,1,m){
rep(j,1,n-1){
if(i & 1) printf("D"); else printf("U");
}
if(i < m) printf("R"); else printf("\n");
}
}
}else{
get();
printf("%lld\n",sum - a[x][y]);
for(int i = 1; i <= n ;i += 2){
if(x == i || x == i + 1){
rep(j,1,y-1){
if(j & 1) printf("D"); else printf("U");
printf("R");
}
if(y < m) printf("R");
rep(j,y+1,m){
if(j & 1 )printf("U"); else printf("D");
if(j < m) printf("R");
}
if(i < n - 1) printf("D");
}else if( i < x ){
rep(j,1,m-1) printf("R");
printf("D");
rep(j,1,m-1) printf("L");
printf("D");
}else{
rep(j,1,m-1) printf("L");
printf("D");
rep(j,1,m-1) printf("R");
if(i < n - 1) printf("D");
}
}
printf("\n");
}
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-26 05:18:43