Alex_tz307

School - Level 4

Oct 30th, 2020 (edited)
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ABS(x) ((x) >= 0 ? (x) : -(x))
  3.  
  4. using namespace std;
  5.  
  6. ifstream fin("text.in");
  7. ofstream fout("text.out");
  8.  
  9. bool fcmp(const pair < int , int >& a, const pair < int , int >& b) {
  10.     return a.second > b.second || (a.second == b.second && a.first < b.first);
  11. }
  12.  
  13. long double my_pow(long double a, long double b) {
  14.     if(b < 0)
  15.         return 1.0 / pow(a, ABS(b));
  16.     return pow(a, b);
  17. }
  18.  
  19. int main() {
  20.     fin.sync_with_stdio(false);
  21.     fout.sync_with_stdio(false);
  22.     fin.tie(nullptr);
  23.     fout.tie(nullptr);
  24.     int N, P;
  25.     fin >> N >> P;
  26.     vector < int > freq(P, 1000);
  27.     for(int itr = 0; itr < N; ++itr) {
  28.         int id1, score1, id2, score2;
  29.         fin >> id1 >> score1 >> id2 >> score2;
  30.         long double difA = freq[id2] - freq[id1];
  31.         long double difB = freq[id1] - freq[id2];
  32.         long double EA = (long double)1.0 / ((long double)1.0 + my_pow(10.0, difA / 400.0));
  33.         long double EB = (long double)1.0 / ((long double)1.0 + my_pow(10.0, difB / 400.0));
  34.         long double SA = 1, SB = 0;
  35.         if(score2 > score1)
  36.             swap(SA, SB);
  37.         freq[id1] += (long double)32.0 * (SA - EA);
  38.         freq[id2] += (long double)32.0 * (SB - EB);
  39.     }
  40.     vector < pair < int , int > > sol;
  41.     for(int i = 0; i < P; ++i)
  42.         sol.emplace_back(i, freq[i]);
  43.     sort(sol.begin(), sol.end(), fcmp);
  44.     for(auto x : sol)
  45.         fout << x.first << ' ' << x.second << '\n';
  46. }
  47.  
Add Comment
Please, Sign In to add comment