一道ACM的题目,请教各位

SENSSSZ 2011-01-17 08:04:39
以下是原题:
Is Bigger Smarter

Some people think that the bigger an elephant is, the smarter it is. To disprove this, you want to take the data on a collection of elephants and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the IQ's are decreasing.
The input will consist several cases. Each case begins with a integer N,there will be N lines, one elephant per line. Input will be terminated by the end-of-file. The data for a particular elephant will consist of a pair of integers: the first representing its size in kilograms and the second representing its IQ in hundredths of IQ points. Both integers are between 1 and 10000. The data will contain information for at most 1000 elephants. Two elephants may have the same weight, the same IQ, or even the same weight and IQ.
Say that the numbers on the i-th data line are W[i] and S[i]. Your program should output a sequence of lines of data; the first line should contain a number n; the remaining n lines should each contain a single positive integer (each one representing an elephant). If these n integers are a[1], a[2],..., a[n] then it must be the case that
W[a[1]] < W[a[2]] < ... < W[a[n]]
and
S[a[1]] > S[a[2]] > ... > S[a[n]]
In order for the answer to be correct, n should be as large as possible. All inequalities are strict: weights must be strictly increasing, and IQs must be strictly decreasing. There may be many correct outputs for a given input, your program only needs to find one.
Sample Input
9
6008 1300
6000 2100
500 2000
1000 4000
1100 3000
6000 2000
8000 1400
6000 1200
2000 1900

Sample Output
4
4
5
9
7

我姑且翻译一下吧……有不好的地方大家包涵
有人认为大象体重越重就越聪明,为了证明这是错的,你要从给定的数据当中挑出尽可能多的一列数据,这一列数据中,随着大象体重的增长,它们的智商在降低。
输入的最开始是一个整数N,接下来是N行整数,输入以EOF结束。每行包含两个整数,第一个整数是大象的体重,第二个是大象的IQ,两个整数都在1到10000之间,最多有1000只大象的数据。两只大象可以有相同的体重或相同的IQ,或者两个都一样。
假设第i行的数据是w[i]和s[i]。程序的输出应该包含几行数据,第一行是一个整数n,接下来有n行数据,每行都是一个整数(每个整数代表一只大象),假设这些数据是a[1], a[2]...a[n],那么应该有
w[a[1]] > w[a[2]] > ... >w[a[n]]
同时有
s[a[1]] > s[a[2]] > ... >s[a[n]]
为了尽可能证明你的结论是正确的,n必须尽可能大。上述不等式都是严格>或<。如果有多个结果,就任意输出其中一个。

Sample Input
9
6008 1300
6000 2100
500 2000
1000 4000
1100 3000
6000 2000
8000 1400
6000 1200
2000 1900

Sample Output
4
4
5
9
7

我没有思路,请各位赐教啊……
...全文
240 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
aliezeng77 2011-01-21
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 victor716 的回复:]
是不是先由轻到重排序,再从中找一条最长的越来越笨的数列
[/Quote]

yes
victor716 2011-01-21
  • 打赏
  • 举报
回复
是不是先由轻到重排序,再从中找一条最长的越来越笨的数列
lz3771 2011-01-20
  • 打赏
  • 举报
回复
顶所有的楼上
zyl072 2011-01-19
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 litaoye 的回复:]

排序后,用最长递减子序列就可以,n*log(n)
[/Quote]

正解。
另外,考虑到体重可能相同,体重相同时,智商低的应该排前面。这样在计算最长递减子序列时可以避免同体重的情况下,低智商的排在高智商的后面。
q200824960 2011-01-19
  • 打赏
  • 举报
回复
[Quote=引用楼主 sensssz 的回复:]
以下是原题:
Is Bigger Smarter
Some people think that the bigger an elephant is, the smarter it is. To disprove this, you want to take the data on a collection of elephants and put as large a subset of th……
[/Quote]

鄙视这样的人。
pmars 2011-01-18
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 litaoye 的回复:]

http://topic.csdn.net/u/20100424/22/7a7b4a50-9110-4cf8-96ec-7fa728593b15.html

引用 3 楼 sensssz 的回复:

就是找最长递减序列这一步不知道怎么做啊……
[/Quote]
看这个帖子4楼的讲述,应该就能明白了!
只是一个递减,一个递增罢了!

前提是,你得先给你的数据排序,排序的时候按照重量为主递增的话,就直接找IQ的递增,当让递减也是可以的!
pmars 2011-01-18
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 litaoye 的回复:]

http://topic.csdn.net/u/20100424/22/7a7b4a50-9110-4cf8-96ec-7fa728593b15.html

引用 3 楼 sensssz 的回复:

就是找最长递减序列这一步不知道怎么做啊……
[/Quote]
不讲究,给我的帖子翻出来了,
aliezeng77 2011-01-18
  • 打赏
  • 举报
回复
500 2000
1000 4000
1100 3000
2000 1900
6000 2100
6000 2000
6000 1200
6008 1300
8000 1400
FancyMouse 2011-01-17
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 sensssz 的回复:]
不是很懂……
[/Quote]
因为那里压根就没有记录解的过程,能懂反而就奇怪了
SENSSSZ 2011-01-17
  • 打赏
  • 举报
回复
啊……感谢……
绿色夹克衫 2011-01-17
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20100424/22/7a7b4a50-9110-4cf8-96ec-7fa728593b15.html

[Quote=引用 3 楼 sensssz 的回复:]

就是找最长递减序列这一步不知道怎么做啊……
[/Quote]
SENSSSZ 2011-01-17
  • 打赏
  • 举报
回复
就是找最长递减序列这一步不知道怎么做啊……
绿色夹克衫 2011-01-17
  • 打赏
  • 举报
回复
排序后,用最长递减子序列就可以,n*log(n)
df7009 2011-01-17
  • 打赏
  • 举报
回复
动态规划

33,008

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