Page 1 of 10
Posted: Fri Nov 09, 2001 10:50 am
by hankkuo
I always got a runtime error in 497.
The problem is a multiple input.
Although I read the help very carefully, I
still can't understand what I should do for
reading the input.
I got a confused for a long time.
I don't know what result in this reply.
Is it cause by reading??
or others??
Thx!!
<font size=-1>[ This Message was edited by: hankkuo on 2001-11-09 09:51 ]</font>
Posted: Thu Nov 29, 2001 3:58 am
by junjieliang
I met with some problems while solving this problems too. Is there any trick in the test cases? Also, is the input file in this format?
2
1
2
3
2
3
1
-END-
Thanks.
Posted: Mon Dec 17, 2001 7:51 am
by junjieliang
Try using C if you are using Pascal. Don't ask me why, but my pascal solution will NOT get accepted by the Judge. Anyway, for those who are still not clear about the input format, it's like this:
-START-
2
1
6
2
3
5
1
3
2
4
-END-
Output should be quite obvious, so I won't put it here.
Posted: Thu Dec 27, 2001 2:59 pm
by cyfra
Hi
I have no idea why i have WA.
Could anyone help me???Program p497;
VAR
stos,tab,wynik,pop:array[1..8000] of integer;
wys,max,maxx,y,ilosc,x:longint;
begin
x:=0;
repeat
x:=x+1;
readln(tab[x]);
until eof;
ilosc:=x;
for x:=1 to ilosc do wynik[x]:=1;
for x:=1 to ilosc do pop[x]:=-1;
for x:=2 to ilosc do
begin
for y:=1 to x-1 do
begin
if tab[x]>=tab[y] then
begin
if wynik[y]+1>wynik[x] then
begin
wynik[x]:=wynik[y]+1;
pop[x]:=y;
end;
end;
end;
end;
max:=0;
maxx:=0;
for x:=1 to ilosc do
begin
if wynik[x]>max then
begin
max:=wynik[x];
maxx:=x;
end;
end;
Writeln('Max hits: ',max);
wys:=0;
repeat
wys:=wys+1;
stos[wys]:=tab[maxx];
maxx:=pop[maxx];
until maxx=-1;
for x:=wys downto 1 do Writeln(stos[x]);
end.
I have no idea????
Please help!!!
Posted: Fri Dec 28, 2001 6:04 am
by junjieliang
It's multiple input!
Posted: Fri Dec 28, 2001 1:00 pm
by cyfra
Thanx.
I go P.E. (it is better than W.A)
Thanks a lot

Posted: Fri Mar 29, 2002 1:48 am
by C8H10N4O2
I think my DP is correct. Can someone tell me why this code is WA? Thanks:o)
Code: Select all
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
void main()
{
int i,j,k,N,Z,z,BL,BP;
char B[100];
vector<int> D,L,P,R;
scanf("%dnn",&Z);
for(z=0;z<Z;z++)
{
if(z>0)
printf("n");
D.clear();
while(gets(B)!=NULL)
{
if(sscanf(B,"%d",&N)!=1)
{
break;
}
else
{
D.push_back(N);
}
}
L=vector<int>(D.size(),-1);
P=L;
L[0]=1;
P[0]=-1;
for(i=1;i<D.size();i++)
{
BL=1;
BP=-1;
for(j=0;j<i;j++)
{
if(D[j]<D[i])
{
BL=L[j]+1;
BP=j;
}
}
L[i]=BL;
P[i]=BP;
}
j=max_element(L.begin(),L.end())-L.begin();
printf("Max hits: %dn",L[j]);
R.clear();
k=L[j];
while(k>0)
{
R.push_back(D[j]);
k--;
j=P[j];
}
reverse(R.begin(),R.end());
for(i=0;i<R.size();i++)
{
printf("%dn",R[i]);
}
}
}
Posted: Fri Mar 29, 2002 10:33 am
by cyfra
Hi!
It is strange...
I have tested it but I couldn't find any mistake on my tests....
Maybe threre is something wrong with vectors...
Try to use normal table...
Good Luck

Posted: Fri Mar 29, 2002 6:32 pm
by C8H10N4O2
It gives me Wrong Answer not SIGSEV or some other wierd thing:P There must be some borderline case? I will try it with arrays and see.
Posted: Sun Apr 07, 2002 10:34 am
by chang
I suggest u to change a single line as follows:
while ( gets(B) && strlen(B) > 0 )
instead of
while ( gets(B) != NULL )
Hope u'll get it AC...
Posted: Sun Apr 14, 2002 3:45 pm
by C8H10N4O2
How would the strlen help? I break the loop if the scanf fails. So, shouldn't that take care of it?
p497
Posted: Wed May 22, 2002 10:56 am
by sjn
I got WA for this problem, i don't know why ...
My source code should be OK, it works perfectly ...
pls help...

so many source code posted
Posted: Wed May 22, 2002 11:23 am
by Fresh
Did you read the problem carefully? Dont just post the code and ask why, why, why and why...
.. wrote:In these days, the board is full of source code....
Why do the people just hope others to debug for them?

-novice

Posted: Wed May 22, 2002 6:25 pm
by Caesum
why are you reading and writing to files?
Posted: Thu May 23, 2002 7:15 am
by sjn
to:Caesum
when i submit ,i'll delete the following:
assign(input,'input.txt');
reset(input);
assign(output,'output.txt');
rewrite(output);