p2739 Shuttle Puzzle
观察样例得知就是和离'_'左边最近的'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的更多相关文章
- USACO 4.4 Shuttle Puzzle
Shuttle PuzzleTraditional The Shuttle Puzzle of size 3 consists of 3 white marbles, 3 black marbles, ...
- USACO4.4 Shuttle Puzzle【bfs+优化】
直接上$bfs$,每一个状态记录下当前字符串的样子,空格的位置,和走到这个状态的答案. 用空格的位置转移,只有$50pts$ 考虑到题目一个性质:$W$只往右走,$B$只往左走,就可以过了. #inc ...
- USACO 完结的一些感想
其实日期没有那么近啦……只是我偶尔还点进去造成的,导致我没有每一章刷完的纪念日了 但是全刷完是今天啦 讲真,题很锻炼思维能力,USACO保持着一贯猎奇的题目描述,以及尽量不用高级算法就完成的题解……例 ...
- USACO刷题索引
序 在距离CSP2019还有41天的国庆备战中,考了一场画风非常奇特的六校联赛,然后被教练建议刷一下这个巩固代码实现能力,然后就来了||ヽ(* ̄▽ ̄*)ノミ|Ю. 这个网站还是挺好玩儿的吧,刚开始各种 ...
- Puzzle 面向服务/切面(AOP/IOC)开发框架 For .Net
Puzzle 面向服务/切面AOP开发框架 For .Net AOP主要实现的目的是针对业务处理过程中的切面进行提取,它所面对的是处理过程中的某个步骤或阶段,以获得逻辑过程中各部分之间低耦合性的隔离效 ...
- HDU5456 Matches Puzzle Game(DP)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5456 Description As an exciting puzzle game for ...
- 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 ...
- poj3678 Katu Puzzle 2-SAT
Katu Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6714 Accepted: 2472 Descr ...
- POJ1651Multiplication Puzzle[区间DP]
Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8737 Accepted: ...
随机推荐
- Oracle错误——ORA-01940: cannot drop a user that is currently connected
背景 在oracle删除用户时,有的时候会提示ORA-01940: cannot drop a user that is currently connected,不能够删除用户. 原因 这是因为有其他 ...
- uniGUI试用笔记(七)
uniGUI的文件下载由于TUniSession的存在而变得非常简单,最典型的一个例子就是将列表中的所有数据导出到Excel中.服务器上采用TMS FlexCel控件,先将数据集中的记录导入到Exce ...
- Flask学习【第5篇】:用Falsk实现的分页
Flask实现的分页组件 from urllib.parse import urlencode,quote,unquote class Pagination(object): "" ...
- Python常用库之Pilow
基本用法 静态方法 PIL.Image.open(fp, mode=’r’) 传入文件路径(str),返回一个image对象 PIL.Image.alpha_composite(im1, im2) 混 ...
- Pytest 简明教程
pytest-learn 通过文章 Python 单元测试框架之 Pytest 剖解入门(第一篇) 学习 Pytest. 有很多的第三方插件可以自定义扩展,并且支持 Allure,生成可视化的测试报告 ...
- luogu1975 [国家集训队]排队
思路 序列中 |i | 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| |----|--|--|--|--|--|--|--|--|--|--| |a[i]| a| b| c| L| d ...
- LuoguP1041 传染病控制
题目地址 题目链接 题解 这里讲一个非正解--贪心+随机化. 贪心的想法是什么? 我们dfs一遍处理出每个节点子树内的节点数量,记为\(siz\). 贪心的砍掉\(siz\)最大的那个子树,在树的形态 ...
- springBoot 学习(总)
springBoot有个中文文档网址,应该是持续更新的. 别的资料 http://tengj.top/2017/02/26/springboot1/ http://412887952-qq-c ...
- [thymeleaf] - 1.Thymeleaf是什么
Thymeleaf是⾯向Web和独⽴环境的现代服务器端Java模板引擎,能够处 理HTML,XML,JavaScript,CSS甚⾄纯⽂本. Thymeleaf旨在提供⼀个优雅的.⾼度可维护的创建模板 ...
- c# 后台post,包含file文件
http request 相关 private bool Upload(KeyValuePair<string, string>[] paramString,Stream paramFil ...