unlucky_13

uva_410_Station Balance

May 18th, 2013
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. /*
  2.  Author                             :     unlucky_13
  3.  Problem_link                       :
  4.  Category                           :
  5.  Algorithm_Used                     :
  6.  
  7.  */
  8.  
  9. #include<cstdio>
  10. #include<sstream>
  11. #include<cstdlib>
  12. #include<cctype>
  13. #include<cmath>
  14. #include<algorithm>
  15. #include<set>
  16. #include<queue>
  17. #include<stack>
  18. #include<list>
  19. #include<iostream>
  20. #include<fstream>
  21. #include<numeric>
  22. #include<string>
  23. #include<vector>
  24. #include<cstring>
  25. #include<map>
  26. #include<iterator>
  27. #define i64 long long int
  28. //const long long int inf = 2147483647 ;
  29. //const int minx=;
  30. //const int maxn=;
  31.  
  32. using namespace std;
  33. int compare(const void *a,const void *b){
  34.  
  35.     /*This will sort in increasing oder */
  36.    
  37.     int *x = (int *)a ;
  38.     int *y = (int *)b ;
  39.     return *x-*y ;
  40.  
  41.  
  42. }
  43. int main() {
  44.    
  45.     freopen("C:\\Users\\Mazhar\\Desktop\\Text_Files\\in.txt", "r", stdin);
  46.    
  47.     int c,s,I,ct=0;
  48.    
  49.     int cham[100000];
  50.     double  imb,avg ;
  51.     while(scanf("%d %d",&c,&s)==2)
  52.     {
  53.         //if(ct) cout<<endl ;
  54.         imb = 0 ;
  55.         I = 0 ;
  56.         avg = 0 ;
  57.         for(int i=s;i<2*c;i++,I++) cham[I]=0 ;
  58.         for(int i=0;i<s;i++,I++) {
  59.             scanf("%d",&cham[I]) ;
  60.             avg+=cham[I] ;
  61.         }
  62.         avg/=c ;
  63.         qsort(cham,I,sizeof(int),compare) ;
  64.        // for(int i=0;i<I;i++) cout<<cham[i]<<" " ;
  65.         printf("Set #%d\n",++ct) ;
  66.         for(int i=0;i<c;i++){
  67.             printf(" %d:",i) ;
  68.             if(cham[i])     cout<<" "<<cham[i];
  69.             if(cham[I-i-1]) cout<<" "<<cham[I-i-1];
  70.             imb +=abs(cham[i]+cham[I-i-1]-avg) ;
  71.             cout<<endl ;
  72.         }
  73.         printf("IMBALANCE = %0.5lf\n\n",imb) ;
  74.        
  75.        
  76.     }
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment