早教吧作业答案频道 -->其他-->
杭电acm1160一直runtimeerrorProblemDescriptionFatMousebelievesthatthefatteramouseis,thefasteritruns.Todisprovethis,youwanttotakethedataonacollectionofmiceandputaslargeasubsetofthisdataaspossibleintoasequen
题目详情
杭电acm1160 一直runtime error
Problem Description
FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the speeds are decreasing.
Input
Input contains data for a bunch of mice, one mouse per line, terminated by end of file.
The data for a particular mouse will consist of a pair of integers: the first representing its size in grams and the second representing its speed in centimeters per second. Both integers are between 1 and 10000. The data in each test case will contain information for at most 1000 mice.
Two mice may have the same weight, the same speed, or even the same weight and speed.
Output
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 a mouse). If these n integers are m[1], m[2],..., m[n] then it must be the case that
W[m[1]] < W[m[2]] < ... < W[m[n]]
and
S[m[1]] > S[m[2]] > ... > S[m[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 speeds must be strictly decreasing. There may be many correct outputs for a given input, your program only needs to find one.
Sample Input
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
#include
#include
using namespace std;
struct speed
{
int w;
int s;
int num;
}a[1003];
bool cmp(speed a,speed b)
{
if(a.w!=b.w)
return a.w>b.w;
else
return a.s
Problem Description
FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a subset of this data as possible into a sequence so that the weights are increasing, but the speeds are decreasing.
Input
Input contains data for a bunch of mice, one mouse per line, terminated by end of file.
The data for a particular mouse will consist of a pair of integers: the first representing its size in grams and the second representing its speed in centimeters per second. Both integers are between 1 and 10000. The data in each test case will contain information for at most 1000 mice.
Two mice may have the same weight, the same speed, or even the same weight and speed.
Output
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 a mouse). If these n integers are m[1], m[2],..., m[n] then it must be the case that
W[m[1]] < W[m[2]] < ... < W[m[n]]
and
S[m[1]] > S[m[2]] > ... > S[m[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 speeds must be strictly decreasing. There may be many correct outputs for a given input, your program only needs to find one.
Sample Input
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
#include
#include
using namespace std;
struct speed
{
int w;
int s;
int num;
}a[1003];
bool cmp(speed a,speed b)
{
if(a.w!=b.w)
return a.w>b.w;
else
return a.s
▼优质解答
答案和解析
1 while 循环结束条件错误.
2 判断条件错误
if(b[i]=max-1&&a[h].s>a[i].s&&a[h].wb.w;
else
return a.s
2 判断条件错误
if(b[i]=max-1&&a[h].s>a[i].s&&a[h].wb.w;
else
return a.s
看了 杭电acm1160一直run...的网友还看了以下:
已知集合A={x|x=3n+1,n∈Z},B={x|x=3n+2,n∈Z},M={x|x=6n+3 2020-04-05 …
定义集合A*B={x|x∈A且x不属于B},若A={1,3,5,7},B={2,3,5},则: ( 2020-05-15 …
已知集合A={m,n/m,1},集合B={m²,m+n,0},若A=B,则()已知集合A={m,n 2020-05-16 …
2/8+3/8+7/16+15/32+……+511/1024怎么用裂项公式计算,计算中=(1/2- 2020-07-16 …
m为偶数,则(a-b)^m·(b-a)^m+n(a≠b)的结果是A.相等B.互为相反数C.不相等D 2020-07-20 …
已知两条不重合的直线m,n两个不重合的平面a,b给出下列命题①若m⊥a,n⊥b且m⊥n则a⊥b②若m 2020-11-02 …
关于直线a,b,l以及平面M,N,下面命题中正确的是()A.若a∥M,b∥M,则a∥bB.若a∥M, 2020-11-02 …
a,b,c表示直线,M表示平面,给出下列四个命题:①若a∥M,b∥M,则a∥b;②若b⊂M,a∥b, 2020-11-02 …
因式分解急!1.a(m+n)-b(m+n)⒉xy(a-b)+x(a-b)3.n(x+y)+x+y⒋a 2020-11-03 …
这步是如何得来的?已知集合A={1,3,根号M},B={1,m},A∪B=A,则m=()(A)0或根 2020-12-02 …