zoukankan      html  css  js  c++  java
  • 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;
    }

  • 相关阅读:
    JAVA数据库建表工具类
    HTML加CSS3太极图demo
    MD5加密(JAVA&JS)
    Base64工具类(JAVA&JS)
    JS模拟圆周运动
    JAVA读取写入excle表兼容版
    Math.PI和Math.sin() 与 Math.cos()搭配使用详解
    MySQL8.0数据库连接问题
    echarts饼状图案例
    JS前端使用MD5加密
  • 原文地址:https://www.cnblogs.com/liulangye/p/2258885.html
Copyright © 2011-2022 走看看