2017南宁网络赛 Problem J Minimum Distance in a Star Graph ( 模拟 )
题意 : 乱七八糟说了一大堆,实际上就是问你从一个序列到另个序列最少经过多少步的变化,每一次变化只能取序列的任意一个元素去和首元素互换
分析 : 由于只能和第一个元素去互换这种操作,所以没啥最优的特别方法,只要乖乖模拟即可,如果第一个元素不在正确位置则将它和正确位置的元素交换使其回到正确位置,如果第一个元素的位置就是正确的,那么就往后找不在正确位置的元素将它互换到第一个去,然后再对第一个元素进行判断即可,直到序列变成最终满足条件的序列........
#include<bits/stdc++.h>
using namespace std;
map<char, int> pos;
], en[];
int n;
bool OK()
{
; i<n; i++){
if(st[i] != en[i])
return false;
}return true;
}
int main(void)
{
scanf("%d", &n);
; t<=; t++){
pos.clear();
scanf("%s %s", st, en);
; i<n; i++){
pos[en[i]] = i;///记录每一个数字的正确位置
}
;
;
while(!OK()){///每一次检查一下序列是否已经变成了最终序列
] != st[]){
swap(st[], st[pos[st[]]]);
ans++;
}else{
; i<n; i++){
if(en[i] != st[i]){
swap(st[], st[i]);
ans++;
break;
}
}
}
}
printf("%d\n", ans);
}
;
}
瞎 : 做题经验不够,不能根据通过人数大胆往简单方向想,导致一直在乱七八糟找规律,期间还写了个BFS进行状态图搜索,导致在这个题浪费挺多时间(ノ`Д)ノ
2017南宁网络赛 Problem J Minimum Distance in a Star Graph ( 模拟 )的更多相关文章
- 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 ACM-ICPC 南宁区比赛 Minimum Distance in a Star Graph
2017-09-25 19:58:04 writer:pprp 题意看上去很难很难,但是耐心看看还是能看懂的,给你n位数字 你可以交换第一位和之后的某一位,问你采用最少的步数可以交换成目标 有五组数据 ...
- 2017 icpc 南宁网络赛
2000年台湾大专题...英语阅读输入输出专场..我只能说很强势.. M. Frequent Subsets Problem The frequent subset problem is define ...
- 2017乌鲁木齐网络赛 j 题
题目连接 : https://nanti.jisuanke.com/t/A1256 Life is a journey, and the road we travel has twists and t ...
- hdu 6152 : Friend-Graph (2017 CCPC网络赛 1003)
题目链接 裸的结论题.百度 Ramsey定理.刚学过之后以为在哪也不会用到23333333333,没想到今天网络赛居然出了.顺利在题面更改前A掉~~~(我觉得要不是我开机慢+编译慢+中间暂时死机,我还 ...
- 2017-ACM南宁网络赛
In this problem, we will define a graph called star graph, and the question is to find the minimum d ...
- 2017北京网络赛 J Pangu and Stones 区间DP(石子归并)
#1636 : Pangu and Stones 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In Chinese mythology, Pangu is the fi ...
- hihocoder 1586 ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛-题目9 : Minimum【线段树】
https://hihocoder.com/problemset/problem/1586 线段树操作,原来题并不难..... 当时忽略了一个重要问题,就是ax*ay要最小时,x.y可以相等,那就简单 ...
随机推荐
- vue路由高级用法
五.路由设置高级用法alias 别名 {path:'/list',component:MyList,alias:'/lists'}redirect 重定向 {path:'/productList',r ...
- java一周学习记录(2017/12/2)
姓名:Danny 日期:2017/12/2 周日 周一 周二 周三 周四 周五 周六 所花时间 120 150 190 150 180 28 ...
- C#银行卡号每隔4位数字加一个空格
1.填写银行卡号每隔4位数字加一个空格 Regex.Replace(dic["BankCardNo"].ToString(), @"(\d{4}(?!$))", ...
- vue+sentry 前端异常日志监控
敲代码最糟心不过遇到自己和测试的环境都OK, 客户使用有各种各样还复现不了的问题,被逼无奈只能走到这一步:前端异常日志监控! vue官方文档如下推荐: 就是说, vue有错误机制处理errorHand ...
- AngularJS——基础小知识(一)
$time0ut :定时器 $rootscope :全局的 $scope : 局部的作用域: 它下面的方法: $scope.$watch $scope.$apply 1)$scope.$wat ...
- PHP批量导入excell表格到mysql数据库
PHP批量导入excell表格到mysql数据库,本人通过亲自测试,在这里分享给大家 1,下载 php excell类库 网上搜索可以下载,这里不写地址 2,建html文件 <form met ...
- 剑指offer-二叉树的镜像-python
题目描述 操作给定的二叉树,将其变换为源二叉树的镜像. 输入描述: 二叉树的镜像定义:源二叉树 8 / \ 6 10 / \ / \ 5 7 9 11 镜像二叉树 8 / \ 10 6 / \ / \ ...
- Qt读写Json
Qt操作Json 1.QJsonDocument 1.详细说明 QJsonDocument类提供了读写JSON文档的方法. QJsonDocument是一个封装了完整JSON文档的类,可以从基于UTF ...
- 关于position的操作
1.position:relative 相较于正常位置的定位 <!DOCTYPE html> <html lang="en"> <head> & ...
- XIB约束布局问题(button)
button默认不给宽度:系统Xib自动适配,最小宽度30.在使用宽度计算时,无法小于这个值