栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 3912 Up and Down

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 3912 Up and Down

#include<stdio.h>struct{       __int64 x,y;}a[100];__int64 map[100][100];int main(){       int w,s,p,i,j,k;       while(scanf("%d",&w)!=EOF,w)       {   for(i=0;i<=88;i++)   {          a[i].x=2000000001;          for(j=0;j<=88;j++)      map[i][j]=2000000001;   }   scanf("%d%d",&s,&p);   j=p;   for(i=1;i<=p;i++)   {          j++;          scanf("%I64d%I64d",&a[i].x,&a[i].y);          map[i][j]=0;   }   a[0].x=a[0].y=0;   a[2*p+1].x=a[2*p+1].y=w;   __int64 sum,count;   for(i=0;i<=0;i++)  {          sum=0;          count=0;          for(j=i+1;j<=p+1;j++)          {      if(j==p+1)      {  if(w>sum)  {         if((w-sum)%s!=0)     count++;         count=count+(w-sum)/s;  }  map[i][2*p+1]=count;  break;      }      if(a[j].x>sum)      {  int tt=count;  if((a[j].x-sum)%s!=0)         count++;  count=count+(a[j].x-sum)/s;  sum+=(count-tt)*s;      }      if(a[j].x==sum)      {  map[i][j]=count;  sum--;      }      else if(a[j].x<sum)      {  map[i][j]=count;  while(a[j+1].x<sum)  {         j++;         map[i][j]=count;  }  if(a[j+1].x==sum)  {         j++;         map[i][j]=count;         int jj=j,kk=s;         sum--;         while(a[jj-1].x==sum)         {     kk--;     map[i][jj]=count;     sum--;jj--;     if(kk==1) break;         }         if(kk==1)         break;  }      }          }   }   for(i=1;i<=p;i++){          j=1;          sum=a[i].y;          count=0;          while(a[i].y>a[j].x||i==j) j++;          for(j;j<=p+1;j++)          {      if(j==p+1)       {  if(w>sum)  {         if((w-sum)%s!=0)     count++;         count=count+(w-sum)/s;  }  map[i+p][2*p+1]=count;  break;      }      if(sum<a[j].x)      {  int tt=count;  if((a[j].x-sum)%s!=0)         count++;  count=count+(a[j].x-sum)/s;  sum+=(count-tt)*s;      }      if(sum==a[j].x)      {  map[i+p][j]=count;  sum--;      }      else if(sum>a[j].x)      {  map[i+p][j]=count;  while(a[j+1].x<sum)  {         j++;         map[i+p][j]=count;  }  if(a[j+1].x==sum)  {         j++;         map[i+p][j]=count;         int jj=j,kk=s;         sum--;         while(a[jj-1].x==sum)         {     kk--;     map[i+p][jj]=count;     sum--;jj--;     if(kk==1) break;         }         if(kk==1) break;  }      }          }   }   for(i=0;i<=2*p+1;i++)       {          for(j=0;j<=2*p+1;j++)          {      for(k=0;k<=2*p+1;k++)      {  if(map[j][k]>map[j][i]+map[i][k])         map[j][k]=map[j][i]+map[i][k];      }          }   }   printf("%I64dn",map[0][2*p+1]);}       return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/367137.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号