zoukankan      html  css  js  c++  java
  • hdu1160FatMouse's Speed

    比我的代码更好的提示

    typedef struct
    {

        int
     w,s;
        int
     len,index;
        int
     before;
    }
    mice;

    建立数据结构时,用index来记录真实的位置,用before来记录排序后,这个元素上一个元素的位置

    max = m[j].len;
    flag = j;

    用j来表示最大的那个数

    贴上我ACCEPT的代码吧

    #include "iostream"
    #include "algorithm"
    using namespace std;
    struct student{
      int weight,speed;
    }num[1000],s[10000];
    struct{
      int a,pre;
    }dp[10000];
    bool cmp(student a,student b){return a.weight<b.weight;}
    int max(int a,int b){return a>b?a:b;}
    
    int main(){
      int top=1,i,j,maxb=1,list[10000],y,t;
      while(cin>>num[top].weight>>num[top].speed){s[top].weight=num[top].weight;s[top].speed=num[top].speed;dp[top].a=1;dp[top++].pre=0;};
      sort(num+1,num+top,cmp);
      //for(i=1;i<top;i++)cout<<num[i].weight<<' '<<num[i].speed<<endl;
      for(i=2;i<top;i++){
         for(j=1;j<i;j++){
          if(num[j].speed>num[i].speed&&num[j].weight<num[i].weight){
            if(dp[i].a<dp[j].a+1){dp[i].a=dp[j].a+1;dp[i].pre=j;}
            if(maxb<dp[i].a){maxb=dp[i].a;y=i;}
            //cout<<"i "<<i<<" j "<<j<<endl;
          }
         }
      }
      t=top;
      top=1;
      while(y){
        list[top++]=y;
        y=dp[y].pre;
      }
      cout<<maxb<<endl;
      for(i=top-1;i>=1;i--){
        for(j=1;j<t;j++)
          if(num[list[i]].weight==s[j].weight&&num[list[i]].speed==s[j].speed)
           cout<<j<<endl;
      }
    }
  • 相关阅读:
    Linux netstat 命令入门知识
    Linux文件预读对系统的影响
    Ubuntu下配置Hadoop环境
    Debian Wheezy 安装Nginx+HHVM
    Linux Glibc库严重安全漏洞检测与修复方案
    关于系统时间的几个问题
    C语言的整型溢出问题
    Django Nginx配置
    linux上安装mysql5.7
    日期、时间选择器
  • 原文地址:https://www.cnblogs.com/dowson/p/3281160.html
Copyright © 2011-2022 走看看