fork download
  1. #include<iostream>
  2. #include<list>
  3. #include<string>
  4. #include<cstring>
  5. #include<sstream>
  6. #include<cctype>
  7. #include<string.h>
  8. #include<algorithm>
  9. #include<cmath>
  10. #include<stack>
  11. #include<fstream>
  12. #include<cstdlib>
  13. #include<vector>
  14. #include<map>
  15. #include<set>
  16. #include<utility>
  17. #include<iomanip>
  18. #include<queue>
  19. #include<stdio.h>
  20. using namespace std;
  21.  
  22. #define INF (1<<29)
  23. #define SET(a) memset(a,-1,sizeof(a))
  24. #define ALL(a) a.begin(),a.end()
  25. #define CLR(a) memset(a,0,sizeof(a))
  26. #define FILL(a,v) memset(a,v,sizeof(a))
  27. #define PB push_back
  28. #define FOR(i,n) for(int i = 0;i<n;i++)
  29. #define PI acos(-1.0)
  30. #define EPS 1e-9
  31. #define MP(a,b) make_pair(a,b)
  32. #define min3(a,b,c) min(a,min(b,c))
  33. #define max3(a,b,c) max(a,max(b,c))
  34. #define READ freopen("input.txt", "r", stdin)
  35. #define WRITE freopen("output.txt", "w", stdout)
  36. #define LL long long
  37. #define MX 100010
  38. #define MOD 1000000007
  39. double abss(double i)
  40. {
  41. return i>0 ?i:(-1.0*i);
  42. }
  43. int main(){
  44. vector<int> l;
  45. int n,s,element;
  46. int set = 1;
  47. while(cin>>n){
  48. double sum = 0;
  49. cin>>s;
  50. FOR(i,s){
  51. cin>>element;
  52. sum+=element;
  53. l.push_back(element);
  54. }
  55. double average = sum/n;
  56. if((l.size()%2)!=0){
  57. l.push_back(0);
  58. }
  59. sort(l.begin(),l.end());
  60. int iter = 0;
  61. cout<<"Set #"<<set<<endl;
  62. double balance = 0;
  63. FOR(i,n){
  64. cout<<" "<<i<<": ";
  65. if(l[iter]!=0)
  66. cout<<l[iter]<<" ";
  67. if(l[l.size()-iter-1]!=0)
  68. cout<<l[l.size()-iter-1]<<endl;
  69. balance+=abss(((l[iter])+(l[l.size()-iter-1]))-(average));
  70. iter++;
  71. }
  72. printf("IMBALANCE = %0.5f\n\n",balance);
  73. if(cin.eof()){
  74. break;
  75. }
  76. set++;
  77. l.clear();
  78. }
  79.  
  80.  
  81. return 0;
  82. }
Success #stdin #stdout 0s 3236KB
stdin
2 3
6 3 8
3 5
51 19 27 14 33
5 9
1 2 3 5 7 11 13 17 19
stdout
Set #1
 0: 8
 1: 3 6
IMBALANCE = 1.00000

Set #2
 0: 51
 1: 14 33
 2: 19 27
IMBALANCE = 6.00000

Set #3
 0: 19
 1: 1 17
 2: 2 13
 3: 3 11
 4: 5 7
IMBALANCE = 11.60000