結果

問題 No.172 UFOを捕まえろ
ユーザー snteasntea
提出日時 2016-07-24 01:35:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 6,945 bytes
コンパイル時間 1,291 ms
コンパイル使用メモリ 149,184 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-06 12:30:31
合計ジャッジ時間 2,440 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef LOCAL111
#else
	#define NDEBUG
#endif
#include <bits/stdc++.h>
const int INF = 1e8;
using namespace std;

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RBP(i,a) for(auto& i : a)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
#else
	#define DEBUG(x) true
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
#define rangej(a,b,c) ((a) <= (c) and (c) < (b))
#define rrangej(b,c) rangej(0,b,c)
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef pair<int,int> P;
typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<LL,LL> LP;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

//library
#define  EPS (1e-10)
#define equal(a, b) (fabs((a) - (b)) < EPS)


class Point {
public:
	double x,y;
	
	Point(double x = 0,double y = 0): x(x), y(y) {}
	
	Point operator+ (const Point &p) { return Point(x + p.x, y + p.y); }
	Point operator- (const Point &p) { return Point(x - p.x, y - p.y); }
	Point operator* (double k) { return Point(x * k, y * k); }
	Point operator/ (double k) { return Point(x / k, y / k); }
	void operator+= (const Point &p) { x += p.x; y += p.y; }

	double norm() { return x*x + y*y; }
	double abs() { return sqrt(norm()); }

