Educational Codeforces Round 84 (Rated for Div. 2) C. Game with Chips

C. Game with Chips

题目链接-C. Game with Chips
在这里插入图片描述
在这里插入图片描述
题目大意
n × m n×m n×m 的网格图上有 k 个棋子,坐标为 ( s x i , s y i sxi,syi sxi,syi) ,每个棋子都有一个对应的必经点坐标 ( f x i , f y i fxi,fyi fxi,fyi) 。现在你有最多 2 n m 2nm 2nm次移动机会,每次移动能够将棋子整体向上下左右四个方向中的一个移动一个单位(如果棋子到达边界将不再移动,棋子可以重叠),给出一种能够让每个棋子到达必经点的方案

解题思路
贪心
因为把整个图遍历一遍也只要 n × m − 1 n×m−1 n×m1次移动,所以可以先把所有点移至一角,然后遍历整个方块,这样一定不会超过 2 m n 2mn 2mn次,且一定能经过每个点
坑点:

  • L (x,y−1); R (x,y+1); D (x+1,y); U (x−1,y)

附上代码

#include<bits/stdc++.h>
#define int long long
#define lowbit(x) (x &(-x))
#define endl '\n'
using namespace std;
const int INF=0x3f3f3f3f;
const int dir[4][2]={-1,0,1,0,0,-1,0,1};
const double PI=acos(-1.0);
const double eps=1e-10;
const int M=1e9+7;
const int N=1e5+5;
typedef long long ll;
typedef pair<int,int> PII;
string s;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);

	
	int n,m,k,x,y;
	cin>>n>>m>>k;
	for(int i=1;i<=(2*k);i++)
		cin>>x>>y;
	s+=string(n-1,'D');
    s+=string(m-1,'R');
	for(int i=1;i<n;i++){
		for(int j=1;j<m;j++){
			if(i&1) s+="R";
			else s+="L";
		}
		cout<<"D";
	}
	for(int j=1;j<m;j++){
		if(n&1) s+="R";
		else s+="L";
	}
	cout<<s.size()<<endl;
	cout<<s<<endl;
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值