Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.31 KB | None | 0 0
  1. #pragma GCC optimize("Ofast")
  2. #pragma GCC optimize("fast-math")
  3. #pragma GCC optimize("unroll-loops")
  4. #include <iostream>
  5. #include <vector>
  6. #include <sstream>
  7. #include <cmath>
  8. #include <algorithm>
  9. #include <string>
  10. #include <cstdio>
  11. #include <fstream>
  12. #include <climits>
  13. #include <map>
  14. #include <set>
  15. #include <deque>
  16. #include <tuple>
  17. using namespace std;
  18. #define sz(x) int(x.size())
  19. #define beg(x) x.begin(), x.end()
  20. #define pow2(x) ((x)*(x))
  21. #define get_auto(x) for (auto& var : x) {cout<<var<<' ';}
  22. typedef long long ll;
  23. typedef unsigned long long ull;
  24. typedef long double ld;
  25. typedef vector < ll > vll;
  26. typedef vector < int > vi;
  27. typedef vector < pair<int, int> > vii;
  28.  
  29. int x,y,c;
  30. vector<int> slozhen;
  31. vector<int> umnozh;
  32. set<int> sod;
  33. map<int,int> un_sod;
  34.  
  35. int main() {
  36.     string s1,s2,s3,s4;
  37.     //Input
  38.     cout<<"Vvedite ishodnoe chislo: ";
  39.     cin>>x;
  40.     cout<<"Vvedite neobhodimoe chislo: ";
  41.     cin>>y;
  42.     getline(cin,s3);
  43.     cout<<"Vvedite operacii slozhenia v 1 stroku:\n";
  44.     getline(cin,s1);
  45.     cout<<"Vvedite operacii umnozhenia v 1 stroku:\n";
  46.     getline(cin,s2);
  47.     cout<<"Vvedite soderzhah cifri v 1 stroku:\n";
  48.     getline(cin,s3);
  49.     cout<<"Vvedite ne_soderzhah cifri v 1 stroku:\n";
  50.     getline(cin,s4);
  51.     //Initialization
  52.     vector<int> v(y+1);
  53.     int predel = x;
  54.     //String processing
  55.     stringstream str1(s1);
  56.     stringstream str2(s2);
  57.     stringstream str3(s3);
  58.     stringstream str4(s4);
  59.     while(str1>>c)
  60.         slozhen.push_back(c);
  61.     while(str2>>c)
  62.         umnozh.push_back(c);
  63.     while(str3>>c)
  64.         sod.insert(c);
  65.     while(str4>>c)
  66.         un_sod[c]=1;
  67.     v[x]=1;
  68.     for (int i = x; i <=y ; ++i) {
  69.         if (un_sod[i]==1) {
  70.             v[i] = 0;
  71.             continue;
  72.         }
  73.         for (auto &var: sod) {
  74.             if(i>var){
  75.                 predel=var;
  76.             }else
  77.                 break;
  78.         }
  79.         for(auto &var: slozhen){
  80.             if(i-var>=predel){
  81.                 v[i]+=v[i-var];
  82.             }
  83.         }
  84.         for(auto &var: umnozh){
  85.             if((i%var)==0 && (i/var)>=predel){
  86.                 v[i]+=v[i/var];
  87.             }
  88.         }
  89.     }
  90.     for (int i = x; i < sz(v); ++i) {
  91.         cout<<i<<": "<<v[i]<<endl;
  92.     }
  93.     cout<<endl<<"ANSWER:"<<v[sz(v)-1];
  94.     return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement