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\n");
/*FILE *outfile;
outfile= freopen("C:\\Users\\SuuTT\\Desktop\\test\\out.txt", "w", stdout);
if (outfile == NULL)
fprintf(stdout, "error on output freopen\n");*/
long _begin_time = clock();
#endif
smain();
#ifndef ONLINE_JUDGE
long _end_time = clock();
printf("time = %ld ms.", _end_time - _begin_time);
#endif
return ;
}
int dir[][] = { ,,,,-,,,- };
const int maxn = 3e3 + ;
struct point {
int x, y;
point(int x = , int y = ) :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 = ;
vector<string> grid;
point ePos;
map<char, Vector> Dirs;
bool valid(const point& p) {
return p.x >= && p.x < Gsize&&p.y >= && p.y < Gsize;
}
void printGrid() {
for (int i = ; i < Gsize; i++) {
rep(j, , Gsize - ) {
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=;
string line;
Dirs['A'] = Vector(-, ); Dirs['B'] = Vector(, ); Dirs['L'] = Vector(, -); Dirs['R'] = Vector(, );
while () {
grid.clear();
ePos.x = -, ePos.y = -;
rep(i, , Gsize - ) {
getline(cin, line);
if (line == "Z")return;
assert(line.size() == Gsize);
rep(j, , Gsize - ){
if (line[j] != ' ')continue;
assert(ePos.x == - && ePos.y == -);
ePos.x = i;
ePos.y = j;
}
grid.push_back(line);
}
//char move;
string moves;
while () {
getline(cin, line); assert(!line.empty());
bool end = *(line.rbegin()) == '';
if (!end) moves.append(line);
else moves.append(line, , line.size() - );
if (end)break;
}
bool legal = ;
//int len =;
//rep(i, , moves.size() - )if (!tryMove(moves[i])) { legal = false; break; }
for (const auto& m : moves) if (!tryMove(m)) { legal = false; break; }
if (t > )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*/

【绿书】 模拟,rep大坑的更多相关文章

  1. 绿书模拟day10 单词前缀

    [题目描述]一组单词是安全的,当且仅当不存在一个单词是另一个单词的前缀,这样才能保证数据不容易被误解,现在你手上有一个单词集合s,你需要计算有多少个自己是安全的.注意空集永远是安全的.[输入格式]第一 ...

  2. PMP模拟错题总结

    本打算15天完成第二轮复习的,结果项目太忙,拖成了25天.第二轮主要以小绿书为主,就是如下这本 怎么说呢,题目偏向于考ITTO的内容,情景题比较少.可以使用“管理圈”APP作为补充 1.敏感性分析的结 ...

  3. 我的CS考研路

    说在前面 从去年7月15号正式准备考研以来,直到今天,3月19号,一共经历8个多月,考研初步告捷,在此想跟大家分享一下自己的经验,希望能对接下来考研的学弟学妹们有所帮助. 首先介绍下我自己的情况,本科 ...

  4. 帮初学者改代码——有多少青春可以挥霍之“c语言 多重排序”

    原文:“c语言 多重排序” 原代码: #include<stdio.h> #include<string.h> struct A { char name[100]; int g ...

  5. C#轻型ORM框架PetaPoco试水

    近端时间从推酷app上了解到C#轻微型的ORM框架--PetaPoco.从github Dapper 开源项目可以看到PetaPoco排第四 以下是网友根据官方介绍翻译,这里贴出来. PetaPoco ...

  6. Dumb Bones UVA - 10529[多米诺重构]

    Dumb Bones UVA - 10529   来自绿书p176  题意 你试图把一些多米诺骨牌排成直线,然后推倒它们.但是如果你在放骨牌的时候不小心把刚放的骨牌碰倒了,它就会把相临的一串骨牌全都碰 ...

  7. 【UVa】12118 Inspector's Dilemma(欧拉道路)

    题目 题目     分析 很巧秒的一道题目,对着绿书瞎yy一会. 联一下必须要走的几条边,然后会形成几个联通分量,统计里面度数为奇数的点,最后再减去2再除以2.这样不断相加的和加上e再乘以t就是答案, ...

  8. ORM之PetaPoco

    近端时间从推酷app上了解到C#轻微型的ORM框架--PetaPoco.从github Dapper 开源项目可以看到PetaPoco排第四 以下是网友根据官方介绍翻译,这里贴出来. PetaPoco ...

  9. 【紫书】【重要】Abbott's Revenge UVA - 816 bfs 复杂模拟 带方向参数的迷宫

    题意:一个迷宫,每个交叉路口有一路标,限制了你从某方向进入该路口所能进入的路口. 题解:1.对于方向的处理:将node多增加一维dir,通过一个const 字符数组 加 上dir_id函数 以及一个方 ...

随机推荐

  1. Apache Spark 2.2.0 新特性详细介绍

    本章内容: 待整理 参考文献: Apache Spark 2.2.0新特性详细介绍 Introducing Apache Spark 2.2

  2. Git教程学习(三)

    主要命令: $ git checkout -- readme.txt #使用暂存区或版本库中最新的版本替换工作区版本 $ git reset HEAD readme.txt # 撤消指定文件的add操 ...

  3. 图解ByteBuffer

    https://www.cnblogs.com/ruber/p/6857159.html https://www.e-learn.cn/content/qita/750752 https://blog ...

  4. 解决百度云推送通知,不显示默认Notification

    问题:百度云推送通知,不显示默认Notification 描述:采用推送消息的方式,可以在onMessage方法里面获取到推送的消息.另外推送通知也有获取到内容,后台日志也有show private ...

  5. centos 7 配置tomcat开机启动

    1. tomcat 需要增加一个pid文件 在tomca/bin 目录下面,增加 setenv.sh 配置,catalina.sh启动的时候会调用,同时配置java内存参数. #add tomcat ...

  6. tomcat启动时非常慢,启动时 一直卡在Root WebApplicationContext: initialization completed

    每次重启自己的服务tomcat都需要卡住很长时间,每次都是日志停在 Root WebApplicationContext: initialization completed in 744 ms这个地方 ...

  7. Git 重命名操作

    截至目前,Tome 和Jerry 都使用手动命令来编译自己的项目.Jerry 决定为他们的项目创建 Makefile,并给予适当的名称来命名“string.c” 文件. [jerry@CentOS p ...

  8. Java JPA小记

    什么是JPA JPA之于ORM(持久层框架,如MyBatis.Hibernate等)正如JDBC之于数据库驱动. JDBC是Java语言定义的一套标准,规范了客户端程序访问关系数据库(如MySQL.O ...

  9. CAP原理中的一致性

    CAP原理指的是,这三个要素最多只能同时实现两点,不可能三者兼顾.因此在进行分布式架构设计时,必须做出取舍.而对于分布式数据系统,分区容忍性是基本要求,否则就失去了价值.因此设计分布式数据系统,就是在 ...

  10. 嵌入式开发之UDP 丢包--- UDP 丢包控制方法

    0. 发送端可以,发送五次左右,再Sleep 1.调用recv方法接收端收到数据后,处理数据花了一些时间,处理完后再次调用recv方法,在这二次调用间隔里,发过来的包可能丢失.对于这种情况可以修改接收 ...