hdu FatMouse's Speed 1160

链接:http://acm.hdu.edu.cn/showproblem.php?pid=1160

先对weight排序,然后根据speed求最长上升的序列

关键是老鼠的编号输出不怎么好高,原来只要用个before变量 记录前个编号就行了

我的想法不同,有点2,所以找错也早了好久

挫代码如下:

#include <iostream>
#include <stdlib.h>
using namespace std;
int i,j;
struct mouse
{
    int len;
    int num;
    int a[1005];
    int wei;
    int spe;
}k[1005];
int cmp(const void *a,const void *b)
{
    struct mouse *x=(struct mouse *)a;
    struct mouse *y=(struct mouse *)b;
    return x->wei-y->wei;
}
int ch(int a)
{
    int x;
    for(x=0;x<a;x++)
    {
        k[i].a[x]=k[j].a[x];
    }
    k[i].a[x]=k[i].num;
}
int main()
{
   int ax,bx,n=0,var,max;
   while(cin>>ax>>bx)
   {
       k[n].a[0]=n+1;
       k[n].wei=ax;
       k[n++].spe=bx;
   }
   for(i=0;i<n;i++)
   k[i].len=1;
   for(i=0;i<n;i++)
   k[i].num=i+1;
   qsort(k,n,sizeof(k[0]),cmp);
   for(i=0;i<n;i++)
   for(j=0;j<i;j++)
   {
       if(k[j].spe>k[i].spe&&k[j].wei<k[i].wei&&k[i].len<=k[j].len)
       {
           ch(k[j].len);
           k[i].len=k[j].len+1;
       }
   }
   var=max=0;
   for(i=0;i<n;i++)
   {
       if(k[i].len>max)
       {
           max=k[i].len;
           var=i;
       }
   }
   cout<<max<<endl;
   for(i=0;i<max;i++)
   {
       cout<<k[var].a[i]<<endl;
   }
    return 0;
}




你可能感兴趣的:(hdu FatMouse's Speed 1160)