All about problems in Volume 100. If there is a thread about your problem, please use it. If not, create one with its number in the subject.
Moderator: Board moderators
Hisoka
Experienced poster
Posts: 120 Joined: Wed Mar 05, 2003 10:40 am
Location: Indonesia
Post
by Hisoka » Sun Apr 06, 2003 12:28 pm
I think your description is wrong.
Code: Select all
input
5 1 4 1 3 2
output
not jolly
I hope this will be help you.
timrau
New poster
Posts: 4 Joined: Wed Feb 12, 2003 5:00 pm
Post
by timrau » Tue Apr 08, 2003 1:57 pm
[c]#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int n;
int last,now;
int ta;
int ansed;
while(scanf("%d",&n)==1)
{
ansed=0;
scanf("%d",&last);
for(ta=2;ta<=n;ta++)
{
scanf("%d",&now);
if((!ansed) && ((abs(now-last)>=n) || now==last))
{
printf("Not jolly\n");
ansed=1;
}
last=now;
}
if(!ansed)
printf("Jolly\n");
}
return(0);
}[/c]
I don't understand why this got a WA.
Hisoka
Experienced poster
Posts: 120 Joined: Wed Mar 05, 2003 10:40 am
Location: Indonesia
Post
by Hisoka » Tue Apr 08, 2003 2:31 pm
Hey, why you not check your program with my sample I/O before you post your code? your program have same mistake with Nick program (cannot pass with my sample IO).
-HISOKA-
timrau
New poster
Posts: 4 Joined: Wed Feb 12, 2003 5:00 pm
Post
by timrau » Sat Apr 12, 2003 3:35 am
Hisoka wrote: Hey, why you not check your program with my sample I/O before you post your code? your program have same mistake with Nick program (cannot pass with my sample IO).
-HISOKA-
But...But I don't understand why your sample input is not "Jolly"?
Eric
Learning poster
Posts: 83 Joined: Wed Sep 11, 2002 6:28 pm
Location: Hong Kong
Post
by Eric » Sat Apr 12, 2003 6:32 am
The problem states that the differneces must map all the value between N-1 to 1.
But in the sample I/O from Hisoka, the differences are 3,3,2,1
which is different from the requirement of 4,3,2,1
So, it is not jolly. Do you get it?
Nick
Learning poster
Posts: 53 Joined: Sun Jan 12, 2003 4:49 am
Post
by Nick » Tue Apr 15, 2003 3:04 pm
Especially to Eric, thanks!!
I thought that as long as the numbers are between 1 and N-1, the sequence is Jolly, so there can be more than one same numbers.
But i was wrong, though I haven't try to fixed my code
JiaYun
New poster
Posts: 12 Joined: Thu May 01, 2003 4:27 am
Post
by JiaYun » Sat May 03, 2003 4:39 am
Input:
Your program will give 3 results:
Perhaps, this problem should be fixed first.
lendlice
New poster
Posts: 22 Joined: Thu Nov 21, 2002 10:50 am
Post
by lendlice » Sun May 25, 2003 3:04 pm
i got W.A
anyone can help me
thanks
[cpp]//10038
#include<stdio.h>
#include<math.h>
main()
{
int in[5000],many=0,i=0,count=0,ans;
while(scanf("%d",&many)==1)
{
for(i=0;i<many;i++)
scanf("%d",&in);
for(i=0;i<many-1;i++)
{
ans=fabs(in-in[i+1]);
if(ans>=1&&ans<many)
count++;
else
break;
}
if(count==many-1)
printf("Jolly\n");
else
printf("Not jolly\n");
count=0;
}
}[/cpp]
Amir Aavani
New poster
Posts: 30 Joined: Wed Oct 23, 2002 6:53 am
Post
by Amir Aavani » Sun Jun 01, 2003 5:40 am
hi lendlice
the problem say that the difference should take on all the values 1 through n-1.
but your program doesn't consider it.
for examle for the following input your program say Jolly in case it is n't really Jolly
3 1 2 3
Taneem
New poster
Posts: 6 Joined: Thu Jun 05, 2003 6:26 pm
Location: Arkansas, USA
Post
by Taneem » Sun Jun 22, 2003 4:43 am
Lendlice,
The problem states..."differences between successive elements take on
ALL possible values between 1 thru N-1. For example,
1 4 2 3 is "Jolly" because it takes the differences {3,2,1} which satisfies all the values between N-1 (=3) through 1.
Therefore, you must keep track of individual differences (hint: an array indexed with the differences will be a way to go).
Hope this helps
Give a man an answer, and he's satisfied today. Teach him to program, and he will be frustrated for the rest of his life. [Anonymous]
zsepi
Learning poster
Posts: 51 Joined: Thu Sep 26, 2002 7:43 pm
Location: Easton, PA, USA
Post
by zsepi » Sun Jun 22, 2003 12:27 pm
lendlice,
I think you might have misunderstood the problem, bacause you only check if the difference between two consecutive numbers is bigger than 0 and less than
many . Just to check out this input:
and obviously, it's not good.
you need to check if
all the differences take on all the values 1 through many-1
Dealing with failure is easy: Work hard to improve.
Success is also easy to handle: You've solved the wrong problem. Work hard to improve.
powerboy
New poster
Posts: 8 Joined: Mon May 12, 2003 6:13 am
Contact:
Post
by powerboy » Mon Jun 30, 2003 4:17 am
what is wrong with my program???
Anyone help me
[cpp]#include <iostream.h>
#include <stdlib.h>
int main()
{
int first = 0;
int second = 0;
int num;
bool * array;
bool flag = true;
while (cin >> num)
{
if (num > 1)
{
array = new bool[num];
int i;
for (i = 1; i <= num; i++)
{
array = false;
}
cin >> second;
for (i = 2; i <= num; i++)
{
first = second;
cin >> second;
if (abs(first - second) < num)
{
array[abs(first - second)] = true;
}
}
for (i = 1; i < num; i++)
{
if (!array)
{
cout << "Not jolly" << endl;
flag = false;
break;
}
}
if (flag)
cout << "Jolly" << endl;
flag = true;
}
else if (num == 1)
{
cin >> num;
}
}
return 0;
}[/cpp]
if11026
New poster
Posts: 3 Joined: Mon Jun 30, 2003 5:39 am
Contact:
Post
by if11026 » Fri Jul 11, 2003 6:53 am
Could anybody tell me what's wrong with my code ?
[c]
/* @JUDGE_ID: 10038 C */
#include <stdio.h>
#include <stdlib.h>
#define true 1
#define false 0
#define boolean unsigned int
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main()
{
boolean Jolly;
int jumdata,i;
int j,diff;
long data[3001];
long kurang[3000];
#ifndef ONLINE_JUDGE
close (0); open ("jump6.txt", O_RDONLY);
close (1); open ("jumpout6.txt", O_WRONLY | O_CREAT, 0600);
#endif
while (scanf("%d",&jumdata)== 1)
{
for (i = 0; i <= 3000; i++)
{
kurang = 0;
}
if ( jumdata == 1)
{
printf("Jolly\n");
}
else
{
for (i = 0; i< jumdata; i++)
{
scanf("%ld",&data);
}
Jolly = true;
i = 1;
while ((i < jumdata) && (Jolly))
{
diff = abs(data - data);
if ((diff > 0) && (diff < jumdata))
{
if (kurang[diff] == 1)
{
Jolly = false;
}
else
{
kurang[diff] = 1;
}
}
else
{
Jolly = false;
}
i++;
}
if (Jolly)
{
printf("Jolly\n");
}
else
{
printf("Not Jolly\n");
}
}
}
return 0;
}
[/c]
turtleking
New poster
Posts: 1 Joined: Sat Jul 19, 2003 7:08 am
Post
by turtleking » Sat Jul 19, 2003 7:12 am
Code: Select all
#include <stdio.h>
int abs(int value)
{
if (value>=0)
{return value;}
else
{return -value;}
}
void jolly(int series[4000],int inputnum)
{
int i,j;
int jolly=0;
int abs_value;
int temp[4000];
for(i=0;i<(inputnum-1);i++)
{
abs_value = abs(series[i]-series[i+1]);
if ((abs_value<=(inputnum-1) )&&(abs_value>=0))
{
for(j=1;j<inputnum;j++)
{
if (abs_value == j)
{temp[j]=1;}
}
}
}
for(i=1;i<inputnum;i++)
{
if (temp[i]!=1)
{
jolly=1;
}
}
if (!jolly)
{
printf("Jolly\n");
}
else
{
printf("Not jolly\n");
}
}
void main(void)
{
int inputnum,i;
int series[4000];
while(scanf("%d",&inputnum)==1)
{
for(i=0;i<inputnum;i++)
{
scanf("%d",&series[i]);
}
jolly(series,inputnum);
}
}
can anyone tell me what's wrong with my code?[/code]
Joseph Kurniawan
Experienced poster
Posts: 136 Joined: Tue Apr 01, 2003 6:59 am
Location: Jakarta, Indonesia
Post
by Joseph Kurniawan » Sat Jul 26, 2003 10:32 am
You should make all the integers stored in array temp zero after you use the function jolly.
[c]for(j=1;j<inputnum;j++)
{
if (abs_value == j)
{temp[j]=1;}
}
[/c]
This will make the integer in temp[j] one.