Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int n, k, f;
- vector <int> x;
- int bin_search(int szukana);
- int main()
- {
- ios_base::sync_with_stdio(NULL);
- cin.tie(NULL);
- cin >> n >> k >> f;
- x.resize(n);
- for (int i = 0; i < n; i++)
- {
- cin >> x[i];
- }
- for (int i = 0; i < n; i++)
- {
- int var = (k * x[i]) + f;
- if (var > x[n - 1]) //jeżeli wykracza z prawej
- {
- cout << n << " ";
- }
- else if (var < x[0]) //jeżeli wykracza z lewej
- {
- cout << 0 << " ";
- }
- else //jeżeli w zakresie
- {
- cout << bin_search(var) << " ";
- }
- }
- return 0;
- }
- int bin_search(int szukana)
- {
- int pocz = 0, kon = n;
- while (pocz != kon)
- {
- int sr = (pocz + kon) / 2;
- if (szukana >= x[sr]) //jeżeli szukana wartość jest większa lub równa od WARTOŚCI!!! srodka
- {
- pocz = sr + 1;
- }
- else
- {
- kon = sr;
- }
- }
- return pocz - 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement