观察样例得知就是和离'_'左边最近的'w'交换位置,然后和离'_'右边最近的'b'交换位置,轮流进行。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <stack>
#include <bitset>
#define mkp make_pair
using namespace std;
const double EPS=1e-;
typedef long long lon;
const lon SZ=,INF=0x7FFFFFFF,mod=; void work(string str,string tmp,int n)
{
vector<int> res;
int pos=str.find('_');
for(int time=;;++time)
{
if(str==tmp)break;
for(int i=;i<min(time,n);++i)
{
if(str==tmp)break;
int dst;
if(time&)dst=str.find_last_of('w',pos);
else dst=str.find('b',pos);
if(dst==-)break;
//cout<<str<<endl;
//cout<<dst<<endl;
res.push_back(dst);
swap(str[pos],str[dst]);
pos=dst;
}
}
for(int i=;i<res.size();++i)
{
if(i%!=)cout<<" ";
cout<<res[i]+;
if((i+)%==)cout<<endl;
}cout<<endl;
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
lon casenum;
//cin>>casenum;
//for(lon time=1;time<=casenum;++time)
{
int n;
cin>>n;
string str(n,'w');
str+='_';
str+=string(n,'b');
string tmp(n,'b');
tmp+='_';
tmp+=string(n,'w');
work(str,tmp,n);
}
return ;
}

p2739 Shuttle Puzzle的更多相关文章

  1. USACO 4.4 Shuttle Puzzle

    Shuttle PuzzleTraditional The Shuttle Puzzle of size 3 consists of 3 white marbles, 3 black marbles, ...

  2. USACO4.4 Shuttle Puzzle【bfs+优化】

    直接上$bfs$,每一个状态记录下当前字符串的样子,空格的位置,和走到这个状态的答案. 用空格的位置转移,只有$50pts$ 考虑到题目一个性质:$W$只往右走,$B$只往左走,就可以过了. #inc ...

  3. USACO 完结的一些感想

    其实日期没有那么近啦……只是我偶尔还点进去造成的,导致我没有每一章刷完的纪念日了 但是全刷完是今天啦 讲真,题很锻炼思维能力,USACO保持着一贯猎奇的题目描述,以及尽量不用高级算法就完成的题解……例 ...

  4. USACO刷题索引

    序 在距离CSP2019还有41天的国庆备战中,考了一场画风非常奇特的六校联赛,然后被教练建议刷一下这个巩固代码实现能力,然后就来了||ヽ(* ̄▽ ̄*)ノミ|Ю. 这个网站还是挺好玩儿的吧,刚开始各种 ...

  5. Puzzle 面向服务/切面(AOP/IOC)开发框架 For .Net

    Puzzle 面向服务/切面AOP开发框架 For .Net AOP主要实现的目的是针对业务处理过程中的切面进行提取,它所面对的是处理过程中的某个步骤或阶段,以获得逻辑过程中各部分之间低耦合性的隔离效 ...

  6. HDU5456 Matches Puzzle Game(DP)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5456 Description As an exciting puzzle game for ...

  7. one recursive approach for 3, hdu 1016 (with an improved version) , permutations, N-Queens puzzle 分类: hdoj 2015-07-19 16:49 86人阅读 评论(0) 收藏

    one recursive approach to solve hdu 1016, list all permutations, solve N-Queens puzzle. reference: t ...

  8. poj3678 Katu Puzzle 2-SAT

    Katu Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6714   Accepted: 2472 Descr ...

  9. POJ1651Multiplication Puzzle[区间DP]

    Multiplication Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8737   Accepted:  ...

随机推荐

  1. python --- 11 第一类对象 函数名 闭包 迭代器

    一 .函数名的运用    ①函数名是⼀个变量, 但它是⼀个特殊的变量, 与括号配合可以执⾏函数的变量 ②函数名是一个内存地址    ③ 函数名可以赋值给其他变量         ④函数名可以当做容器类 ...

  2. CentOS6.8下安装Redis

    1.由于Redis是使用C语言开发的,安装时需要对Redis的源码进行编译,编译依赖gcc环境,如果没有gcc,需要先安装gcc: yum install gcc-c++ 2.安装完成后,进入Redi ...

  3. uniGUI试用笔记(十一)

    最近研究了一下UniGUI的TuniDBGrid,记录一下免得忘记了. TuniDBGrid的重要属性包括: 1.列—TUniDBGridColumns和TUniDBGridColumn 每个列对象( ...

  4. Python3基础 list list()生成空列表

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  5. 【BZOJ】2734: [HNOI2012]集合选数

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2734 考虑$N=4$的情况: \begin{bmatrix} 1&3 &X ...

  6. mime模块响应或设置Node.js的Content-Type头

    转载自:https://itbilu.com/nodejs/core/VJYaAfKrl.html   MIME,即:Multipurpose Internet Mail Extensions,多用途 ...

  7. spring集成shiro报错解决(no bean named 'shiroFilter' is defined)

    引言: 本人在使用spring集成shiro是总是报“no bean named 'shiroFilter' is defined”,网上的所有方式挨个试了一遍,又检查了一遍, 还是没有解决,最后,抱 ...

  8. Integer的最大值

    来自:https://blog.csdn.net/qq_33611068/article/details/77369050 有这样一道题: 编程测试,遍历 0 到 int所能表示最大的正数,将消耗的时 ...

  9. ArrayList的详解

    数组一旦给定大小就是固定的,只能放同类型的不能再改,还有一种高级的可扩充的,就是arrayList类,被称作动态数组或者集合. 使用步骤: 1. 引用命名空间system.collections: 2 ...

  10. C++.运行时类型判断_测试代码

    ZC:C++ 编程思想——运行时类型识别 - 浅墨浓香 - 博客园.html(https://www.cnblogs.com/5iedu/articles/5585895.html) -------- ...