计算几何(一)

7.16

1.https://codeforces.com/problemset/problem/127/A 水题

2.https://codeforces.com/problemset/problem/136/D

八个点,分成一个长方形一个正方形,也可以两个正方形

展开
int n,k;
struct Point {
	int x,y;
	int id;
	Point() {}
	Point(double x,double y):x(x),y(y) {}
	Point operator - (Point B) {
		return Point(x-B.x,y-B.y);
	}
};

int Distance(Point A,Point B) {
//	return hypot(A.x-B.x,A.y-B.y);
	return (A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y);
}

Point p[N];
int vis[10];
int ch(int x) {
	int y=0;
	while(x) {
		if(x & 1)y++;
		x /= 2;
	}
	if(y == 4)return 1;
	return 0;
}

bool cmp(Point a,Point b) {
	if(a.y != b.y)return a.y < b.y;
	return a.x < b.x;
}


int ok1(Point v[]) {
	Point xx = v[2] - v[1];
	Point yy = v[4] - v[2];
	if(xx.x*yy.x + xx.y*yy.y != 0)return 0;
	if(Distance(v[1],v[3]) != Distance(v[2],v[4]))return 0;
	if(Distance(v[1],v[2]) != Distance(v[3],v[4]))return 0;
	return 1;
}

int ok2(Point v[]) {
	Point xx = v[2] - v[1];
	Point yy = v[4] - v[2];
	if(xx.x*yy.x + xx.y*yy.y != 0)return 0;
	if(Distance(v[1],v[2]) != Distance(v[2],v[4]))return 0;
	if(Distance(v[2],v[4]) != Distance(v[3],v[4]))return 0;
	if(Distance(v[4],v[3]) != Distance(v[3],v[1]))return 0;
	if(Distance(v[3],v[1]) != Distance(v[1],v[2]))return 0;
	return 1;
}

void work() {
	for(int i=1; i<=8; i++) {
		scanf("%d%d",&p[i].x,&p[i].y);
		p[i].id =i;
		vis[i] = 0;
	}
	int flag = 0;
	for(int i=1; i<= (1<<8)-1; i++) {
		if(!ch(i))continue;
		int x=i,t=1;
		Point v1[10],v2[10];
		int tot1=1,tot2=1;

		for(int i=1; i<=8; i++)vis[i]=0;

		while(x) {
			if(x & 1) {
				v1[tot1++] = p[t];
				vis[t] = 1;
			}
			x /= 2;
			t++;
		}
		for(int i=1; i<=8; i++) {
			if(!vis[i])v2[tot2++] = p[i];
		}
		sort(v1+1,v1+5,cmp);
		sort(v2+1,v2+5,cmp);

		if((ok1(v1)&&ok1(v2)) && (ok2(v1)||ok2(v2))) {
			if(ok2(v2)) {
				for(int i=1; i<=4; i++) {
					swap(v1[i],v2[i]);
				}
			}
			printf("YES\n");
			for(int i=1; i<=4; i++)printf("%d ",v1[i].id);
			printf("\n");
			for(int i=1; i<=4; i++)printf("%d ",v2[i].id);
			printf("\n");
			flag = 1;
			break;
		}
	}
	if(flag ==0 )printf("NO\n");
}

3.https://codeforces.com/problemset/problem/140/A 问一个大圆里能否放n个小圆,用圆心角判断

展开
void work() {
	scanf("%d%lf%lf",&n,&R,&r);
	int x=0;
	if(r > R)x=0;
	else if(2*r > R)x=1;
	else if(2*r==R)x=2;
	else {
		double t = asin(r/(R-r));
		t = PI / t;
		x = (int)t;
		if(x+1-t <= eps)x++;
		
	}
	if(x >= n)printf("YES\n");
	else printf("NO\n"); 
}

4.https://codeforces.ml/contest/18/problem/A 问一个三角形能否移动一个距离变成直角三角形

展开
const double eps = 1e-9;
int n,k;

struct Point {
	int x,y;
	int id;
	Point() {}
	Point(double x,double y):x(x),y(y) {}
	Point operator - (Point B) {
		return Point(x-B.x,y-B.y);
	}
	bool operator == (Point B) {
		return x == B.x && y == B.y;
	}
};

int Distance(Point A,Point B) {
//	return hypot(A.x-B.x,A.y-B.y);
	return (A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y);
}
Point p[3];

int fun(Point x,Point y) {
	if(x.x*y.x+x.y*y.y == 0)return 1;
	return 0;
}

int dir[4][2] = {-1,0,1,0,0,1,0,-1};
int op[4][2] =  {1,0,-1,0,0,-1,0,1};

int ok1() {
	Point v1=p[0]-p[1],v2=p[1]-p[2],v3=p[2]-p[0];
	if(fun(v1,v2) || fun(v2,v3) || fun(v3,v1))return 1;
	return 0;
}

int ok2() {
	for(int i=0; i<3; i++) {
		for(int j=0; j<4; j++) {
			p[i].x = p[i].x + dir[j][0];
			p[i].y = p[i].y + dir[j][1];
			if(p[0] == p[1] || p[1] == p[2] || p[2] == p[0]) {
				p[i].x = p[i].x + op[j][0];
				p[i].y = p[i].y + op[j][1];
				continue;
			}
			if(ok1())return 1;
			p[i].x = p[i].x + op[j][0];
			p[i].y = p[i].y + op[j][1];
		}
	}
	return 0;
}

void work() {
	for(int i=0; i<3; i++) {
		scanf("%d%d",&p[i].x,&p[i].y);
	}
	if(ok1()) {
		printf("RIGHT\n");
	} else if(ok2()) {
		printf("ALMOST\n");
	} else {
		printf("NEITHER\n");
	}
}
posted @ 2021-07-16 23:12  LaiYiC  阅读(32)  评论(0编辑  收藏  举报