Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<fstream>
- #include<sstream>
- #include<iomanip>
- #include<iostream>
- #include<array>
- #include<map>
- #include<vector>
- #include<algorithm>
- using namespace std;
- constexpr int x_size = 686, y_size = 460;
- template<typename T> using V=vector<T>;
- string utos(int k){
- string ret;
- while(k)
- ret.push_back('0'+k%10),k/=10;
- reverse(ret.begin(),ret.end());
- return ret;
- }
- int main(){
- fstream fin("input.txt", ios::in);
- string str,res;
- getline(fin,str);
- while(getline(fin,str)){
- str.resize(remove_if(str.begin(),str.end(),[](char x){
- return !isdigit(x) and !isspace(x);
- })-str.begin());
- res+=str;
- }
- stringstream ss(res);
- V<V<double>> arr(x_size,V<double>(y_size));
- for(int i=0;i!=x_size;i++)
- for(int j=0;j!=y_size;j++)
- ss>>arr[i][j];
- for(int k=1;k<=10;k++){
- const int fixed_x_size = x_size/k, fixed_y_size = y_size/k;
- V<V<double>> fixed_arr(fixed_x_size,V<double>(fixed_y_size));
- string a="p"s+utos(k)+".txt"s;
- fstream fout(a.data(),ios::out|ios::trunc);
- for(int i=0;i!=fixed_x_size*k;i++)
- for(int j=0;j!=fixed_y_size*k;j++)
- fixed_arr[i/k][j/k]+=arr[i][j];
- for(auto& i:fixed_arr)
- for(auto& j:i)
- j/=k*k;
- map<double,long long> m;
- for(const auto& i:fixed_arr)
- for(const auto& j:i)
- m[j]++;
- using node=pair<double,long long>;
- vector<node> v;
- for(auto i=m.rbegin();i!=m.rend();i++)
- v.emplace_back(i->first,i->second);
- sort(v.begin(),v.end(),[](node a,node b){
- return a.second>b.second||(a.second==b.second&&a.first<b.first);
- });
- for(const auto& i:v)
- fout<<i.first<<"\t"<<i.second<<endl;
- string b="p"s+utos(k)+"_fixed.txt"s;
- fstream fout2(b.data(),ios::out|ios::trunc);
- for(int i=0;i<int(v.size());i++)
- fout2<<i+1<<'\t'<<v[i].second<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment