deushiro

file

Jan 27th, 2020
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream in("input.txt");
  7. ofstream out("output.txt");
  8.  
  9. int ans = 7;
  10.  
  11. vector<int> res;
  12.  
  13. void rec(set<int> a, vector<int> dist){
  14.     /*for (int t : dist) {
  15.         cout << t << " ";
  16.     }
  17.     cout << endl;
  18.     for (int v : a) {
  19.         cout << v << " ";
  20.     }
  21.     cout << endl<< ":" << endl;*/
  22.     if(a.size() == 0){
  23.         if(dist.size() < ans){
  24.             res = dist;
  25.             ans = dist.size();
  26.         }
  27.         return;
  28.     }
  29.     if(dist.size() >= ans){
  30.         return;
  31.     }
  32.     for(int i = 2; i <= 20; ++i){
  33.         set<int> temp;
  34.         bool flag = false;
  35.         for(int j : a){
  36.             if (j >= i)
  37.                 flag = true;
  38.             if(j / i + j % i > 1) temp.insert(j / i + j % i);
  39.         }
  40.         if (flag) {
  41.             dist.push_back(i);
  42.             rec(temp, dist);
  43.             dist.pop_back();
  44.         }
  45.     }
  46. }
  47.  
  48.  
  49. int main() {
  50.     string s;
  51.     vector<int> dist;
  52.     int counter = 0;
  53.     set<int> a;
  54.     while(getline(in, s)){
  55.         for(char i : s){
  56.             if(i == ' '){
  57.                 ++counter;
  58.             }
  59.             else{
  60.                 if(counter > 1){
  61.                     a.insert(counter);
  62.                 }
  63.                 counter = 0;
  64.             }
  65.         }
  66.         if(counter > 1){
  67.             a.insert(counter);
  68.         }
  69.         counter = 0;
  70.     }
  71.     for (int v : a) {
  72.         cout << v << " ";
  73.     }
  74.     cout << endl;
  75.     rec(a, dist);
  76.     out << res.size() << endl;
  77.     for(int i = 0; i < res.size(); ++i){
  78.         out << res[i] << " ";
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment