資瓷點此閱讀QvQ
300
Description
有個機器人,從某一點出發,他只有碰到地形邊緣或者碰到走過的點時纔會改變運動方向,然後接着走,現在給出他的運動軌跡,判斷他的運動是否合法,如果合法的話,那麼整個地形的最小面積是多少。每次走的步數
Solution
先確定最大的最小的
Code
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> pii;
int dx[] = {0, -1, 0, 1};
int dy[] = {1, 0, -1, 0};
const int N = 205;
bool vis[N][N];
struct RotatingBot {
int minArea(vector <int> moves) {
int n = moves.size();
int x = 100, y = 100;
int mxx = 100, mxy = 100, mnx = 100, mny = 100;
for (int i = 0; i < n; ++i) {
int dir = i % 4;
int tx = x + dx[dir] * moves[i];
int ty = y + dy[dir] * moves[i];
mxx = max(mxx, tx), mnx = min(mnx, tx);
mxy = max(mxy, ty), mny = min(mny, ty);
x = tx, y = ty;
}
x = 100, y = 100;
vis[x][y] = 1;
if (mxx > 151 || mxy > 151 || mnx < 49|| mxy < 49) return -1;
for (int i = 0; i <= 151; ++i) {
vis[i][mxy + 1] = vis[i][mny - 1] = 1;
vis[mxx + 1][i] = vis[mnx - 1][i] = 1;
}
for (int i = 0; i < n; ++i) {
int dir = i % 4;
for (int j = 0; j < moves[i]; ++j) {
int tx = x + dx[dir];
int ty = y + dy[dir];
if (vis[tx][ty]) return -1;
vis[tx][ty] = 1;
x = tx, y = ty;
}
if (i != n - 1 && !vis[x + dx[dir]][y + dy[dir]]) return -1;
}
return (mxx - mnx + 1) * (mxy - mny + 1);
}
};
500
Description
兩個人在一個無限大的格子裏輪流塗紅藍兩色,第一個人先在
Solution
將前幾輪的情況手畫一下,是下圖這個樣子的。。
容易發現只有在
Code
#include <bits/stdc++.h>//conclusion
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> pii;
struct CheckerExpansion {
vector <string> resultAfter(long long t, long long x0, long long y0, int w, int h) {
vector<string> ans;
for (int i = 0; i < h; ++i) {
string s = "";
for (int j = 0; j < w; ++j) {
LL x = x0 + j;
LL y = y0 + h - i - 1;
if (y > x) {
s += ".";
continue;
}
if ((x + y) % 2 == 0) {
LL n = (x + y) / 2;
LL m = abs(x - n);
if (n >= t) s += ".";
else if ((n & m) == m) { //amazing
if (n & 1) s += "B";
else s += "A";
}
else s += ".";
}
else s += ".";
}
ans.pb(s);
}
return ans;
}
};