Codeforces 114B Meeting
がんばる。
complex使ってみた。norm使ったらTLEしてつらい。
pairかnormを自前で書いたら余裕で通った。
#include <iostream> #include <cstdio> #include <iomanip> #include <vector> #include <map> #include <set> #include <queue> #include <bitset> #include <stack> #include <utility> #include <numeric> #include <algorithm> #include <functional> #include <cctype> #include <complex> #include <string> #include <sstream> using namespace std; #define all(c) c.begin(),c.end() #define rall(c) c.rbegin(),c.rend() #define rep(i,n) for(unsigned int i=0;i<(n);i++) #define tr(it,container) for(typeof(container.begin()) it = container.begin(); \ it != container.end(); ++it) typedef long long ll; typedef complex<double> P; const int dx[] = {1,0,-1,0}; const int dy[] = {0,-1,0,1}; const double EPS = 1e-9; const int days[] = {31,28,31,30,31,30,31,31,30,31,30,31}; const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31}; P make_p(double x,double y){ P tmp(x,y); return tmp; } int main(){ int xa,ya,xb,yb; cin >> xa >> ya >> xb >> yb; int n; cin >> n; if(xa > xb) swap(xa,xb); if(ya > yb) swap(ya,yb); vector<pair<P,double> > R; rep(i,n){ int x,y,r; cin >> x >> y >> r; R.push_back(make_pair(make_p(x,y),r*r)); } vector<P> K; for(int x=xa;x<=xb;x++){ K.push_back(make_p(x,ya)); K.push_back(make_p(x,yb)); } for(int y=ya+1;y<yb;y++){ K.push_back(make_p(xa,y)); K.push_back(make_p(xb,y)); } int count = 0; tr(it1,K){ bool hot = false; tr(it2,R){ P np = (*it1) - (*it2).first; if(np.real()*np.real() + np.imag()*np.imag() <= (*it2).second){ hot = true; break; } } if(!hot) count++; } cout << count << endl; return 0; }