观察样例得知就是和离'_'左边最近的'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. Restful framework【第六篇】认证组件

    基本用法 -认证功能 1 写一个类,继承BaseAuthentication 2 def authenticate(self,request) ,记住传request对象 -如果验证通过,返回None ...

  2. Android灯光系统通知灯【转】

    本文转载自:https://blog.csdn.net/danwuxie/article/details/82193880 一.通知灯应用程序的编写 1.首先实现一个按钮功能 <LinearLa ...

  3. MongDB 数据库使用技巧及注意事项

    说明 本文记录MongoDB数据库的使用技巧总结,特性发现. 利用TTL特性实现数据定时删除 限制: 你不能创建TTL索引,如果要索引的字段已经在其他索引中使用. 索引不能包含多个字段. 索引的字段必 ...

  4. C# 给类做事件的一般做法

    https://docs.microsoft.com/zh-cn/dotnet/standard/events/how-to-raise-and-consume-events 第一个示例演示如何引发和 ...

  5. JXOI2018守卫 区间DP

    链接 https://loj.ac/problem/2545 思路 f[i][j]表示i到j区间的最小监视人数 可以预处理出来g[i][j],表示i能否监视到j (其实预处理的关系不大,完全可以直接判 ...

  6. Docker 编排工具Rancher 1.6.18

    使用docker获取rancher [root@localhost /]# docker pull rancher/server:stable [root@localhost /]# docker i ...

  7. word设置行距18磅

    参考:word如何设置行距18磅 word设置行距18磅 选中需要设置的段落--"格式"菜单--段落--"缩进和间距"标签--在"行距"下拉 ...

  8. 【BZOJ】3142: [Hnoi2013]数列

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3142 12年也有一个组合数学...(这几年的画风啊.... 考虑直接去做:DP? DP+容 ...

  9. C#:MVC打印PDF文件

    在百度上找了许多PDF文件打印,但是符合我需求的打印方式还没看到,所以根据看了https://www.cnblogs.com/TiestoRay/p/3380717.html的范例后,研究了一下,做出 ...

  10. 四: scrapy爬虫框架

    5.爬虫系列之scrapy框架   一 scrapy框架简介 1 介绍 (1) 什么是Scrapy? Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架,非常出名,非常强悍.所谓的框架 ...