【绿书】 模拟,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\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大坑的更多相关文章
- 绿书模拟day10 单词前缀
[题目描述]一组单词是安全的,当且仅当不存在一个单词是另一个单词的前缀,这样才能保证数据不容易被误解,现在你手上有一个单词集合s,你需要计算有多少个自己是安全的.注意空集永远是安全的.[输入格式]第一 ...
- PMP模拟错题总结
本打算15天完成第二轮复习的,结果项目太忙,拖成了25天.第二轮主要以小绿书为主,就是如下这本 怎么说呢,题目偏向于考ITTO的内容,情景题比较少.可以使用“管理圈”APP作为补充 1.敏感性分析的结 ...
- 我的CS考研路
说在前面 从去年7月15号正式准备考研以来,直到今天,3月19号,一共经历8个多月,考研初步告捷,在此想跟大家分享一下自己的经验,希望能对接下来考研的学弟学妹们有所帮助. 首先介绍下我自己的情况,本科 ...
- 帮初学者改代码——有多少青春可以挥霍之“c语言 多重排序”
原文:“c语言 多重排序” 原代码: #include<stdio.h> #include<string.h> struct A { char name[100]; int g ...
- C#轻型ORM框架PetaPoco试水
近端时间从推酷app上了解到C#轻微型的ORM框架--PetaPoco.从github Dapper 开源项目可以看到PetaPoco排第四 以下是网友根据官方介绍翻译,这里贴出来. PetaPoco ...
- Dumb Bones UVA - 10529[多米诺重构]
Dumb Bones UVA - 10529 来自绿书p176 题意 你试图把一些多米诺骨牌排成直线,然后推倒它们.但是如果你在放骨牌的时候不小心把刚放的骨牌碰倒了,它就会把相临的一串骨牌全都碰 ...
- 【UVa】12118 Inspector's Dilemma(欧拉道路)
题目 题目 分析 很巧秒的一道题目,对着绿书瞎yy一会. 联一下必须要走的几条边,然后会形成几个联通分量,统计里面度数为奇数的点,最后再减去2再除以2.这样不断相加的和加上e再乘以t就是答案, ...
- ORM之PetaPoco
近端时间从推酷app上了解到C#轻微型的ORM框架--PetaPoco.从github Dapper 开源项目可以看到PetaPoco排第四 以下是网友根据官方介绍翻译,这里贴出来. PetaPoco ...
- 【紫书】【重要】Abbott's Revenge UVA - 816 bfs 复杂模拟 带方向参数的迷宫
题意:一个迷宫,每个交叉路口有一路标,限制了你从某方向进入该路口所能进入的路口. 题解:1.对于方向的处理:将node多增加一维dir,通过一个const 字符数组 加 上dir_id函数 以及一个方 ...
随机推荐
- Swift 同构与异构
1.数据源中的同构与异构 对于 Swift 的集合数据来说,有同构和异构之分. 如果你需要讨论一群鸟类或者一批飞机,那么这样的数据是同构的,比如包含鸟类的数组 [Bird] 和包含飞机的数组 [Air ...
- sed 简明教程 (转)
sed 简明教程 2013年2月20日 awk于1977年出生,今年36岁本命年,sed比awk大2-3岁,awk就像林妹妹,sed就是宝玉哥哥了.所以 林妹妹跳了个Topless,他的哥哥sed ...
- WEBAPI 的简单示例
一.webapi 1.在webapiconfig中移除xml的返回格式,返回格式就自动使用Json格式 config.Formatters.Remove(config.Formatters.XmlFo ...
- Apache Hadoop YARN: 背景及概述
从2012年8月开始Apache Hadoop YARN(YARN = Yet Another Resource Negotiator)成了Apache Hadoop的一项子工程.自此Apache H ...
- Java知多少(71)文件与目录管理
目录是管理文件的特殊机制,同类文件保存在同一个目录下不仅可以简化文件管理,而且还可以提高工作效率.Java 语言在 java.io 包中定义了一个 File 类专门用来管理磁盘文件和目录. 每个 Fi ...
- cannot open shared object file: No such file or directory
一般我们在Linux下执行某些外部程序的时候可能会提示找不到共享库的错误, 比如:error while loading shared libraries: libxxx.so: cannot ope ...
- Java如何获取本地计算机的IP地址和主机名?
在Java编程中,如何获取本地计算机的IP地址和主机名? 以下示例显示如何使用InetAddress类的getLocalAddress()方法获取系统的本地IP地址和主机名. package com. ...
- rqalpha探究 1 setup.py
rqalpha是难得几个好的做量化交易的开源项目,不过由于自己python用的实在不多,看起来还是觉得很复杂. 因此准备抽取出框架,从最简单的搭建. 思路 从setup着手,看一下如何建立一个发布工程 ...
- React Native 项目整合 CodePush 全然指南
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/y4x5M0nivSrJaY3X92c/article/details/81976844 作者 | 钱 ...
- windows下MySQL免安装版配置教程mysql-5.7.24-winx64.zip版本
一. 以管理员身份运行cmd,进入mysql的bin目录 执行以下代码. #初始化数据库 mysqld --initialize #初始化不会显示密码mysqld --initialize --con ...