#include<string>
#include<algorithm>//sort()
#include<iostream>
using namespace std;
struct Rat{ int num, w, s; };
int k = 0, w, s; Rat rat[1000];
void init()
{
while (cin >> w >> s)
{
rat[k].num = k + 1;
rat[k].w = w; rat[k].s = s;
k++;
}
}
bool cmp(Rat a, Rat b)//结构体Rat没有定义小于运算 要定义比较函数cmp才能调用sort函数
{
if (a.w != b.w) return a.w<b.w;
else return a.s>b.s;
}
void path(int *p, Rat *rat, int start)
{
if (start == -1) return;
path(p, rat, p[start]);
cout << rat[start].num << endl;
}
int main()
{
int c[1000] = { 0 }, p[1000]; c[0] = 1;
memset(p, -1, sizeof(p));
init();
sort(rat, rat + k + 1, cmp);
for (int i = 1; i <= k; i++)
{
for (int j = 0; j<i; j++)
{
if (rat[j].w<rat[i].w&&rat[j].s>rat[i].s)
if (c[i]<c[j]){ c[i] = c[j]; p[i] = j; }
}
c[i]++;
}
int max = 0, start;
for (int i = 0; i <= k; i++)
{
if (max<c[i]) { max = c[i]; start = i; }
}
cout << max << endl;
path(p, rat, start);
}
ZOJ 1108 FatMouse's Speed
最新推荐文章于 2024-03-26 20:49:24 发布