## 545

Moderator: Board moderators

### Accepted 545

Cleaned
Last edited by medv on Wed Oct 30, 2002 7:54 pm, edited 1 time in total.
medv
Learning poster

Posts: 85
Joined: Sun Jul 14, 2002 1:17 pm

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
Learning poster

Posts: 73
Joined: Mon Oct 14, 2002 7:15 am
Location: United States

### 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.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
pc5971
New poster

Posts: 34
Joined: Mon Aug 05, 2002 11:24 am

Did you notice the blue flag? It's multi input!

little joey
Guru

Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Ok, but how must look this input?

Code: Select all
`  2  5  6`

and output

Code: Select all
`  2^-5 = 3.125E-2  2^-6 = 1.563E-2`

or

input:

Code: Select all
`  2  5  6  5  6  1`

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...
pc5971
New poster

Posts: 34
Joined: Mon Aug 05, 2002 11:24 am

try to use log2() instead of log10() .... log2() means log(), I think .....

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)
Dominik Michniewski
Guru

Posts: 828
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland

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
pc5971
New poster

Posts: 34
Joined: Mon Aug 05, 2002 11:24 am

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.

kmhasan
Problemsetter

Posts: 107
Joined: Fri Oct 26, 2001 2:00 am

### I am exhaused!! Help!!

Who can email me a correct program?
Many thanks.
ccwangtao@sohu.com
tonyk
New poster

Posts: 7
Joined: Mon May 05, 2003 5:11 pm

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
__nOi.m....
Noim
Learning poster

Posts: 88
Joined: Sun Oct 13, 2002 6:11 am

### 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~

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
bornagirl2397
New poster

Posts: 2
Joined: Fri Mar 07, 2003 9:14 am
Location: republic of korea

### 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]
Quantris
Learning poster

Posts: 75
Joined: Sat Dec 27, 2003 4:49 am

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?
Andrew Neitsch
New poster

Posts: 43
Joined: Fri Jun 25, 2004 9:37 pm

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.
Quantris
Learning poster

Posts: 75
Joined: Sat Dec 27, 2003 4:49 am

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
jackie
New poster

Posts: 47
Joined: Tue May 04, 2004 4:24 am

PreviousNext