AOJ1024 Cleaning Robot 2.0

先说一说这个OJ:貌似是11区某大学ACM的OJ,叫AIZU ONLINE JUDGE,貌似还可以看到部分犇的代码。。。跪跪跪

然后知道这个OJ是某场比赛安利的= =

接下来将做法:

首先我们可以发现每个点周围两种颜色的个数都是2...(不要问我为什么)

然后可以发现,构成图形是由2 * 2的同色的地砖或者围成一圈的同色地砖且每边的长度都是偶数,详见样例(不要问我为什么,因为很重要所以说两遍)

接着可以发现,如果第一行的状态确定了,整个解就确定了,而且第一行的状态可以做到和k一一对应(不要问我为什么,因为很重要所以说三遍)

然后就可以直接进行构造了。。。

对于一个点(x, y),它上面的点(x, y - 1)的周围另外三个点的颜色都已经确定了,故也可以将它的颜色确定

 1 #include <cstdio>
 2 #include <cstring>
 3
 4 using namespace std;
 5 typedef long long ll;
 6 const int N = 100;
 7 const int dx[] = {1, -1, 0, 0};
 8 const int dy[] = {0, 0, 1, -1};
 9
10 int n;
11 ll K;
12 int mp[N][N];
13
14 inline bool out (int x) {
15     return x <= 0 || x > n;
16 }
17
18 #define X i + dx[k]
19 #define Y j + dy[k]
20 int main() {
21     int i, j, k, cnt;
22     while (scanf("%d%lld", &n, &K), n) {
23         --K;
24         if (K >= (1ll << (n / 2)) || (n & 1)) {
25             puts("No");
26             putchar(‘\n‘);
27             continue;
28         }
29         memset(mp, -1, sizeof(mp));
30         for (i = 1; i <= n; ++i)
31             mp[1][i] = ((K >> (n - i >> 1)) & 1);
32         for (i = 1; i < n; ++i)
33             for (j = 1; j <= n; ++j) {
34                 for (k = cnt = 0; k < 4; ++k) {
35                     if (out(X) || out(Y)) continue;
36                     if (mp[X][Y] == mp[i][j]) ++cnt;
37                 }
38                 if (cnt == 2) mp[i + 1][j] = !mp[i][j];
39                 else mp[i + 1][j] = mp[i][j];
40             }
41         for (i = 1; i <= n; ++i) {
42             for (j = 1; j <= n; ++j)
43                 putchar(mp[i][j] ? ‘E‘ : ‘.‘);
44             putchar(‘\n‘);
45         }
46         putchar(‘\n‘);
47     }
48     return 0;
49 }

时间: 2024-10-12 20:06:27

AOJ1024 Cleaning Robot 2.0的相关文章

POJ - 2688 Cleaning Robot

题意:求回收所有垃圾的最短路 思路:先BFS处理两个垃圾的距离,然后DFS记忆化搜索 dp[i][state]表示处理到第i个后状态是state的最短路 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <queue> using namespace std; const int

poj 2688 Cleaning Robot (tsp问题)

Cleaning Robot Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4073   Accepted: 1659 Description Here, we want to solve path planning for a mobile robot cleaning a rectangular room floor with furniture. Consider the room floor paved with

poj 2688 cleaning robot(bfs+dfs)

Description Here, we want to solve path planning for a mobile robot cleaning a rectangular room floor with furniture. Consider the room floor paved with square tiles whose size fits the cleaning robot (1 * 1). There are 'clean tiles' and 'dirty tiles

Cleaning Robot POJ - 2688

题目链接:https://vjudge.net/problem/POJ-2688 题意:在一个地面上,有一个扫地机器人,有一些障碍物,有一些脏的地砖,问,机器热能不能清扫所有的地砖, (机器人不能越过障碍物),如果能,需要得到机器人移动最少步数. 思路:可以把扫地机器人和地砖编号,然后得出编号之间的相互距离,那么就变成了一个图问题. 用bfs来得出编号之间的距离. 再用dfs来填边,得到最少移动步数,注意要剪支,不然就T了... 1 #include <iostream> 2 #include

POJ 1573 &amp; POJ 2632(两道有趣的Robot)

题目链接:POJ 1573 Robot Motion & POJ 2632 Crashing Robots [题意]题意就不说了,有兴趣从链接点进去看吧,就是机器人各种打扫房间,行驶指令. [思路]2632是一道纯模拟题,只要把题意读懂,就可以用代码模拟过程,只是写起来有点蛋疼,代码力还是欠缺啊.而1573感觉挺新奇的,我用的DFS来模拟,好久没有写DFS,一开始又把dir数组写错了,结果总是得出0. 下面贴代码,先是2632的AC代码: 1 /* 2 ** POJ 2632 Crashing

Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot 【二分 + 尺取】

任意门:http://codeforces.com/contest/1073/problem/C C. Vasya and Robot time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has got a robot which is situated on an infinite Cartesian plane, i

CodeForce Educational round Div2 C - Vasya and Robot

C. Vasya and Robot time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell (0,0)(0,0). Robot can perfor

489. Robot Room Cleaner - Hard

Given a robot cleaner in a room modeled as a grid. Each cell in the grid can be empty or blocked. The robot cleaner with 4 given APIs can move forward, turn left or turn right. Each turn it made is 90 degrees. When it tries to move into a blocked cel

Leetcode: Robot Room Cleaner

Given a robot cleaner in a room modeled as a grid. Each cell in the grid can be empty or blocked. The robot cleaner with 4 given APIs can move forward, turn left or turn right. Each turn it made is 90 degrees. When it tries to move into a blocked cel