记录编号 |
118470 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[NOIP 2010冲刺十三]迷之阶梯 |
最终得分 |
100 |
用户昵称 |
HouJikan |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.013 s |
提交时间 |
2014-09-07 09:14:57 |
内存使用 |
1.29 MiB |
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <iterator>
#include <functional>
#define pritnf printf
#define scafn scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint;
const int INF=0x7ffffff;
//==============struct declaration==============
struct node
{
int pos;int power;
node (int pos=0,int power=0):pos(pos),power(power){}
};
//==============var declaration=================
const int MAXN=510;
int n;
LL h[MAXN];
int f[MAXN][500];//f[i][j]表示在台阶i蓄力j的最短时间
//==============function declaration============
//==============main code=======================
int main()
{
string FileName="ladder";//程序名
string FloderName="COGS";//文件夹名
freopen((FileName+".in").c_str(),"r",stdin);
freopen((FileName+".out").c_str(),"w",stdout);
#ifdef DEBUG
system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
clock_t Start_Time=clock();
#endif
scanf("%d",&n);
For(i,1,n)
scanf("%lld",&h[i]);
h[n+1]=INF;
memset(f,-1,sizeof(f));
f[1][0]=0;
queue <node>Q;
Q.push(node(1,0));
while (!Q.empty())
{
node now=Q.front();Q.pop();
if (now.pos==n)
{
printf("%d\n",f[n][now.power]);
return 0;
}
if (now.pos!=1&&(f[now.pos-1][now.power+1]==-1||f[now.pos-1][now.power+1]>f[now.pos][now.power]+1))
{
Q.push(node(now.pos-1,now.power+1));
f[now.pos-1][now.power+1]=f[now.pos][now.power]+1;
}
for(int i=now.pos+1;i<=n&&h[i]-h[now.pos]<=(1<<now.power);i++)
if (f[i][0]==-1||f[i][0]>f[now.pos][now.power]+1)
{
Q.push(node(i,0));
f[i][0]=f[now.pos][now.power]+1;
}
}
printf("-1\n");
#ifdef DEBUG
clock_t End_Time=clock();
cout<<endl<<endl<<"Time Used: "<<(End_Time-Start_Time)/CLOCKS_PER_SEC<<endl;
#endif
return 0;
}
//================fuction code====================