konchin_shih

0531-2

May 31st, 2021
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. #include<fstream>
  2. #include<sstream>
  3. #include<iomanip>
  4. #include<iostream>
  5. #include<array>
  6. #include<map>
  7. #include<vector>
  8. #include<algorithm>
  9. using namespace std;
  10.  
  11. constexpr int x_size = 686, y_size = 460;
  12.  
  13. template<typename T> using V=vector<T>;
  14.  
  15. string utos(int k){
  16.     string ret;
  17.     while(k)
  18.         ret.push_back('0'+k%10),k/=10;
  19.     reverse(ret.begin(),ret.end());
  20.     return ret;
  21. }
  22.  
  23.  
  24. int main(){
  25.     fstream fin("input.txt", ios::in);
  26.  
  27.     string str,res;
  28.     getline(fin,str);
  29.     while(getline(fin,str)){
  30.         str.resize(remove_if(str.begin(),str.end(),[](char x){
  31.             return !isdigit(x) and !isspace(x);
  32.         })-str.begin());
  33.         res+=str;
  34.     }
  35.     stringstream ss(res);
  36.     V<V<double>> arr(x_size,V<double>(y_size));
  37.    
  38.     for(int i=0;i!=x_size;i++)
  39.         for(int j=0;j!=y_size;j++)
  40.             ss>>arr[i][j];
  41.  
  42.     for(int k=1;k<=10;k++){
  43.         const int fixed_x_size = x_size/k, fixed_y_size = y_size/k;
  44.         V<V<double>> fixed_arr(fixed_x_size,V<double>(fixed_y_size));
  45.         string a="p"s+utos(k)+".txt"s;
  46.         fstream fout(a.data(),ios::out|ios::trunc);
  47.  
  48.         for(int i=0;i!=fixed_x_size*k;i++)
  49.             for(int j=0;j!=fixed_y_size*k;j++)
  50.                 fixed_arr[i/k][j/k]+=arr[i][j];
  51.      
  52.         for(auto& i:fixed_arr)
  53.             for(auto& j:i)
  54.                 j/=k*k;
  55.      
  56.         map<double,long long> m;
  57.      
  58.         for(const auto& i:fixed_arr)
  59.             for(const auto& j:i)
  60.                 m[j]++;
  61.         using node=pair<double,long long>;
  62.         vector<node> v;
  63.      
  64.         for(auto i=m.rbegin();i!=m.rend();i++)
  65.             v.emplace_back(i->first,i->second);
  66.      
  67.         sort(v.begin(),v.end(),[](node a,node b){
  68.             return a.second>b.second||(a.second==b.second&&a.first<b.first);
  69.         });
  70.      
  71.         for(const auto& i:v)
  72.             fout<<i.first<<"\t"<<i.second<<endl;
  73.  
  74.         string b="p"s+utos(k)+"_fixed.txt"s;
  75.         fstream fout2(b.data(),ios::out|ios::trunc);
  76.  
  77.         for(int i=0;i<int(v.size());i++)
  78.             fout2<<i+1<<'\t'<<v[i].second<<endl;
  79.     }
  80.  
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment