756 - Biorhythms
Moderator: Board moderators
-
- New poster
- Posts: 2
- Joined: Sun May 05, 2002 10:12 am
- Location: Guangzhou, China
- Contact:
756 - Biorhythms
I got wrong answers. Would you please tell me why?
[pascal]
{$E+,I-,N+,Q-,R-,S-}
var
a,b,c,d,s:longint;
ccase:longint;
begin
ccase:=0;
repeat
ccase:=ccase+1;
read(a,b,c,d);
if a+b+c+d=-4 then exit;
a:=a mod 23;
b:=b mod 28;
c:=c mod 33;
s:=a*28*33*6+b*23*33*19+c*23*28*2;
if s>=23*28*33 then s:=s mod (23*28*33);
if s<=d then s:=s+23*28*33;
writeln('Case ',ccase,': the next triple peak occurs in ',s-d,' days.');
until false;
end.[/pascal]
[pascal]
{$E+,I-,N+,Q-,R-,S-}
var
a,b,c,d,s:longint;
ccase:longint;
begin
ccase:=0;
repeat
ccase:=ccase+1;
read(a,b,c,d);
if a+b+c+d=-4 then exit;
a:=a mod 23;
b:=b mod 28;
c:=c mod 33;
s:=a*28*33*6+b*23*33*19+c*23*28*2;
if s>=23*28*33 then s:=s mod (23*28*33);
if s<=d then s:=s+23*28*33;
writeln('Case ',ccase,': the next triple peak occurs in ',s-d,' days.');
until false;
end.[/pascal]
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
756 - Biorythms .....
Could anyone tell me what's wrong with this algorithm ?
I don't talk about eficiency of this algorithm, because it's poor
but about cases in which these code doesn't work ... I can't find such one ....
Please help!!!
Dominik Michniewski
Code: Select all
#include <stdio.h>
#define MAX 21300
char days[MAX];
int main(void)
{
int i,n,N,P,E,I,d,c;
scanf("%d",&N);
for(n=0;n<N;n++)
{
c = 1;
while(scanf("%d %d %d %d",&P,&E,&I,&d) == 4)
{
if((P == -1) && (E == -1) && (I == -1) && (d == -1)) break;
for(i=0;i<MAX;i++) days[i] = 0;
for(i=P;i<MAX;i+=23) days[i]++;
for(i=P-23;i>0;i-=23) days[i]++;
for(i=E;i<MAX;i+=28) days[i]++;
for(i=E-28;i>0;i-=28) days[i]++;
for(i=I;i<MAX;i+=33) days[i]++;
for(i=I-33;i>0;i-=33) days[i]++;
for(i=d+1;i<MAX;i++) if(days[i] == 3) break;
if(i > 21252) i = d + 21252;
printf("Case %d: the next triple peak occurs in %d days.\n",
c++,i-d);
}
if(n < N-1) printf("\n");
}
return 0;
}

Please help!!!
Dominik Michniewski
-
- Guru
- Posts: 834
- Joined: Wed May 29, 2002 4:11 pm
- Location: Wroclaw, Poland
- Contact:
-
- New poster
- Posts: 12
- Joined: Sun Jun 01, 2003 12:21 pm
- Location: Pune, India
756 Biorhythms
Can't imagine why I get WA. Some nice test cases may help if you can't point out my mistake...... Please help me out oh brainy ones.
Code: Select all
#include<iostream.h>
main()
{
int p,e,i,d,z,count=1,cases;
for(cin >> cases;cases--;){
while(1)
{
cin>>p>>e>>i>>d;
if(p==-1) break;
p = p % 23;
e = e % 28;
i = i % 33;
z = (d/33*33)+i;
if(z==d) z+=33;
for(;z<=21252;z+=33)
if (z%23==p && z%28==e) break;
cout<<"Case "<<count<<": the next triple peak occurs in "
<<(z-d)<<" days.\n";
count++;
}count=1;cout << "\n";
}
}
Your program produces wrong output for this input:
[c]
1
210 44 270 348
152 37 4 148
365 290 231 89
-1 -1 -1 -1
[/c]
The output should be:
[c]
Case 1: the next triple peak occurs in 20976 days.
Case 2: the next triple peak occurs in 21141 days.
Case 3: the next triple peak occurs in 21229 days.
[/c]
I also saw that you print an empty line after the last case, which is probably not WA, but at least PE.
Best regards
--
hager
[c]
1
210 44 270 348
152 37 4 148
365 290 231 89
-1 -1 -1 -1
[/c]
The output should be:
[c]
Case 1: the next triple peak occurs in 20976 days.
Case 2: the next triple peak occurs in 21141 days.
Case 3: the next triple peak occurs in 21229 days.
[/c]
I also saw that you print an empty line after the last case, which is probably not WA, but at least PE.
Best regards
--
hager
-
- New poster
- Posts: 12
- Joined: Sun Jun 01, 2003 12:21 pm
- Location: Pune, India
Problem Accepted with P.E.
Thanks a lot for the test cases. A little investigation reavealed
Also, even the extra line that you had mention gave me a WA. However even after I removed that, I got PE.......gotta look into that, but who cares ?
Thanks again !
I had assumed 21252 days from beginning of year.you may assume that a triple peak will occur within 21252 days of the given date.
Also, even the extra line that you had mention gave me a WA. However even after I removed that, I got PE.......gotta look into that, but who cares ?