	bool operator< (const Point &p) const {
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator> (const Point &p) const {
		return x != p.x ? x > p.x : y > p.y;
	}

	bool operator== (const Point &p) const {
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}

	bool operator!= (const Point &p) const {
		return !(Point(x,y) == p);
	}
};
typedef Point Vector;

class Segment {
public:
	Point p1, p2;
	Segment(Point p1 = Point(0,0), Point p2 = Point(0,0)): p1(p1), p2(p2) {}
};
typedef Segment Line;

class Circle {
public:
	Point c;
	double r;
	Circle(Point c = Point(), double r = 0.0): c(c), r(r) {};
};
typedef vector<Point> Polygon;


double norm(Vector a);
double abs(Vector a);
double dot(Vector a, Vector b);
double cross(Vector a, Vector b);
bool isParallel(Vector v1, Vector v2);
bool isOrthogonal(Vector v1, Vector v2);
bool isParallel(Segment s1, Segment s2) ;
bool isOrthogonal(Segment s1, Segment s2);
Vector project(Vector v1, Vector v2);
Point project(Line s, Point p);
Point reflect(Line l, Point p);
double getDistance(Point a, Point b);
double getDistanceLP(Line l, Point p);
double getDistance(Segment a, Point b);
int ccw(Point p0, Point p1, Point p2);
bool intersect(Point p0, Point p1, Point p2, Point p3);
bool intersect(Segment a, Segment b);
bool intersect(Circle c, Line s);
bool intersect(Circle a, Circle b);
double getDistance(Segment a, Segment b);
pair<Point, Point> getCrossPoints(Circle c, Line l);


double norm(Vector a) {
	return a.x*a.x + a.y*a.y;
}

double abs(Vector a){
	return sqrt(norm(a));
}

double dot(Vector a, Vector b) {
	return a.x * b.x + a.y * b.y ;
}

double cross(Vector a, Vector b) {
	return a.x*b.y - a.y*b.x;
}

bool isParallel(Vector v1, Vector v2) {
	return equal(cross(v1, v2), 0.0);
}

bool isOrthogonal(Vector v1, Vector v2) {
	return equal(dot(v1, v2), 0.0);
}

bool isParallel(Segment s1, Segment s2) {
	return equal(cross(s1.p1 - s1.p2, s2.p1 - s2.p2), 0.0);
}

bool isOrthogonal(Segment s1, Segment s2) {
	return equal(dot(s1.p1 - s1.p2, s2.p1 - s2.p2), 0);
}

Vector project(Vector v1, Vector v2){
	return v1 * (dot(v1, v2) / v1.norm());
}

Point project(Line s, Point p){
	return project(s.p2 - s.p1, p - s.p1) + s.p1;
}

Point reflect(Line l, Point p){
	return (project(l, p) - p) * 2 + p;
}

double getDistance(Point a, Point b) {
	return (a-b).abs();
}

double getDistanceLP(Line l, Point p) {
	return abs(cross(l.p2 - l.p1, p - l.p1) / abs(l.p2 - l.p1));
}

double getDistance(Segment a, Point b) {
	if(dot(a.p2 - a.p1, b - a.p1) < 0)	return (b - a.p1).abs();
	if(dot(a.p1 - a.p2, b - a.p2) < 0)	return (b - a.p2).abs();
	return getDistanceLP(a, b);
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_FRONT = 2;
static const int ONLINE_BACK  = -2;
static const int ON_SEGMENT = 0;

int ccw(Point p0, Point p1, Point p2) {
	Vector a = p1 - p0;
	Vector b = p2 - p0;
	if(cross(a,b) > EPS)	return COUNTER_CLOCKWISE;
	if(cross(a,b) < -EPS)	return CLOCKWISE;
	if(dot(a,b) < -EPS)	return ONLINE_BACK;
	if(a.norm() < b.norm())	return ONLINE_FRONT;
	return ON_SEGMENT;
}

bool intersect(Point p0, Point p1, Point p2, Point p3){
	return ccw(p0,p1,p2)*ccw(p0,p1,p3) <= 0 && ccw(p2,p3,p0)*ccw(p2,p3,p1) <= 0;
}

bool intersect(Segment a, Segment b){
	return intersect(a.p1, a.p2, b.p1, b.p2);
}

bool intersect(Circle c, Line s){
	return getDistance(s, c.c)-c.r < EPS;
}

bool intersect(Circle a, Circle b){
	return getDistance(a.c, b.c) < a.r+b.r+EPS;
}

double getDistance(Segment a, Segment b) {
	if(intersect(a, b))	return 0;
	else	return min({getDistance(a, b.p1), getDistance(a, b.p2), getDistance(b, a.p1), getDistance(b, a.p2)});
}

Point getCrossPoint(Segment s1, Segment s2){
	Vector base = s2.p2-s2.p1;
	double d1 = abs(cross(base, s1.p1-s2.p1));
	double d2 = abs(cross(base, s1.p2-s2.p1));
	double t = d1/(d1+d2);
	return s1.p1+(s1.p2-s1.p1)*t;
}

pair<Point, Point> getCrossPoints(Circle c, Line l){
	assert(intersect(c,l));
	Vector pr = project(l, c.c);
	Vector e = (l.p2 - l.p1) / abs(l.p2 - l.p1);
	double base = sqrt(c.r*c.r - norm(pr - c.c));
	return make_pair(pr + e*base, pr - e*base);
}

double arg(Vector p) { return atan2(p.y, p.x); }
Vector polar(double a, double r){ return Point(cos(r)*a, sin(r)*a); }

pair<Point, Point> getCrossPoints(Circle c1, Circle c2) {
	assert(intersect(c1, c2));
	double d = abs(c1.c-c2.c);
	double a = acos((c1.r * c1.r + d * d - c2.r * c2.r)/(2 * c1.r * d));
	double t = arg(c2.c - c1.c);
	return make_pair(c1.c+polar(c1.r, t+a), c1.c+polar(c1.r, t-a));
}

//library

const int dx[] = {-1,1,-1,1};
const int dy[] = {-1,1,1,-1};

int main()
{
	ios_init();
	Point p;
	int r;
	cin >> p.x >> p.y >> r;
	Point pa[4];
	double rt = sqrt(2);
	rt = 1./rt;
	REP(i,4){
		pa[i] = p;
		pa[i].x += dx[i]*rt*r;
		pa[i].y += dy[i]*rt*r;
		DEBUG(pa[i].x); DEBUG(pa[i].y);
	}
	int di = 1;
	while(true){
		DEBUG(di);
		bool f = true;
		REP(i,4){
			REP(j,4){ 
				if(!((dy[j]*pa[i].y <= dy[j]*(dx[j]*pa[i].x+dy[j]*di)))){
					DEBUG(pa[i].y); DEBUG(pa[i].x);
					f = false;
					goto END;
				}
			}
		}
		END:
		if(f){
			cout << di << endl;
			break;
		}
		di++;
	}
	return 0;
}
0