545 - Heads

All about problems in Volume 5. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

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

Accepted 545

Post by medv » Tue Oct 29, 2002 8:47 pm

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

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

Post by rjhadley » Wed Oct 30, 2002 7:51 am

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

pc5971
New poster
Posts: 34
Joined: Mon Aug 05, 2002 11:24 am
Contact:

545 WA - 474 AC Who can help me???

Post by pc5971 » Thu Apr 03, 2003 2:59 pm

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

User avatar
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post by little joey » Thu Apr 03, 2003 7:47 pm

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

pc5971
New poster
Posts: 34
Joined: Mon Aug 05, 2002 11:24 am
Contact:

Post by pc5971 » Fri Apr 04, 2003 12:28 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...

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski » Fri Apr 04, 2003 2:26 pm

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)

pc5971
New poster
Posts: 34
Joined: Mon Aug 05, 2002 11:24 am
Contact:

Post by pc5971 » Fri Apr 04, 2003 6:34 pm

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

User avatar
kmhasan
Problemsetter
Posts: 107
Joined: Fri Oct 26, 2001 2:00 am
Location: Canada
Contact:

Post by kmhasan » Fri Apr 04, 2003 6:59 pm

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.

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

I am exhaused!! Help!!

Post by tonyk » Tue May 06, 2003 4:30 pm

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

Noim
Learning poster
Posts: 88
Joined: Sun Oct 13, 2002 6:11 am
Location: Bangladesh

Post by Noim » Mon Jan 19, 2004 8:07 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....

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

545 WA plz tell about the input format~

Post by bornagirl2397 » Thu Jun 24, 2004 5:11 pm

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

Quantris
Learning poster
Posts: 80
Joined: Sat Dec 27, 2003 4:49 am
Location: Edmonton AB Canada

545 WA

Post by Quantris » Tue Jul 13, 2004 4:55 am

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]

Andrew Neitsch
New poster
Posts: 43
Joined: Fri Jun 25, 2004 9:37 pm

Post by Andrew Neitsch » Wed Jul 14, 2004 9:06 pm

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?

Quantris
Learning poster
Posts: 80
Joined: Sat Dec 27, 2003 4:49 am
Location: Edmonton AB Canada

Post by Quantris » Thu Jul 15, 2004 1:48 am

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.

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

Post by jackie » Sat Aug 07, 2004 8:18 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

Post Reply

Return to “Volume 5 (500-599)”