2017 ACM-ICPC 南宁区比赛 Minimum Distance in a Star Graph
2017-09-25 19:58:04
writer:pprp
题意看上去很难很难,但是耐心看看还是能看懂的,给你n位数字
你可以交换第一位和之后的某一位,问你采用最少的步数可以交换成目标
有五组数据
用BFS进行搜索,并进行剪枝,已经搜索过的点不再搜索
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <set>
#include <queue> using namespace std; string sa, sb; int n; struct node
{
string str;
int times;
node()
{
str = "";
times = ;
}
}; int bfs()
{
queue<node> q;
set<string> ss;
node now , nex;
now.str = sa;
q.push(now);
ss.insert(now.str);
while(!q.empty())
{
now = q.front();
q.pop();
if(now.str == sb)
return now.times;
for(int i = ; i < n;i++)
{
nex.str = now.str;
nex.times = now.times+;
nex.str[i] = now.str[];
nex.str[] = now.str[i];
if(ss.count(nex.str) == )
{
ss.insert(nex.str);
q.push(nex);
}
else
continue;
}
}
} int main()
{
cin >> n;
for(int i = ; i < ;i++)
{
cin >> sa >> sb;
cout << bfs() << endl;
} return ;
}
现阶段掌握搜索还不是太好,希望以后可以尽快掌握
2017 ACM-ICPC 南宁区比赛 Minimum Distance in a Star Graph的更多相关文章
- 2017 ACM/ICPC 南宁区 网络赛 Overlapping Rectangles
2017-09-24 20:11:21 writer:pprp 找到的大神的代码,直接过了 采用了扫描线+线段树的算法,先码了,作为模板也不错啊 题目链接:https://nanti.jisuanke ...
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 Minimum Distance in a Star Graph
In this problem, we will define a graph called star graph, and the question is to find the minimum d ...
- 2017ICPC南宁赛区网络赛 Minimum Distance in a Star Graph (bfs)
In this problem, we will define a graph called star graph, and the question is to find the minimum d ...
- 2017南宁网络赛 Problem J Minimum Distance in a Star Graph ( 模拟 )
题意 : 乱七八糟说了一大堆,实际上就是问你从一个序列到另个序列最少经过多少步的变化,每一次变化只能取序列的任意一个元素去和首元素互换 分析 : 由于只能和第一个元素去互换这种操作,所以没啥最优的特别 ...
- 2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路
transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 132768/1 ...
- 2017 ACM/ICPC Shenyang Online SPFA+无向图最长路
transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 132768/1 ...
- 2017 ACM/ICPC Asia Regional Qingdao Online
Apple Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submi ...
- 2017 ACM ICPC Asia Regional - Daejeon
2017 ACM ICPC Asia Regional - Daejeon Problem A Broadcast Stations 题目描述:给出一棵树,每一个点有一个辐射距离\(p_i\)(待确定 ...
- 2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest
2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest A - Arranging Wine 题目描述:有\(R\)个红箱和\(W\)个白箱,将这 ...
随机推荐
- Photoshop打开时报错“不能打开暂存盘文件。。。”
解决方法: 1.找到应用程序(Photoshop.exe文件) 2.右键 -> 属性 -> 兼容性 -> 更改所有用户的设置 -> 勾选上“以管理员身份运行此程序”.
- Newman语法参数
npm install -g newman npm install -g newman-reporter-html newman run XXX.json -k -r html --reporter- ...
- mysql不乱码的思想总结
不乱码的思想:中文环境下建议选择utf-8 1.linux服务器端的设置: 1 [root@localhost app]# cat /etc/sysconfig/i18n 2 LANG="e ...
- linux系统压缩\解压命令详解
转自:http://www.cnblogs.com/qq78292959/archive/2011/07/06/2099427.html. tar -c: 建立压缩档案-x:解压-t:查看内容-r:向 ...
- 【多线程基础】- 多个线程顺序打印ABC
题目:3个线程名字分别是A,B,C 现在在console上连续打印10次 ABC . public class Test { public static void main(String[] args ...
- python中的内置函数总结
官方文档 一. 数学函数 #abs() 绝对值 #bin() 二进制 0b #oct() 八进制 0o #hex() 十六进制 0x #complex 复数 x=1-2j print(x) print ...
- java初学一
1.区分大小写 public static void main String args[] 是类体中的一个方法,之后的两个大括号以及之间的内容叫做方法体,一个java应用程序中必须有一个类且只有一个 ...
- split_lzo_lib.sh
split_lzo_lib.sh #!/bin/sh#输入文件名filename=$1#分割文件大小filesize=4096#输出库文件名libname="lib"$(echo ...
- Spring-1-F Dice(HDU 5012)解题报告及测试数据
Dice Time Limit:1000MS Memory Limit:65536KB Description There are 2 special dices on the table. ...
- windows 常用cmd命令
为了减少使用鼠标的频次,熟记一些常用应用的快捷键与系统本身常用的命令是必须的,以下记录一些常用的windows系统命令. 查看网络端口占用情况 :netstat -ano | findstr 8080 ...