Ending 2014-07-01 01:13:01
点我顶贴
收藏
删除
#include<iostream>
#include<cstring>
#include<climits>
#include<algorithm>
using namespace std;
int main()
{
int t,j,width,ncase,arr[5005],dp[5050];
double slope = 2147483647,x;
cin >> ncase >>width;
for(int i = 0; i < ncase; ++i)
cin>>arr[i];
memset(dp,1E10,sizeof(dp));
dp[0] = 1; //起点已经算一个
for(int i = 1; i < ncase; ++i)
{
t = max(i - width,0); //坐标范围波动
for (slope=1E12,dp[i]=10000,j=i-1; j>=t; j--)
{
x=(double)(arr[i]-arr[j])/(double)(i-j);
if (x<=slope)
{
slope=x;
if (dp[j]+1<dp[i]) dp[i]=dp[j]+1;
}
}
}
cout << dp[ncase - 1];
}
#1 159753abclife@2015-11-24 01:56:30
33512
回复
删除
真不知道怎么AC
#include<iostream>
中间要打空格,不然不过,千万别好心害了人- -
纠正#include <iostream>