kburnik

C++ - Zadatak WLAN - rješenje

Jan 10th, 2013
71
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     Task: WLAN
  3.         Za zadani skup WLAN odašiljaca zadanih sa koordinatama (X,Y)
  4.         i jedinstvenim dometom signala R za svaku stanicu  (u metrima),
  5.         odrediti minimlani broj stanica koje mogu neposredno komunicirati
  6.         te maksimalni broj stanica koje mogu neposredno komunicirati
  7.  
  8.     Category: P2
  9.  
  10.     Solution by: Kristijan Burnik
  11.  
  12. */
  13. #include <iostream>
  14. #include <cstdlib>
  15. #include <algorithm>
  16. #include <vector>
  17. #include <set>
  18. #include <map>
  19.  
  20. using namespace std;
  21.  
  22. typedef pair <int,int> Com;
  23. #define X first
  24. #define Y second
  25.  
  26. int q(int x) {return x*x; }
  27.  
  28. bool inrange(Com a, Com b, int r){
  29.     return (q(a.X-b.X) + q(a.Y-b.Y)) <= (r*r);
  30. }
  31.  
  32.  
  33. int main(void) {
  34.  
  35.     vector < Com > coms;
  36.     int r,n;
  37.     cin >> r >> n;
  38.  
  39.     coms.resize(n);
  40.  
  41.     vector <int> graph;
  42.     graph.resize(n);
  43.  
  44.     int mins = n , maxs = 0 , s;
  45.     for (int i = 0; i < n ; i++) {
  46.         cin >> coms[i].X >> coms[i].Y;
  47.         for (int j = 0 ; j <= i; j++) {
  48.             if (inrange(coms[i],coms[j],r)) {
  49.                 s = ++graph[ i ];
  50.                 mins = min(s,mins);
  51.                 maxs = max(s,maxs);
  52.             }
  53.         }
  54.     }
  55.     cout << mins << " " << maxs << endl;
  56.  
  57.     return 0;
  58. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×