10454 - Trexpression

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

Moderator: Board moderators

ChristopherH
New poster
Posts: 31
Joined: Sun Feb 23, 2003 9:18 pm
Location: Waterloo, Ontario, Canada

10454 - Trexpression

Post by ChristopherH »

Update Feb 27: Please disregard this message. I made an error in my data-checking program. I apologise. Original message follows:

A (hopefully helpful) note for those frustrated with Trexpressions:

Contrary to the problem spec, the judging data contains characters other than those specified in the problem, including whitespace.

Be conservative in your input routines (ie don't use cin >> string).

It's unfortunate that one has to have an AC solution in hand before one can test for these infelicities. Note Feb 27: of course this claim is incorrect too -- one gets RTE before WA.
Last edited by ChristopherH on Thu Feb 27, 2003 7:38 pm, edited 1 time in total.
kzaman010
Problemsetter
Posts: 18
Joined: Wed Jan 16, 2002 2:00 am
Location: Bangladesh
Contact:

Trexpression

Post by kzaman010 »

There is no WHITESPACE in the JUDGE data.
And there is also no other characters
except that specified in the problem statement.

JUDGE SOLUTION HAS ALSO USED " scanf() " which does not deal
with WHITE SPACE and also there is no
BLANK LINE in the input file.

So check carefully, what mistakes you have done.
ChristopherH
New poster
Posts: 31
Joined: Sun Feb 23, 2003 9:18 pm
Location: Waterloo, Ontario, Canada

Post by ChristopherH »

I apologise. You are correct, there is no whitespace.

I wrote a RTE-on-bad-data checking program, but I made an error in doing so and it spuriously reported a problem. I was attempting to help a friend decipher a WA.

Regards,
Christopher
ChristopherH
New poster
Posts: 31
Joined: Sun Feb 23, 2003 9:18 pm
Location: Waterloo, Ontario, Canada

Post by ChristopherH »

Update: I just performed another test, using the following program:

[cpp]
void rte() {
for (int *p = reinterpret_cast<int *>(1); ; p++) *p = 0xDEADBEEF;
}

int main(int argc, char *argv[]) {
char line[150], *p;
char c = '\n', nc;
int pl = 0;
while ((nc = getchar()) != EOF) {
c = nc;
}
if (c != '\n') rte();
return 0;
}
[/cpp]

And verified that the final line of the judging data does not end with a newline.

This will cause errors for people using getline(cin, string).

Such a text file may be considered valid in a Windows environment, but would not be considered canonical in a UNIX environment. I strongly suggest that UVA judging data include a final newline.
User avatar
cytse
Learning poster
Posts: 67
Joined: Mon Sep 16, 2002 2:47 pm
Location: Hong Kong
Contact:

Post by cytse »

i used the following to read input
[cpp]
string s;
while (getline(cin,s)) {
...
}
[/cpp]

and the program got AC. What is the problem?
ChristopherH
New poster
Posts: 31
Joined: Sun Feb 23, 2003 9:18 pm
Location: Waterloo, Ontario, Canada

Post by ChristopherH »

That should have read: problems for people using cin.eof().
You're right, getline works okay if you test it that way.
Shahriar Nirjon
New poster
Posts: 16
Joined: Tue Dec 03, 2002 9:44 pm

Post by Shahriar Nirjon »

<^7

I've got AC after changing the input taking style.
Most possibly the file does not contain a newline at the last
line of file. So I checked it like this_

[cpp]


int main()
{
unsigned long long r;
char t[256];
//freopen("del.txt", "r", stdin);
setF( :o );

while(1)
{
scanf("%s", t);
if(feof(stdin) && t[0]==0)break;
r = eval(t);
printf("%llu\n", r);
t[0] = 0;
}
return 20;
}


[/cpp]
..
A great helper
Posts: 454
Joined: Thu Oct 18, 2001 2:00 am
Location: Hong Kong

10454 - WA :(

Post by .. »

Could anyone kindly give me the output?

1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1*1+1+1+1+1+1+1+1+1+1*1+1+1+1+1+1+1+1+1+1
1+1+1+1+1+1+1*1+1+1+1+1+1*1+1+1+1+1+1*1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1
1+1+1+(1+1*1+1+1+1+1+1*1+1+1)+1+1+1*1+1+1+1+1+(1)+1+1+1+(1+1+1+1)+1+1+1+1
(1+(1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1))
(1+(1+(1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1)))

I checked the board and know that the input may miss a newline at the last line. Can anyone tell if reading input in this way is ok or not?? Thanks!

Code: Select all

while(scanf("%s", str) == 1) {
.............
}
My signature:
  • Please make discussion about the algorithm BRFORE posting source code.
    We can learn much more in discussion than reading source code.
  • I HATE testing account.
  • Don't send me source code for debug.
Per
A great helper
Posts: 429
Joined: Fri Nov 29, 2002 11:27 pm
Location: Sweden

Post by Per »

My solution outputs:

Code: Select all

3116285494907301262
212336130412243110
55534064877048198
12635931808500
812944042149730764
212336130412243110
About input: it should be ok, since the input has no whitespace (other than newline), but I used cin+getline, so I can't promise. :)
..
A great helper
Posts: 454
Joined: Thu Oct 18, 2001 2:00 am
Location: Hong Kong

Post by .. »

Thanks Austrin!
I found the stupid bug in my code~~
My signature:
  • Please make discussion about the algorithm BRFORE posting source code.
    We can learn much more in discussion than reading source code.
  • I HATE testing account.
  • Don't send me source code for debug.
helmet
New poster
Posts: 31
Joined: Tue Mar 02, 2004 11:55 am

10454 WA

Post by helmet »

I am getting WA for this problem and I think I am making a mistake in the base case/tricky cases.

I would appreciate some test cases plz.

Also could someone verify the input-output for these

Input:

Code: Select all

1+1+1+1+2*2+1*2*2*2+1+1+1+1*2+1
((((((1+2))))))
1*1*1*1*1*1*1*1*1
(1*1*1*1)*(1*1*1*1*1)
1+1+1*1+1+1*1+1+1*(1+1+1+1+1)
Output:

Code: Select all

83980
1
1430
70
1848
Any advice anyone?I cant find any other thread about this problem :(.
Just another brick in the wall...
..
A great helper
Posts: 454
Joined: Thu Oct 18, 2001 2:00 am
Location: Hong Kong

Post by .. »

I get the same output.
My signature:
  • Please make discussion about the algorithm BRFORE posting source code.
    We can learn much more in discussion than reading source code.
  • I HATE testing account.
  • Don't send me source code for debug.
helmet
New poster
Posts: 31
Joined: Tue Mar 02, 2004 11:55 am

Post by helmet »

So what could be a problem?

Without revealing much about my solution let me just say that my answer is the product of several subproblems all of which are somehow based on catalan numbers.

Any overflow problems?
Just another brick in the wall...
..
A great helper
Posts: 454
Joined: Thu Oct 18, 2001 2:00 am
Location: Hong Kong

Post by .. »

My program only use add and multiplcation, I use long long to store all the (intermediate) numbers.
If your program used division, then you need to be careful if any overflow of intermediate numbers.
My signature:
  • Please make discussion about the algorithm BRFORE posting source code.
    We can learn much more in discussion than reading source code.
  • I HATE testing account.
  • Don't send me source code for debug.
helmet
New poster
Posts: 31
Joined: Tue Mar 02, 2004 11:55 am

Post by helmet »

I dont use division anywhere.

Could you gimme some good sample ip and op?(something which can hopefully find my bug...:( )

Thanks in advance...
Just another brick in the wall...
Post Reply

Return to “Volume 104 (10400-10499)”