545  Heads
Moderator: Board moderators
545 WA  474 AC Who can help me???
Pls. tell me what's wrong with my code. I get WA but for 474 problem I got AC
I modified the code so it round the result now, that means that for n=6 I obtain 1.563E2, and for n=7 => 7.813E3...
[cpp]
#include <stdio.h>
#include <math.h>
main()
{ long n;
double u,a,l2;
long b;
l2=log10((double)2);
while(scanf("%ld",&n)==1)
{
printf("2^%ld = ",n);
b=(long int)ceil((double)n*l2);
a=pow(2, b/l2n);
u=((long int)(a*1000))/1000.0;
u=(au)*10000;
n=ceil(u);
a=(long int) (a*1000);
if (n>=5) a=a+1;
a=a/1000;
printf("%.3lfE%ld\n",a,b);
}
}
[/cpp]
Thanx
I modified the code so it round the result now, that means that for n=6 I obtain 1.563E2, and for n=7 => 7.813E3...
[cpp]
#include <stdio.h>
#include <math.h>
main()
{ long n;
double u,a,l2;
long b;
l2=log10((double)2);
while(scanf("%ld",&n)==1)
{
printf("2^%ld = ",n);
b=(long int)ceil((double)n*l2);
a=pow(2, b/l2n);
u=((long int)(a*1000))/1000.0;
u=(au)*10000;
n=ceil(u);
a=(long int) (a*1000);
if (n>=5) a=a+1;
a=a/1000;
printf("%.3lfE%ld\n",a,b);
}
}
[/cpp]
Thanx

 Guru
 Posts: 1080
 Joined: Thu Dec 19, 2002 7:37 pm
Ok, but how must look this input?
and output
or
input:
and output
In fact I tried both but the same result WA...
Code: Select all
2
5
6
Code: Select all
2^5 = 3.125E2
2^6 = 1.563E2
or
input:
Code: Select all
2
5
6
5
6
1
Code: Select all
2^5 = 3.125E2
2^6 = 1.563E2
2^5 = 3.125E2
2^6 = 1.563E2
2^1 = 5.000E1
In fact I tried both but the same result WA...

 Guru
 Posts: 834
 Joined: Wed May 29, 2002 4:11 pm
 Location: Wroclaw, Poland
 Contact:
try to use log2() instead of log10() .... log2() means log(), I think .....
I remember, that it was difference in rounding ....
Dominik Michniewski
I remember, that it was difference in rounding ....
Dominik Michniewski
If you really want to get Accepted, try to think about possible, and after that  about impossible ... and you'll get, what you want ....
Born from ashes  restarting counter of problems (800+ solved problems)
Born from ashes  restarting counter of problems (800+ solved problems)
Both the input formats are correct. By the 2 in the first line you're saying that there will be two set of test cases. The input sets are separated by blank lines.
K M Hasan
http://www.cs.umanitoba.ca/~kmhasan/
http://www.cs.umanitoba.ca/~kmhasan/

 New poster
 Posts: 2
 Joined: Fri Mar 07, 2003 9:14 am
 Location: republic of korea
