比赛 |
NOIP_2 |
评测结果 |
AAAAAAAAAA |
题目名称 |
驾车旅行 |
最终得分 |
100 |
用户昵称 |
zqzas |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2008-09-08 22:10:38 |
显示代码纯文本
#include <stdio.h>
#include <stdlib.h>
#define maxn 55
#define inf 999999
const double eat=20.0;
typedef struct Jiayou{
double pos;
double pri;
}Jiayou;
int n;
double goal,full,far,kml,ans,f[maxn];
Jiayou jia[maxn];
FILE *f1,*f2;
inline double min(double a,double b)
{
return a<b?a:b;
}
int cmp(const void *a,const void *b)
{
return (((Jiayou*)a)->pos > ((Jiayou*)b)->pos?1:-1);
}
void dp(int x)
{
int i,j;
double pos,pri,zan;
pos=jia[x].pos;
pri=jia[x].pri;
if (goal-pos<=far)
{
f[x]=0;
return;
}
for (i=n;i>x;i--)
{
if (jia[i].pos-pos<=far)
{
zan=eat+(jia[i].pos-pos)/kml*jia[i].pri;
if (f[i]==inf)
dp(i);
f[x]=min(f[x],f[i]+zan);
break;
}
}
for (j=i-1;j>x;j--)
{
if (jia[j].pos-pos>far/2)
{
zan=eat+(jia[j].pos-pos)/kml*jia[j].pri;
if (f[j]==inf)
dp(j);
f[x]=min(f[x],f[j]+zan);
}
else
break;
}
}
void run(void)
{
dp(0);
ans+=f[0];
}
void ini(void)
{
int i;
fscanf(f1,"%lf",&goal);
fscanf(f1,"%lf%lf%lf",&full,&kml,&ans);
fscanf(f1,"%d",&n);
for (i=1;i<=n;i++)
fscanf(f1,"%lf%lf",&jia[i].pos,&jia[i].pri);
qsort(jia,n+1,sizeof(jia[0]),cmp);
far=kml*full;
for (i=0;i<=n;i++)
f[i]=inf;
}
int main(void)
{
f1=fopen("tour.in","r");
f2=fopen("tour.out","w");
ini();
run();
fprintf(f2,"%.1lf",ans);
fclose(f1);fclose(f2);
return 0;
}