zoukankan      html  css  js  c++  java
  • 【绿书】 模拟,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*/
    成功的路并不拥挤,因为大部分人都在颓(笑)
  • 相关阅读:
    c:forTokens标签循环输出
    jsp转long类型为date,并且格式化
    spring中@Param和mybatis中@Param使用区别(暂时还没接触)
    734. Sentence Similarity 有字典数组的相似句子
    246. Strobogrammatic Number 上下对称的数字
    720. Longest Word in Dictionary 能连续拼接出来的最长单词
    599. Minimum Index Sum of Two Lists两个餐厅列表的索引和最小
    594. Longest Harmonious Subsequence强制差距为1的最长连续
    645. Set Mismatch挑出不匹配的元素和应该真正存在的元素
    409. Longest Palindrome 最长对称串
  • 原文地址:https://www.cnblogs.com/SuuT/p/9051885.html
Copyright © 2011-2022 走看看