10370 - Above Average

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

Moderator: Board moderators

amd-RS
New poster
Posts: 27
Joined: Thu Sep 05, 2002 7:37 am

10370 - Above Average

Post by amd-RS » Sun Oct 06, 2002 3:17 pm

How can I get 0:00:000 for this problem? Any hints would be welcome !!!

Thanks !

Stefan Pochmann
A great helper
Posts: 284
Joined: Thu Feb 28, 2002 2:00 am
Location: Germany
Contact:

Post by Stefan Pochmann » Sun Oct 06, 2002 5:53 pm

How long do you need with your current program? I need 10 milliseconds, but I think that's only because I use the fairly slow cin of C++. Maybe try using scanf or write your own input function.

junjieliang
Experienced poster
Posts: 169
Joined: Wed Oct 31, 2001 2:00 am
Location: Singapore

Not really...

Post by junjieliang » Mon Oct 07, 2002 7:30 am

Nopes, scanf also gives you 10 ms. What's your current time? IMHO 10 ms is not a bad time...:D Maybe the problem lies in floating numbers, try not using floating-points at all and see what happens...
All the best :)

amd-RS
New poster
Posts: 27
Joined: Thu Sep 05, 2002 7:37 am

Post by amd-RS » Mon Oct 07, 2002 5:21 pm

My current time is 10ms, and I'm using fscanf for input. I note that the six persons who get zero used C++ or Pascal. Stefan, how can I write my own input function.

Thanks both of you for the replies!!! :D

Aur

Stefan Pochmann
A great helper
Posts: 284
Joined: Thu Feb 28, 2002 2:00 am
Location: Germany
Contact:

Post by Stefan Pochmann » Mon Oct 07, 2002 7:52 pm

You could use getc or getchar or something like that to read single characters. Or even fread to read large blocks. Or maybe read the numbers as strings. In all of these cases, you have to write your own code to transform the single digits to the whole numbers.

Furthermore, try using int instead of float/double (in case you do that), just as junjieliang suggested. This will also give you safety from rounding errors if you do it right.

amd-RS
New poster
Posts: 27
Joined: Thu Sep 05, 2002 7:37 am

Post by amd-RS » Tue Oct 08, 2002 5:08 am

I used only int !!! Can I put my algo. here fou you to check it out ?

Thanks !!!

gvcormac
Problemsetter & Reviewer
Posts: 194
Joined: Fri Mar 15, 2002 2:00 am
Contact:

Post by gvcormac » Wed Oct 09, 2002 2:23 pm

Preamble:

I know that this is just a puzzle and as such you have every right to spend your time thinking about it, but wouldn't it be more interesting to attack some of the harder problems rather than to try to wring the last millisecond out of this one?

Solution:

As has been mentioned, scanf() and/or cin consume the majority of the time. If you replace them by a single read() [called "big inhale" in the trade] followed by strtok/atoi, you'll make it run in 0.000 seconds. The use of floating point vs. integer is a Red Herring. I have no idea if the STL equivalents of strtok/atoi would be fast enough. I'm skeptical.

venia
New poster
Posts: 1
Joined: Sat Oct 12, 2002 7:32 pm
Location: Taiwan
Contact:

10370 WA >_< !!!

Post by venia » Sat Oct 12, 2002 7:35 pm

I got several times WA about 10370. Is there any special case that I didn't consider? Could someone give some test data for me? You may also mail to me. email:u89417@ice.ntnu.edu.tw. Thank you. :cry:

turuthok
Experienced poster
Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia
Contact:

Post by turuthok » Mon Oct 14, 2002 8:43 am

Hi, ...

10370 - Above Average is I believe one of the easiest problems in this site. Not sure what's wrong with your WA ... most likely it's a precision problem or other simple mistakes ... please post a little bit of your code here and let's see ...

-turuthok-

