AC日记——图灵机游戏 codevs 2292
【Shadow 1】第二题
Shadow最近知道了图灵机是什么(Shadow:就是一行格子和一个机器头移来移去的呗!),于是他突发奇想,创造了一个新游戏——“图灵机游戏”(Shadow:好听吧?)。
游戏规则如下:
在一条长长的纸上有N个格子,每个格子上都有一个数,第i格的数记为Ai,机器头刚开始在第1格。这个游戏有两个操作:
1.如果现在在第i格,则可以移动机器头到第Ai格;
2.把某个Ai减少或增加1。
然而,fotile96看了之后却不以为然。“嗯,你挑战一下用最少次数使机器头到达第N格吧,这样好玩些……”
现在,Shadow已经快Crazy了。于是,Shadow把脸转向了你……
1行,1个整数,为最少的操作次数。
3
对于30%的数据,1≤N≤10;
对于60%的数据,1≤N≤1000;
对于100%的数据,1≤N≤100000,1≤Ai≤N。
<h4>样例解释</h4>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> #define maxn 100005 using namespace std; int if_z,n,ai[maxn],dis[maxn]; char Cget; bool if_[maxn]; inline void in(int &now)
{
now=,if_z=,Cget=getchar();
while(Cget>''||Cget<'')
{
if(Cget=='-') if_z=-;
Cget=getchar();
}
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
now*=if_z;
return ;
} int main()
{
in(n);queue<int>que;
for(int i=;i<=n;i++) in(ai[i]);
if_[ai[]]=true,dis[ai[]]=;que.push(ai[]);
while(!que.empty())
{
int now=que.front();
if(!if_[ai[now]])
{
que.push(ai[now]);
if_[ai[now]]=true;
dis[ai[now]]=dis[now]+;
}
if(now+<=n&&!if_[now+])
{
que.push(now+);
if_[now+]=true;
dis[now+]=dis[now]+;
}
if(now->&&!if_[now-])
{
que.push(now-);
if_[now-]=true;
dis[now-]=dis[now]+;
}
que.pop();
}
cout<<dis[n];
return ;
}
AC日记——图灵机游戏 codevs 2292的更多相关文章
- AC日记——约瑟夫问题 codevs 1282
1282 约瑟夫问题 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 大师 Master 题解 查看运行结果 题目描述 Description 有编号从1到N的N个小 ...
- AC日记——[SCOI2009]游戏 bzoj 1025
[SCOI2009]游戏 思路: 和为n的几个数最小公倍数有多少种. dp即可: 代码: #include <bits/stdc++.h> using namespace std; #de ...
- AC日记——国王游戏 洛谷 P1080
国王游戏 思路: 贪心+高精: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 1005 struct Dat ...
- AC日记——色板游戏 洛谷 P1558
色板游戏 思路: sb题: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 struct Tre ...
- AC日记——[SCOI2010]游戏 bzoj 1854
1854: [Scoi2010]游戏 Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 4938 Solved: 1948[Submit][Status] ...
- AC日记——丑数 codevs 1246
1246 丑数 USACO 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description 对于一给定的素 ...
- AC日记——砍树 codevs 1388
1388 砍树 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 伐木工人米尔科需要砍倒M米长的木 ...
- AC日记——元素查找 codevs 1230
1230 元素查找 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description 给出n个正整数,然后有 ...
- AC日记——石子归并 codevs 1048
1048 石子归并 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 有n堆石子排成一列,每堆石子 ...
随机推荐
- MySQL在windows上的安装步骤
参考文章MySQL安装及建议:https://zhuanlan.zhihu.com/p/44977117 但在进入mysql中修改root命令时,使用文章中的命令: ALTER USER 'root' ...
- C++简易酒店管理系统,实现(查询、入住、退房、楼层选择、退出)功能
#include <iostream> #include <string.h> #include <stdlib.h> void enter(); void che ...
- overtrue/wechat 包 由 sys_get_temp_dir 引发的 the directory "c:\Windows" is not writable
vendor\overtrue\wechat\src\Foundation\Application.php registerBase 方法 在初始化属性时 $this['cache'] = funct ...
- destoon 自定义session丢失
destoon 在使用session之前 应该实例化 $session = new dsession(); destoon通过配置文件加载了不同session存储方式.如果你使用session的页面 ...
- 配置wamp开发环境之mysql的配置
此前我已经将wamp配置的Apache.PHP.phpmyadmin全部配置完成,以上三种配置参照 配置wamp开发环境 下面我们来看看mysql的配置,这里用的是mysql5.5.20,下载地址: ...
- POJ 1791 Parallelogram Counting(求平行四边形数量)
Description There are n distinct points in the plane, given by their integer coordinates. Find the n ...
- PTA 7-2 符号配对
直接用栈模拟即可,数组可做,但因为这节数据结构是栈,为了期末考试还是手写一下栈的操作,值得注意的是,这道题用gets函数在PTA上会编译错误,用scanf("%[^\n]", st ...
- Post页面爬取失败__编码问题
python3爬取Post页面时, 报以下错误 "POST data should be bytes or an iterable of bytes. It cannot be of typ ...
- oracle 控制文件的重建
目录 oracle 控制文件的重建 NORESETLOGS RESETLOGS oracle 控制文件的重建 不到最后时刻,如三个控制文件都已损坏,又没有控制文件的备份.还是不要重建控制文件,处理不好 ...
- TOJ3031: Multiple bfs
3031: Multiple Time Limit(Common/Java):2000MS/6000MS Memory Limit:65536KByte Total Submit: 60 ...