C. Game with Chips
Posted dealer
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C. Game with Chips相关的知识,希望对你有一定的参考价值。
Petya has a rectangular Board of size n×mn×m. Initially, kk chips are placed on the board, ii-th chip is located in the cell at the intersection of sxisxi-th row and syisyi-th column.
In one action, Petya can move all the chips to the left, right, down or up by 11 cell.
If the chip was in the (x,y)(x,y) cell, then after the operation:
- left, its coordinates will be (x,y−1)(x,y−1);
- right, its coordinates will be (x,y+1)(x,y+1);
- down, its coordinates will be (x+1,y)(x+1,y);
- up, its coordinates will be (x−1,y)(x−1,y).
If the chip is located by the wall of the board, and the action chosen by Petya moves it towards the wall, then the chip remains in its current position.
Note that several chips can be located in the same cell.
For each chip, Petya chose the position which it should visit. Note that it‘s not necessary for a chip to end up in this position.
Since Petya does not have a lot of free time, he is ready to do no more than 2nm2nm actions.
You have to find out what actions Petya should do so that each chip visits the position that Petya selected for it at least once. Or determine that it is not possible to do this in 2nm2nm actions.
The first line contains three integers n,m,kn,m,k (1≤n,m,k≤2001≤n,m,k≤200) — the number of rows and columns of the board and the number of chips, respectively.
The next kk lines contains two integers each sxi,syisxi,syi (1≤sxi≤n,1≤syi≤m1≤sxi≤n,1≤syi≤m) — the starting position of the ii-th chip.
The next kk lines contains two integers each fxi,fyifxi,fyi (1≤fxi≤n,1≤fyi≤m1≤fxi≤n,1≤fyi≤m) — the position that the ii-chip should visit at least once.
In the first line print the number of operations so that each chip visits the position that Petya selected for it at least once.
In the second line output the sequence of operations. To indicate operations left, right, down, and up, use the characters L,R,D,UL,R,D,U respectively.
If the required sequence does not exist, print -1 in the single line.
3 3 2 1 2 2 1 3 3 3 2
3 DRD
5 4 3 3 4 3 1 3 3 5 3 1 3 1 4
9 DDLUUUURR
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <set> #include <queue> #include <map> #include <sstream> #include <cstdio> #include <cstring> #include <numeric> #include <cmath> #include <iomanip> #include <deque> #include <bitset> //#include <unordered_set> //#include <unordered_map> //#include <bits/stdc++.h> //#include <xfunctional> #define ll long long #define PII pair<int, int> using namespace std; int dir[5][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } ,{ 0,0 } }; const long long INF = 0x7f7f7f7f7f7f7f7f; const int inf = 0x3f3f3f3f; const double pi = 3.14159265358979; const int mod = 1e9 + 7; const int maxn = 2005; //if(x<0 || x>=r || y<0 || y>=c) //1000000000000000000 inline ll read() { ll x = 0; bool f = true; char c = getchar(); while (c < ‘0‘ || c > ‘9‘) { if (c == ‘-‘) f = false; c = getchar(); } while (c >= ‘0‘ && c <= ‘9‘) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); return f ? x : -x; } int main() { int n, m, k; cin >> n >> m >> k; string res=""; for (int i = 1; i < n; i++) res += ‘U‘; for (int i = 1; i < m; i++) res += ‘L‘; for (int i = 0; i < n; i++) { for (int j = 1; j < m; j++) { if (i % 2 == 0) res += ‘R‘; else res += ‘L‘; } if (i != n - 1) res += ‘D‘; } cout << res.size() << endl; cout << res << endl; return 0; }
以上是关于C. Game with Chips的主要内容,如果未能解决你的问题,请参考以下文章
Educational Codeforces Round 84 (Rated for Div. 2) C. Game with Chips(思维题)
C - Game with Chips.Educational Codeforces Round 84 (Rated for Div. 2)