srm 550

資瓷點此閱讀QvQ

300


Description

有個機器人,從某一點出發,他只有碰到地形邊緣或者碰到走過的點時纔會改變運動方向,然後接着走,現在給出他的運動軌跡,判斷他的運動是否合法,如果合法的話,那麼整個地形的最小面積是多少。每次走的步數50

Solution

先確定最大的最小的x,y ,然後進行驗證,如果走到重複的地方或者不應該轉彎時轉彎則不合法。

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

兩個人在一個無限大的格子裏輪流塗紅藍兩色,第一個人先在(0,0) 塗紅,然後接下來的每一輪,對於所有的點(x,y) ,如果(x1,y1)(x2,y) 一個有另一個人的顏色,一個爲空,那麼就把這個點塗成自己的顏色,問經過t 輪之後,某個區域的染色情況。

Solution

將前幾輪的情況手畫一下,是下圖這個樣子的。。

容易發現只有在yx 這些格子纔會被染色,然後發現按y=x+b 來看,奇數的沒有被染色,偶數的有被染色的。且非常類似楊輝三角,其實楊輝三角奇數項纔會被染色。這裏有個神奇的結論c[n][m](n&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;m)==m ,於是就做完了QvQ

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;
    }
};
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章