Advertisement
monyca98

bucuresti iulie2015

Mar 6th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4. void citire(int &a, int &b, int &c, int &n,int x[])
  5. {
  6.     cout << "a="; cin >> a;
  7.     cout << "b="; cin >> b;
  8.     cout << "c="; cin >> c;
  9.     cout << "n="; cin >> n;
  10.     cout << "dati numerele din secventa s:";
  11.     for (int i = 0; i < n; i++)
  12.         cin >> x[i];
  13. }
  14. int rezEcuatie(int a, int b, int x, int y)
  15. {
  16.     return x*x*a + y*y*b;
  17. }
  18. void perechi(int v[], int n, int a, int b, int c)
  19. {
  20.     int i = 0;
  21.     while (i < n)
  22.     {
  23.         int j = i+1;
  24.         while (j < n)
  25.         {
  26.             if (rezEcuatie(a, b, v[i], v[j])==c)
  27.                 cout << "(" << v[i] << "," << v[j] << ")";
  28.             if (rezEcuatie(a, b, v[j], v[i])==c)
  29.                 cout << "(" << v[j] << "," << v[i] << ")";     
  30.             j++;
  31.         }
  32.         i++;
  33.     }
  34. }
  35. void perechiEficientCresc(int v[], int n, int a, int b, int c,int &count)
  36. {
  37.     int i = 0;
  38.     count = 0;
  39.     while (i < n && v[i]*v[i]*a<=c || v[i]*v[i]*b<=c)
  40.     {
  41.         int j = i+1;
  42.         while (j < n && rezEcuatie(a,b,v[i],v[j]) <= c && v[i]*v[i]*b<=c-v[j]*v[j]*a && v[j]*v[j]*b<=c-v[i]*v[i]*a)
  43.         {
  44.            
  45.             if (rezEcuatie(a, b, v[i], v[j]) == c)
  46.                 count++;
  47.             if (rezEcuatie(a, b, v[j], v[i]) == c)
  48.                     count++;
  49.             j++;
  50.         }
  51.         i++;
  52.     }
  53.    
  54.  
  55. }
  56. int main()
  57. {
  58.     int x[50], a, b, c, n,count;
  59.     citire(a, b, c, n, x);
  60.     //perechi(x, n, a, b, c);
  61.     perechiEficientCresc(x, n, a, b, c,count);
  62.     cout << "sunt " << count << " perechi cu proprietatea ceruta";
  63.     cout << endl << endl;
  64.     system("pause");
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement