library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub beet-aizu/library

:heavy_check_mark: test/aoj/2187.test.cpp

Depends on

Code

// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2187
// verification-helper: ERROR 1e-5

#include<bits/stdc++.h>
using namespace std;

#define call_from_test
#include "../../tools/chminmax.cpp"
#include "../../tools/all_permutations.cpp"
#undef call_from_test

signed solve(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  const int n=9;
  vector<int> as(n),bs(n);
  for(int i=0;i<n;i++) cin>>as[i];
  for(int i=0;i<n;i++) cin>>bs[i];
  int num=0,cnt=0;
  auto f=
    [&](vector<int> vs){
      int x=0,y=0;
      for(int i=0;i<n;i++){
        if(as[vs[i]]<bs[i]) x+=as[vs[i]]+bs[i];
        if(as[vs[i]]>bs[i]) y+=as[vs[i]]+bs[i];
      }
      if(x<y) num++;
      cnt++;
    };
  all_permutations(n,f);

  double A=(double)num/cnt;
  double B=1.0-A;
  cout<<fixed<<setprecision(5);
  cout<<A<<" "<<B<<endl;
  return 0;
}

signed main(){
  int T;
  cin>>T;
  while(T--) solve();
  return 0;
}
#line 1 "test/aoj/2187.test.cpp"
// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2187
// verification-helper: ERROR 1e-5

#include<bits/stdc++.h>
using namespace std;

#define call_from_test
#line 1 "tools/chminmax.cpp"

#line 3 "tools/chminmax.cpp"
using namespace std;
#endif
//BEGIN CUT HERE
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//END CUT HERE
#ifndef call_from_test
signed main(){
  return 0;
}
#endif
#line 1 "tools/all_permutations.cpp"

#line 3 "tools/all_permutations.cpp"
using namespace std;
#endif
//BEGIN CUT HERE
template<typename F>
void all_permutations(int n,F f){
  vector<int> vs(n);
  iota(vs.begin(),vs.end(),0);
  do f(vs); while(next_permutation(vs.begin(),vs.end()));
}
//END CUT HERE
#ifndef call_from_test
signed main(){
  return 0;
}
#endif
#line 10 "test/aoj/2187.test.cpp"
#undef call_from_test

signed solve(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  const int n=9;
  vector<int> as(n),bs(n);
  for(int i=0;i<n;i++) cin>>as[i];
  for(int i=0;i<n;i++) cin>>bs[i];
  int num=0,cnt=0;
  auto f=
    [&](vector<int> vs){
      int x=0,y=0;
      for(int i=0;i<n;i++){
        if(as[vs[i]]<bs[i]) x+=as[vs[i]]+bs[i];
        if(as[vs[i]]>bs[i]) y+=as[vs[i]]+bs[i];
      }
      if(x<y) num++;
      cnt++;
    };
  all_permutations(n,f);

  double A=(double)num/cnt;
  double B=1.0-A;
  cout<<fixed<<setprecision(5);
  cout<<A<<" "<<B<<endl;
  return 0;
}

signed main(){
  int T;
  cin>>T;
  while(T--) solve();
  return 0;
}
Back to top page