Page 10 of 93
Posted: Tue Sep 24, 2002 8:18 am
by mklein49
oops
Posted: Tue Sep 24, 2002 8:19 am
by mklein49
Wouldn't this,
[cpp]while(!(cin.eof()))
{
cin >> i >> j;[/cpp]
workt the same as
[cpp]while(cin >> i >> j)[/cpp]
Posted: Tue Sep 24, 2002 8:27 am
by mklein49
Well, you were right. I made the correction and the program was accepted.
..
Posted: Tue Sep 24, 2002 5:13 pm
by soyoja
Some problems are test a few input data. If these problem need
simple algorithm or low time complexity solution, then these
problem's run times are extremely fast. So I think that 0.000 sec
is a possible time. But I also know that some people can cheat
their code. -_-;
As I believe..
Posted: Wed Sep 25, 2002 5:56 am
by Whinii F.
As I know, they work differently since eof() functions (including feof() in C) return true AFTER they have REACHED the actual end of file. So, we need to access the end-of-file location by trying to read. THEN the eof() functions will return true..
Try a little code for each one, and you'll get it..[/cpp]
what's problem in my code?? (100)
Posted: Sun Sep 29, 2002 1:18 am
by makefriend8
@begin_of_source_code
/* @JUDGE_ID: 22306NP 100 C++ */
#include<iostream.h>
unsigned int i,j;
unsigned int index[1000001];
int cacu(unsigned int k)
{
unsigned int s=k;
if(s==1)return 1;
int num=0;
while(1)
{
if(s<k)
{
return (index[s]+num);
}
if(s%2==1){s=3*s+1;num++;}
else if(s%2==0){s=s/2;num++;}
}
}
void init()
{
int unsigned k1;
for(k1=1;k1<=1000000;k1++)
{
index[k1]=cacu(k1);
}
cout<<index[55]<<endl;
}
void mywork()
{
unsigned int k1,k2,sum=0;;
for(k1=i;k1<=j;k1++)
{
k2=index[k1];
if(sum<k2)sum=k2;
}
cout<<i<<" "<<j<<" "<<sum<<endl;
}
int main()
{
init();
while(cin>>i>>j)
{
if(i>j)
{
int temp=i;i=j;j=temp;
}
mywork();
}
return 0;
}
@end_of_source_code
3n+1 problem
Posted: Tue Oct 01, 2002 4:54 am
by pahmed
every time i send this program, judge rely that " Wrong Answer". But it run correctly in my computer.can any one tell me what is the problem?
/*@judge_id: 22085KW 100 C */
#include<stdio.h>
int A(unsigned long int x);
void main()
{
int p,i,j,max=0,g,iReal,jReal;
scanf("%d %d\n",&i,&j);
iReal=i;jReal=j;
if (i>j)
{g=i;i=j;j=g;}
for (g=i;g<j+1;g++)
{
p=A(g);
if (p>max) max=p;
}
printf("%d %d %d\n",iReal,jReal,max);
}
int A(unsigned long int x)
{
int q=0;
an:
if (x==1){q++;return q;}
else if(x%2==1)
{x=3*x+1;q++;goto an;}
else
{x=x/2;q++;goto an;}
}
/*@end_of_source_code*/
Posted: Tue Oct 01, 2002 8:06 am
by Dominik Michniewski
Why do you have such line in your code ?
in init function ?? In my opinion this may cause error ....
Best regards
Dominik
Posted: Tue Oct 01, 2002 10:45 am
by turuthok
Well, your code seems to handle only one test-case ...
-turuthok-
Posted: Tue Oct 01, 2002 10:55 am
by turuthok
Don't forget when you already handle >1 test-case, print a new-line after the result of each test-case.
-turuthok-
Can someone help me??
Posted: Thu Oct 03, 2002 10:47 am
by fOOd_aCe
Well I don't know how to stop the cicle the gets the input. I've tried this but it doesn't seem to work.
[c]while(scanf(" %ld %ld", &i[n] &j[n]) == 2)
{
n++;
}
[/c]
I'd apreciate some help... Thanx[/c]
Posted: Thu Oct 03, 2002 12:37 pm
by Adil
hello there fOOd_aCe. about your code,
initialize n=0 at the start, and of course, put a comma between &i[n] and &j[n].
Posted: Thu Oct 03, 2002 12:41 pm
by Dominik Michniewski
it should work ....
BTW I use scanf("%d %d" ..... without any leading spaces ....
your construction is very good and optimal for C - scanf returns number of successfully readed fields, also if you read 2 fields and got value of 2 as scanf'sreturn - it's correct.... in any other case you terminate loop statement ....
Best regards
Dominik
Problem 100 Help
Posted: Thu Oct 03, 2002 9:34 pm
by Rob Ferguson
Why does the judge tell me its the wrong answer. (Your program has not solved the problem. It ran during 4.820 seconds.) I get correct answers in Visual C++. Does anyone have any suggestions on how to correct my problem?
Thanks,
Rob
[cpp]
/* @JUDGE_ID: XXXXXX 100 C++ */
@BEGIN_OF_SOURCE_CODE
#include <iostream>
using namespace std;
int main() {
register long int n,i,j,k,l,c;
while(cin >> i >> j) {
if(i>j) {
k=i;i=j;j=k;
}
l=0;
k=i;
for (k;k<=j;k++) {
n=k;
c=0;
while (1) {
c++;
if (n==1) {
break;
}
if (n%2==1) {
n=(3*n)+1;
} else {
n/=2;
}
}
if (c>l) {
l=c;
}
}
cout << i << " " << j << " " << l << endl;
}
return 0;
}
@END_OF_SOURCE_CODE[/cpp]
Posted: Thu Oct 03, 2002 11:43 pm
by turuthok
Most of the times, the Online Judge is the one who's correct ...
Hint: Please read the first sentence on the "The Output" section.
-turuthok-