soyoja
Experienced poster
Posts: 106
Joined: Sun Feb 17, 2002 2:00 am
Location: Seoul, South Korea
Contact:

Post by soyoja » Tue Oct 15, 2002 7:30 pm

I agree. : )

It's a really easy problem. You only need to calculate average of input numbers,

and count above average of input data.

Be careful when you print your output, especially conversion to percentage format.

Good Luck~ : )

Whinii F.
Experienced poster
Posts: 151
Joined: Wed Aug 21, 2002 12:07 am
Location: Seoul, Korea
Contact:

and..

Post by Whinii F. » Tue Oct 15, 2002 9:05 pm

you may find out you don't need any floating number type variables in solving this problem..

try small cases, like just one number or that kind of things.
it may be your code, not the algorithm that is wrong..

turuthok
Experienced poster
Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia
Contact:

Post by turuthok » Wed Oct 16, 2002 12:43 am

That's correct, I know I don't use any double or float type in my C solution ... But I definitely did real-numbers calculation at the end (when I print the output, of course).

-turuthok-

Sajid
Learning poster
Posts: 94
Joined: Sat Oct 05, 2002 5:34 pm
Location: CS - AIUB, Dhaka, Bangladesh.
Contact:

Using Floating variable

Post by Sajid » Mon Oct 28, 2002 11:17 pm

Why may i not use floating point variable??? the answer should be floating point variable. what do u think???

User avatar
cytse
Learning poster
Posts: 67
Joined: Mon Sep 16, 2002 2:47 pm
Location: Hong Kong
Contact:

Post by cytse » Tue Mar 04, 2003 5:15 pm

When N=1, the answer should be 0.000%, because the score of the only student is equal to the average, which is surely not above average :wink:

User avatar
Riyad
Experienced poster
Posts: 131
Joined: Thu Aug 14, 2003 10:23 pm
Location: BUET
Contact:

10370, plizzzzzzzzz help me , WA

Post by Riyad » Tue Oct 07, 2003 4:41 pm

i went through both the topics about 10370 available in the board . i tried to follow the advices . but i am constantly getting WA . may be it is the precision problem or i am missing some thing . i did not use any floating point number in my calculation . only used them while printing the answer.

here , pliz Take a look at my clumpsy code :(:(:(:(:(

Code: Select all

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void bubble_sort(int v[],int n ){

	int i , j,temp;
	
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			if(v[i]>v[j]){
				temp=v[i];
				v[i]=v[j];
				v[j]=temp;
			}
			else
				continue;
		
		}
	
	}

}

void check(int numbers[], int index, int sum, int nos){

	
	int count=0,i;
	int avg;
	double s,n;

	
	
	n=nos;
	
	avg=(int)(sum/nos);
	

	
	
	for(i=0;i<index;i++){
		
		if(numbers[i] > avg){
		
			count=index-i;
			
			break;
                                                //count++;
			
			
			
		}
		
		else
			continue;
	
	}
	

	s=(double)(count/n)*100.0;
	
        printf("%.3lf!\n",s);



}


int main(){

	int cases;
	int numbers[1500];
	int index,flag,nos,sum;
	char *p;
	char input[10000];




	while(scanf("%d",&cases)==1){
	
		getchar();

		while(cases>0){
		
			flag=0;
			index=0;
			sum=0;

			gets(input);
			

			p=strtok(input," \n");
			
			while(p!=NULL){
			
				if(flag==0){
					nos=atoi(p);
				}

				else{
				
					numbers[index++]=atoi(p);
					sum+=atoi(p);
				}
				p=strtok(NULL," \n");
				flag++;
			
			}
			

			
		
			bubble_sort(numbers,index);
			
			
			check(numbers,index,sum,nos);
			
			
			cases--;
		}

		

	
	
	
	}


	
	return 0;
}
Waiting for any kind of reply and help .
Bye
Riyad
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN

Post Reply

Return to “Volume 103 (10300-10399)”