ural 1119. Metro

看完题直接 二维数组做的 MLE了

可以转换一下思路

每走一个折线 就节约(200-sqrt(2)*100)

所以可以求最多可走多少折线块 从总路中减去节约的就可以了

 http://acm.timus.ru/problem.aspx?space=1&num=1119

#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string>
#include<map>
#include<queue>
#include<algorithm>
#include<string.h>
#include<stack>
using namespace std;
struct node
{
    int x,y;
}mem[101];
bool cmp(node a,node b)
{
    if(a.x==b.x)
    return a.y<b.y;
    return a.x<b.x;
}
int main()
{
   //freopen("d:\\6\\bin\\Debug\\hu.txt","r",stdin);
   const double T=sqrt(2.0)*100;
   int a[101];
   int n,m,k,i,j,l,max;
   cin>>n>>m;
   cin>>k;
   for(i=0;i<k;i++)
   cin>>mem[i].x>>mem[i].y;
   if(k==0)
   {
       printf("%d\n",(n+m)*100);
       return 0;
   }
   sort(mem,mem+k,cmp);
   a[0]=1;l=1;
   for(i=1;i<k;i++)
   {
       max=0;
       for(j=0;j<i;j++)
       {
           if(mem[j].y<mem[i].y&&mem[j].x<mem[i].x&&a[j]>max)
           {
               max=a[j];
           }
           a[i]=max+1;
           if(a[i]>l)
           l=a[i];
       }
   }
   printf("%d\n",int((n+m)*100.0-l*(200.0-T)+0.5));
   return 0;
}

转载于:https://www.cnblogs.com/liulangye/archive/2011/11/22/2258885.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值