545 WA plz tell about the input format~
i don't use math theory.. ex) log..
but, my prog output is correct about other post's test cases..
i don't know whether my prog is worng or not.
is my prog really wrong??
or ain't i understanding the input format??
i saw that other post mentioned about the input format..
plz help me~
but, my prog output is correct about other post's test cases..
i don't know whether my prog is worng or not.
is my prog really wrong??
or ain't i understanding the input format??
i saw that other post mentioned about the input format..
plz help me~
Code: Select all
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
void main()
{
int n,i,y,caseno;
double x;
char c[10];
cin>>caseno;
while(caseno){
if(c[0]=='\n') break;
sscanf(c,"%d",&n);
x=1; y=0;
for(i=0;i<n;i++){
if((int)x/2==0){
y++;
x*=10;
}
x/=2;
}
printf("2^%d = %.3lfE%d\n",n,x,y);
}
}
aaa
545 WA
Not sure why I'm getting WA  is it an input format thing? (I know this is a slow way to do it).
[cpp]
#include <cstdio>
using namespace std;
int main() {
int n, c;
scanf("%d", &c);
for (int i = 0; i < c; ++i) {
if (i)
putc('\n', stdout);
scanf(" ");
int line = getc(stdin); ungetc(line, stdin);
while ((line != '\n') && (line != EOF)) {
scanf("%d", &n); while(getc(stdin) == ' ');
double mantissa = 1.0; int exp = 0;
for (int i = 0; i < n; ++i) {
mantissa /= 2.0;
if (mantissa < 1) {
mantissa *= 10.0;
++exp;
}
}
printf("2^%d = %.3lfE%d\n", n, mantissa, exp);
line = getc(stdin); ungetc(line, stdin);
}
}
}
[/cpp]
[cpp]
#include <cstdio>
using namespace std;
int main() {
int n, c;
scanf("%d", &c);
for (int i = 0; i < c; ++i) {
if (i)
putc('\n', stdout);
scanf(" ");
int line = getc(stdin); ungetc(line, stdin);
while ((line != '\n') && (line != EOF)) {
scanf("%d", &n); while(getc(stdin) == ' ');
double mantissa = 1.0; int exp = 0;
for (int i = 0; i < n; ++i) {
mantissa /= 2.0;
if (mantissa < 1) {
mantissa *= 10.0;
++exp;
}
}
printf("2^%d = %.3lfE%d\n", n, mantissa, exp);
line = getc(stdin); ungetc(line, stdin);
}
}
}
[/cpp]

 New poster
 Posts: 43
 Joined: Fri Jun 25, 2004 9:37 pm
Your program gives different output from my AC solution:
diff me you
6,7c6,7
< 2^6 = 1.563E2
< 2^7 = 7.813E3

> 2^6 = 1.562E2
> 2^7 = 7.812E3
The correct numbers are
In[2]:=
\!\(2\^{\(6\), \(7\)} // N\)
Out[2]=
{0.015625, 0.0078125}
I have tried on all 9000 valid inputs, so that should fix it.
Isn't this issue addressed in an earlier post?
diff me you
6,7c6,7
< 2^6 = 1.563E2
< 2^7 = 7.813E3

> 2^6 = 1.562E2
> 2^7 = 7.812E3
The correct numbers are
In[2]:=
\!\(2\^{\(6\), \(7\)} // N\)
Out[2]=
{0.015625, 0.0078125}
I have tried on all 9000 valid inputs, so that should fix it.
Isn't this issue addressed in an earlier post?
I got tons of WAs before AC.
Algorithm is just the same as 474.
My friend got AC and we have the same answer for all n (1<=n<=9000) on windows XP + VC++6.0. But the judge always said WA.
Then I find the special precison lost when n = 6 and n = 7 which means
Then I just printf("1.563") for n = 6 and printf("7.813") for n = 7 others are all same as the WA code and get AC.
The precison is really tedious problem.
The multy input is just like others
here is input and output
[cpp] scanf("%d", &cases);
gets(buf), gets(buf);
while (cases)
{
while (gets(buf) && buf[0])
{
sscanf(buf, "%d", &n);
//calculate t and m
printf("2^%d = %.3lfE%d\n", n, t, m);
}
if (cases)
printf("\n");
}[/cpp]
BTW i use log10 and pow functions
if you know why got WA on judge but same answer with AC code for all n on own windows plz tell me mail to:jackie@hit.edu.cn
THKS
Good luck
Algorithm is just the same as 474.
My friend got AC and we have the same answer for all n (1<=n<=9000) on windows XP + VC++6.0. But the judge always said WA.
Then I find the special precison lost when n = 6 and n = 7 which means
you have to face 5 when printf("%.3lf", answer)2^6 = 1.56250E2
2^7 = 7.81250E3
Then I just printf("1.563") for n = 6 and printf("7.813") for n = 7 others are all same as the WA code and get AC.
The precison is really tedious problem.
The multy input is just like others
here is input and output
[cpp] scanf("%d", &cases);
gets(buf), gets(buf);
while (cases)
{
while (gets(buf) && buf[0])
{
sscanf(buf, "%d", &n);
//calculate t and m
printf("2^%d = %.3lfE%d\n", n, t, m);
}
if (cases)
printf("\n");
}[/cpp]
BTW i use log10 and pow functions
if you know why got WA on judge but same answer with AC code for all n on own windows plz tell me mail to:jackie@hit.edu.cn
THKS
Good luck