Advertisement
Guest User

Cbon

a guest
Mar 21st, 2013
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. bool *found;
  7.  
  8. void check(int i){
  9.     if(i>=0 && i<1000)
  10.         if(!found[i])
  11.             found[i]=true;
  12. }
  13. int abs(int i){
  14.     if(i<0)
  15.         return -i;
  16.     return i;
  17. }
  18.  
  19. void test(vector<int> list){
  20.     if(list.size()==1)
  21.         return;
  22.     for(int i=0;i<list.size();i++){
  23.         for(int j=i+1;j<list.size();j++){
  24.             vector<int> temp=list;
  25.             temp.erase(temp.begin()+j);
  26.             temp[i]=list[i]+list[j];
  27.             check(temp[i]);
  28.             test(temp);
  29.             temp[i]=list[i]*list[j];
  30.             check(temp[i]);
  31.             test(temp);
  32.             temp[i]=abs(list[i]-list[j]);
  33.             check(temp[i]);
  34.             test(temp);
  35.             if(list[j]!=0)
  36.             if(!(list[i]%list[j])){
  37.                 temp[i]=list[i]/list[j];
  38.                 check(temp[i]);
  39.                 test(temp);
  40.             }
  41.             if(list[i]!=0)
  42.             if(!(list[j]%list[i])){
  43.                 temp[i]=list[j]/list[i];
  44.                 check(temp[i]);
  45.                 test(temp);
  46.             }
  47.         }
  48.     }
  49. }
  50.  
  51. int main()
  52. {
  53.     int N;
  54.     vector<int> list;
  55.     found=new bool[1000]();
  56.     cin >> N;
  57.     list.resize(N);
  58.     for(int i=0;i<N;i++){
  59.         cin>>list[i];
  60.         found[list[i]]=true;
  61.     }
  62.     test(list);
  63.     int foundn=0;
  64.     for(int i=0;i<1000;i++){
  65.         if(found[i])
  66.             foundn++;
  67.     }
  68.     cout << foundn << endl;
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement