Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.79 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <map>
  7. using namespace std;
  8.  
  9. map<long long,bool> v;
  10.  
  11. struct date
  12. {
  13.     int month,day,year,hour,minute;
  14.     bool operator < (date b) /// a<b
  15.     {
  16.         date a = *this;
  17.         if(a.year < b.year)
  18.             return true;
  19.         else if(a.year > b.year)
  20.             return false;
  21.         else if(a.month < b.month)
  22.             return true;
  23.         else if(a.month > b.month)
  24.             return false;
  25.         else if(a.day < b.day)
  26.             return true;
  27.         else if(a.day > b.day)
  28.             return false;
  29.         else if(a.hour < b.hour)
  30.             return true;
  31.         else if(a.hour > b.hour)
  32.             return false;
  33.         else if(a.minute < b.minute)
  34.             return true;
  35.         else if(a.minute > b.minute)
  36.             return false;
  37.         else
  38.             return false;            
  39.     }
  40.    
  41.     bool operator > (date b)
  42.     {
  43.         return !(*this<b);
  44.     }
  45. };
  46.  
  47. struct data
  48. {
  49.     date d;
  50.     long double lat,lon;
  51.     long long phone;
  52.     bool operator < (data b)
  53.     {
  54.         return this->d < b.d;
  55.     }
  56. };
  57.  
  58. string read_str()
  59. {
  60.     char c = getchar();
  61.     string ans;
  62.     while(c!=',' && c!='\n')
  63.     {
  64.         ans += c;
  65.         c = getchar();
  66.     }
  67.     return ans;
  68. }
  69.  
  70. long double read_ldbl()
  71. {
  72.     long double ans;
  73.     cin>>ans;
  74.     return ans;
  75. }
  76.  
  77. long long read_longlong()
  78. {
  79.     long long ans;
  80.     cin>>ans;
  81.     return ans;
  82. }
  83.  
  84. date read_date()
  85. {
  86.     date neo;
  87.     char bs;
  88.     cin>>neo.month>>bs>>neo.day>>bs>>neo.year>>neo.hour>>bs>>neo.minute;
  89.     return neo;
  90. }
  91.  
  92. long double LAT,LON;
  93.  
  94. vector<data> input;
  95.  
  96. int main() {
  97.     cin>>LAT;
  98.     LAT = LAT*(M_PI/180.0L);
  99.     getchar();
  100.     cin>>LON;
  101.     LON = LON*(M_PI/180.0L);
  102.     long double r;
  103.     cin>>r;
  104.     string s;
  105.     vector<int> order;
  106.     getchar();
  107.     for(int i=0;i<4;++i)
  108.     {
  109.         s = read_str();
  110.         if(s == "Date&Time")
  111.             order.push_back(0);
  112.         if(s == "Latitude")
  113.             order.push_back(1);
  114.         if(s == "Longitude")
  115.             order.push_back(2);                
  116.         if(s == "PhoneNumber")
  117.             order.push_back(3);
  118.         //cout<<order[i]<<" ";
  119.     }
  120.     //cout<<"\n";
  121.     int tmp;
  122.     char bs;
  123.     data neo;
  124.     while(!cin.eof())
  125.     {
  126.         for(int i=0;i<order.size();++i)
  127.         {
  128.             switch(order[i])
  129.             {
  130.                 case 0:
  131.                     neo.d = read_date();
  132.                     break;
  133.                 case 1:
  134.                     neo.lat = read_ldbl();
  135.                     break;
  136.                 case 2:
  137.                     neo.lon = read_ldbl();
  138.                     break;
  139.                 case 3:
  140.                     neo.phone = read_longlong();
  141.                     break;
  142.             }
  143.             getchar();
  144.             if(cin.eof())
  145.                 goto skip;
  146.         }
  147.         neo.lat = neo.lat*(M_PI/180.0L);
  148.         neo.lon = neo.lon*(M_PI/180.0L);
  149.         input.push_back(neo);
  150.     }
  151.     skip:
  152.     sort(input.begin() , input.end());
  153.     bool first  = true;
  154.     vector<long long> PHONE;
  155.     for(int i=input.size()-1;i>=0;--i)
  156.     {
  157.         if(!v[input[i].phone])
  158.         {
  159.             v[input[i].phone] = true;
  160.            
  161.             long double d =  2.0L * 6378.137L * asin (sqrt (sin((LAT - input[i].lat)/2.0L)*sin((LAT - input[i].lat)/2.0L) + cos(LAT) * cos(input[i].lat) * sin((LON - input[i].lon)/2.0L)*sin((LON - input[i].lon)/2.0L)));
  162.            
  163.             if(d>r)
  164.                 continue;
  165.                
  166.             PHONE.push_back(input[i].phone);
  167.         }
  168.     }
  169.     sort(PHONE.begin(),PHONE.end());
  170.     for(int i=0;i<PHONE.size();++i)
  171.         cout<<PHONE[i]<<(i==PHONE.size()-1?"":",");
  172.     return 0;
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement