10370 - Above Average

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

Moderator: Board moderators

10370 - Above Average

Postby 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 !
amd-RS
New poster
 
Posts: 27
Joined: Thu Sep 05, 2002 7:37 am

Postby 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.
Stefan Pochmann
A great helper
 
Posts: 284
Joined: Thu Feb 28, 2002 2:00 am
Location: Germany

Not really...

Postby 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 :)
junjieliang
Experienced poster
 
Posts: 169
Joined: Wed Oct 31, 2001 2:00 am
Location: Singapore

Postby 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
amd-RS
New poster
 
Posts: 27
Joined: Thu Sep 05, 2002 7:37 am

Postby 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.
Stefan Pochmann
A great helper
 
Posts: 284
Joined: Thu Feb 28, 2002 2:00 am
Location: Germany

Postby 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 !!!
amd-RS
New poster
 
Posts: 27
Joined: Thu Sep 05, 2002 7:37 am

Postby 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.
gvcormac
Problemsetter & Reviewer
 
Posts: 194
Joined: Fri Mar 15, 2002 2:00 am

10370 WA >_< !!!

Postby 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:
venia
New poster
 
Posts: 1
Joined: Sat Oct 12, 2002 7:32 pm
Location: Taiwan

Postby 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-
turuthok
Experienced poster
 
Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia

Postby 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~ : )
soyoja
Experienced poster
 
Posts: 106
Joined: Sun Feb 17, 2002 2:00 am
Location: Seoul, South Korea

and..

Postby 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..
Whinii F.
Experienced poster
 
Posts: 151
Joined: Wed Aug 21, 2002 12:07 am
Location: Seoul, Korea

Postby 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-
turuthok
Experienced poster
 
Posts: 193
Joined: Thu Sep 19, 2002 6:39 am
Location: Indonesia

Using Floating variable

Postby 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???
Sajid
Learning poster
 
Posts: 94
Joined: Sat Oct 05, 2002 5:34 pm
Location: CS - AIUB, Dhaka, Bangladesh.

Postby 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
cytse
Learning poster
 
Posts: 67
Joined: Mon Sep 16, 2002 2:47 pm
Location: Hong Kong

10370, plizzzzzzzzz help me , WA

Postby 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
User avatar
Riyad
Experienced poster
 
Posts: 131
Joined: Thu Aug 14, 2003 10:23 pm
Location: BUET

Next

Return to Volume CIII

Who is online

Users browsing this forum: No registered users and 0 guests