Thanks again !
I wanted to change the world, but they didn't give me the source code.
Excuse me, can anyone tell me why the method above works?
'cos I can only think of the "try-it-all" approach (I used it and got ACC in 0.14 s. Not a very good time, of course
)
'cos I can only think of the "try-it-all" approach (I used it and got ACC in 0.14 s. Not a very good time, of course

7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
-
- Experienced poster
- Posts: 147
- Joined: Fri Jun 13, 2003 10:46 pm
756 Biorythms Pascal
The program reproduces all output as it should be, following the posts.
Nevertheless I still get WA.
It would be very nice if somebody could tell me why. I'm rather sure
it's a silly mistake, but I can't find it.
Thanks
Added: I'm off for three weeks so there won't be any replies during
that period.
Addes (years later): It's not a multiple input problem anymore?!
Nevertheless I still get WA.
It would be very nice if somebody could tell me why. I'm rather sure
it's a silly mistake, but I can't find it.
Thanks
Added: I'm off for three weeks so there won't be any replies during
that period.
Addes (years later): It's not a multiple input problem anymore?!
Last edited by WR on Tue Apr 12, 2005 9:11 am, edited 1 time in total.
-
- New poster
- Posts: 38
- Joined: Mon Dec 09, 2002 1:53 pm
- Location: Poznan, Poland
Re: 756 Biorythms Pascal
It's a multiple input problem.WR wrote:The program reproduces all output as it should be, following the posts.
Nevertheless I still get WA.
Re: 756 - Biorythms .....
MAX should be at least 21252+365=21617Dominik Michniewski wrote:Could anyone tell me what's wrong with this algorithm ?
Code: Select all
#include <stdio.h> #define MAX 21300
Since you can assume that the peak will occur within 21252 days of the given date, you can omit the checkDominik Michniewski wrote:I don't talk about eficiency of this algorithm, because it's poorCode: Select all
if(i > 21252) i = d + 21252; printf("Case %d: the next triple peak occurs in %d days.\n", c++,i-d);
but about cases in which these code doesn't work ... I can't find such one ....
Please help!!!
Dominik Michniewski
Code: Select all
if(i>21252)
Code: Select all
if(i>d+21252)
Ciao!!!
Claudio
Re: 756 Biorythms Pascal
Multiple input means there's more than input line? The programszymcio2001 wrote:It's a multiple input problem.WR wrote:The program reproduces all output as it should be, following the posts.
Nevertheless I still get WA.
should handle that. Or is there a misconception of multiple input
on my side?!
Re: 756 Biorythms Pascal
Multiple input means that the program must process a set of inputs.WR wrote:Multiple input means there's more than input line? The programszymcio2001 wrote:It's a multiple input problem.
should handle that. Or is there a misconception of multiple input
on my side?!
Here is the relevant link:
http://online-judge.uva.es/portal/modul ... ?id=minput
Ciao!!!
Claudio
756 - Biorhythm
Could anybody please tell me what's wrong with this program?
I suppose the program now handles multiple input?! It didn't
before, but even now it's a WA.
CODE removed.
Thanks to UFP2161 (see below) I'm sure the program now will be accepted.
I suppose the program now handles multiple input?! It didn't
before, but even now it's a WA.
CODE removed.
Thanks to UFP2161 (see below) I'm sure the program now will be accepted.
Last edited by WR on Fri Jan 16, 2004 8:47 am, edited 1 time in total.