497 - Strategic Defense Initiative

All about problems in Volume 4. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
hankkuo
New poster
Posts: 1
Joined: Fri Nov 09, 2001 2:00 am

Post by hankkuo » Fri Nov 09, 2001 10:50 am

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>

junjieliang
Experienced poster
Posts: 169
Joined: Wed Oct 31, 2001 2:00 am
Location: Singapore

Post by junjieliang » Thu Nov 29, 2001 3:58 am

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.

junjieliang
Experienced poster
Posts: 169
Joined: Wed Oct 31, 2001 2:00 am
Location: Singapore

Post by junjieliang » Mon Dec 17, 2001 7:51 am

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.

cyfra
Experienced poster
Posts: 144
Joined: Thu Nov 22, 2001 2:00 am
Location: Gdynia, Poland

Post by cyfra » Thu Dec 27, 2001 2:59 pm

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!!!

junjieliang
Experienced poster
Posts: 169
Joined: Wed Oct 31, 2001 2:00 am
Location: Singapore

Post by junjieliang » Fri Dec 28, 2001 6:04 am

It's multiple input!

cyfra
Experienced poster
Posts: 144
Joined: Thu Nov 22, 2001 2:00 am
Location: Gdynia, Poland

Post by cyfra » Fri Dec 28, 2001 1:00 pm

Thanx.

I go P.E. (it is better than W.A)

Thanks a lot :smile:

C8H10N4O2
Experienced poster
Posts: 137
Joined: Wed Feb 27, 2002 2:00 am
Location: Pasadena, CA

Post by C8H10N4O2 » Fri Mar 29, 2002 1:48 am

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]);
		}
	}
}

cyfra
Experienced poster
Posts: 144
Joined: Thu Nov 22, 2001 2:00 am
Location: Gdynia, Poland

Post by cyfra » Fri Mar 29, 2002 10:33 am

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 :smile:

C8H10N4O2
Experienced poster
Posts: 137
Joined: Wed Feb 27, 2002 2:00 am
Location: Pasadena, CA

Post by C8H10N4O2 » Fri Mar 29, 2002 6:32 pm

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.

chang
New poster
Posts: 16
Joined: Wed Jan 16, 2002 2:00 am

Post by chang » Sun Apr 07, 2002 10:34 am

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...

C8H10N4O2
Experienced poster
Posts: 137
Joined: Wed Feb 27, 2002 2:00 am
Location: Pasadena, CA

Post by C8H10N4O2 » Sun Apr 14, 2002 3:45 pm

How would the strlen help? I break the loop if the scanf fails. So, shouldn't that take care of it?

sjn
Learning poster
Posts: 73
Joined: Mon Apr 08, 2002 8:22 am
Contact:

p497

Post by sjn » Wed May 22, 2002 10:56 am

I got WA for this problem, i don't know why ...
My source code should be OK, it works perfectly ...


pls help... :roll:
Last edited by sjn on Mon Feb 02, 2004 5:51 pm, edited 2 times in total.

Fresh
New poster
Posts: 46
Joined: Mon Apr 15, 2002 10:42 am
Contact:

so many source code posted

Post by Fresh » Wed May 22, 2002 11:23 am

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? :evil:
-novice :-?

Caesum
Experienced poster
Posts: 225
Joined: Fri May 03, 2002 12:14 am
Location: UK
Contact:

Post by Caesum » Wed May 22, 2002 6:25 pm

why are you reading and writing to files?

sjn
Learning poster
Posts: 73
Joined: Mon Apr 08, 2002 8:22 am
Contact:

Post by sjn » Thu May 23, 2002 7:15 am

to:Caesum

when i submit ,i'll delete the following:

assign(input,'input.txt');
reset(input);
assign(output,'output.txt');
rewrite(output);

Post Reply

Return to “Volume 4 (400-499)”