Page 2 of 5
Accepted 545
Posted: Tue Oct 29, 2002 8:47 pm
by medv
Cleaned
Posted: Wed Oct 30, 2002 7:51 am
by rjhadley
Problems 474 and 545 are almost identical, but they (seem to) expect different output for n = 6 and n = 7 due to rounding variations:
474
2^-6 = 1.562e-2
2^-7 = 7.812e-3
545
2^-6 = 1.563E-2
2^-7 = 7.813E-3
545 WA - 474 AC Who can help me???
Posted: Thu Apr 03, 2003 2:59 pm
by pc5971
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.563E-2, and for n=7 => 7.813E-3...
[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/l2-n);
u=((long int)(a*1000))/1000.0;
u=(a-u)*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
Posted: Thu Apr 03, 2003 7:47 pm
by little joey
Did you notice the blue flag? It's multi input!
Posted: Fri Apr 04, 2003 12:28 pm
by pc5971
Ok, but how must look this input?
and output
or
input:
and output
Code: Select all
2^-5 = 3.125E-2
2^-6 = 1.563E-2
2^-5 = 3.125E-2
2^-6 = 1.563E-2
2^-1 = 5.000E-1
In fact I tried both but the same result WA...
Posted: Fri Apr 04, 2003 2:26 pm
by Dominik Michniewski
try to use log2() instead of log10() .... log2() means log(), I think .....
I remember, that it was difference in rounding ....
Dominik Michniewski
Posted: Fri Apr 04, 2003 6:34 pm
by pc5971
I can't find log2() function in Borland C++ that I use. Ok no problem because I'll download gcc and I'll try again. Pls. tell me what about the input. Which of them are correct ?!
Thanx anyway
Posted: Fri Apr 04, 2003 6:59 pm
by kmhasan
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.
I am exhaused!! Help!!
Posted: Tue May 06, 2003 4:30 pm
by tonyk
Who can email me a correct program?
Many thanks.
ccwangtao@sohu.com
Posted: Mon Jan 19, 2004 8:07 pm
by Noim
for 545 and 474 , my outputs are same.
i think the only problem is in the inpur format of 545.
input is like that:
2
2
5
5
6
545 WA plz tell about the input format~
Posted: Thu Jun 24, 2004 5:11 pm
by bornagirl2397
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~
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);
}
}
545 WA
Posted: Tue Jul 13, 2004 4:55 am
by Quantris
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]
Posted: Wed Jul 14, 2004 9:06 pm
by Andrew Neitsch
Your program gives different output from my AC solution:
diff me you
6,7c6,7
< 2^-6 = 1.563E-2
< 2^-7 = 7.813E-3
---
> 2^-6 = 1.562E-2
> 2^-7 = 7.812E-3
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?
Posted: Thu Jul 15, 2004 1:48 am
by Quantris
It gives the right values on my computer; I also tried it on several (linux) boxes in ECE. guess I'm just unlucky then.
ok, I'll just make those special cases.
Posted: Sat Aug 07, 2004 8:18 am
by jackie
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
2^-6 = 1.56250E-2
2^-7 = 7.81250E-3
you have to face 5 when printf("%.3lf", answer)
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