• 【绿书】 模拟,rep大坑


    https://vjudge.net/contest/229603#problem/B

    绿书题

    大模拟,绿书上用了个比较麻烦的输入,其实只要getchar()!='0'就行

    坑:

    rep(i,0,s.length()-1)会wa

    len=s.length()-1后不会。。。

    #define _CRT_SECURE_NO_WARNINGS
    #include<cstring>
    #include<cctype>
    #include<cstdlib>
    #include<iomanip>
    #include<cmath>
    #include<cstdio>
    #include<string>
    #include<cassert>
    #include<stack>
    #include<ctime>
    #include<list>
    #include<set>
    #include<map>
    #include<queue>
    #include<vector>
    #include<sstream>
    #include<fstream>
    #include<iostream>
    #include<functional>
    #include<algorithm>
    #include<memory.h>
    //#define INF 0x3f3f3f3f
    #define eps 1e-6
    #define pi acos(-1.0)
    #define e exp(1.0)
    #define rep(i,t,n)  for(int i =(t);i<=(n);++i)
    #define per(i,n,t)  for(int i =(n);i>=(t);--i)
    #define mp make_pair
    #define pb push_back
    #define mmm(a,b) memset(a,b,sizeof(a))
    //std::ios::sync_with_stdio(false);
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    void smain();
    #define ONLINE_JUDGE
    int main() {
        //ios::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
        FILE *myfile;
        myfile =freopen("C:\Users\SuuTT\Desktop\test\in.txt", "r", stdin);
        if (myfile == NULL)
            fprintf(stdout, "error on input freopen
    ");
        /*FILE *outfile;
        outfile= freopen("C:\Users\SuuTT\Desktop\test\out.txt", "w", stdout);
        if (outfile == NULL)
            fprintf(stdout, "error on output freopen
    ");*/
        long _begin_time = clock();
    #endif
        smain();
    #ifndef ONLINE_JUDGE
        long _end_time = clock();
        printf("time = %ld ms.", _end_time - _begin_time);
    #endif
        return 0;
    }
    int dir[4][2] = { 1,0,0,1,-1,0,0,-1 };
    const int maxn = 3e3 + 5;
    struct point {
        int x, y;
        point(int x = 0, int y = 0) :x(x), y(y) {}
        
    };
    typedef point Vector;
    Vector operator+ (const Vector& A, const Vector& B) { return Vector(A.x + B.x, A.y + B.y); }
    Vector operator- (const point& A, const point& B) { return Vector(A.x - B.x, A.y - B.y); }
    Vector operator* (const Vector& A, int p) { return Vector(A.x*p, A.y*p); }
    Vector operator/ (const Vector& A, int p) { return Vector(A.x / p, A.y / p); }
    bool operator== (const point& a, const point &b) { return a.x == b.x && a.y == b.y; }
    bool operator< (const point& p1, const point& p2) { return p1.x < p2.x || (p1.x == p2.x && p1.y < p2.y); }
    const int Gsize = 5;
    vector<string> grid;
    point ePos;
    map<char, Vector> Dirs;
    bool valid(const point& p) {
        return p.x >= 0 && p.x < Gsize&&p.y >= 0 && p.y < Gsize;
    }
    void  printGrid() {
        for (int i = 0; i < Gsize; i++) {
            rep(j, 0, Gsize - 1) {
                if (j)cout << ' ';
                cout << grid[i][j];
            }
            cout << endl;
        }
    }
    bool tryMove(char cmd) {
        if (!Dirs.count(cmd))return false;
        assert(Dirs.count(cmd));
        point p = ePos + Dirs[cmd];
        if (!valid(p))return false;
        swap(grid[p.x][p.y], grid[ePos.x][ePos.y]);
        ePos = p;
        return true;
    }
    int n; int ans;
    
    void Run(){
        
    }
    
    void smain() {
        int t=1;
        string line;
        Dirs['A'] = Vector(-1, 0); Dirs['B'] = Vector(1, 0); Dirs['L'] = Vector(0, -1); Dirs['R'] = Vector(0, 1);
        while (1) {
            grid.clear();
            ePos.x = -1, ePos.y = -1;
            rep(i, 0, Gsize - 1) {
                getline(cin, line);
                if (line == "Z")return;
                assert(line.size() == Gsize);
                rep(j, 0, Gsize - 1){    
                    if (line[j] != ' ')continue;
                    assert(ePos.x == -1 && ePos.y == -1);
                    ePos.x = i;
                    ePos.y = j;
                }
                grid.push_back(line);
            }
            //char move;
            string moves;
            while (1) {
                getline(cin, line); assert(!line.empty());
                bool end = *(line.rbegin()) == '0';
                if (!end) moves.append(line);
                else moves.append(line, 0, line.size() - 1);
                if (end)break;
            }
            bool legal = 1;
            //int len =;
            //rep(i, 0, moves.size() - 1)if (!tryMove(moves[i])) { legal = false; break; }
            for (const auto& m : moves) if (!tryMove(m)) { legal = false; break; }
            if (t > 1)cout << endl;
            cout << "Puzzle #" << t++ << ":" << endl;//Puzzle #2:
            if (legal) printGrid();
            else cout << "This puzzle has no final configuration." << endl;
        }
        
    }
    /*
    
    TRGSJ
    XDOKI
    M VLN
    WPABE
    UQHCF
    ARRBBL0
    ABCDE
    FGHIJ
    KLMNO
    PQRS 
    TUVWX
    AAA
    LLLL0
    ABCDE
    FGHIJ
    KLMNO
    PQRS 
    TUVWX
    AAAAABBRRRLL0
    Z*/
    成功的路并不拥挤,因为大部分人都在颓(笑)
  • 相关阅读:
    还原 | revert (Cascading & Inheritance)
    过滤器 | filter (Filter Effects)
    过渡时间 | transition-duration (Animations & Transitions)
    过渡延时 | transition-delay (Animations & Transitions)
    过渡属性 | transition-property (Animations & Transitions)
    过渡定时功能 | transition-timing-function (Animations & Transitions)
    过渡 | transition (Animations & Transitions)
    ProxySQL 读写分离
    《抛弃learning rate decay吧!》
    《Tensorflow 中 learning rate decay 的奇技淫巧 》
  • 原文地址:https://www.cnblogs.com/SuuT/p/9051885.html
Copyright © 2020-2023  润新知