Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

大家说的左上右下的坑我跳过去了,但是。。。

Posted by KatrineYang at 2016-10-23 13:38:54 on Problem 1410
竟然是线段。。。我当直线做了。。。嚷肮一次
#include <iostream>
#include <stdio.h>
using namespace std;

void jh(int &x, int &y){
	int tmp = x;
	x = y;
	y = tmp;
}

struct pt{
	int x,y;
	pt(int x, int y): x(x), y(y){}
};

struct rctg{
	int xl, xr, yb, yt;
	rctg(int l, int r, int b, int t){
		if(l>r) jh(l,r);
		if(b>t) jh(b,t);
		xl = l, xr = r, yb = b, yt = t;
	}
};

bool inside(pt &p, rctg &r){
	return p.x >= r.xl && p.x <= r.xr && p.y >= r.yb && p.y <= r.yt;
}

pt *qdp, *zdp;
rctg *rp;
int t;
char answers[4] = "FT";

void initT(){
	scanf("%d", &t);
}

bool initC(){
	if(!t) return 0;
	t--;
	int xstart, ystart, xend, yend, xleft, ytop, xright, ybottom;
	scanf("%d%d%d%d%d%d%d%d", &xstart, &ystart, &xend, &yend, &xleft, &ytop, &xright, &ybottom);
	if(xstart > xend || (xstart == xend && ystart > yend)){
		jh(xstart, xend);
		jh(ystart, yend);
	}
	qdp = new pt(xstart, ystart);
	zdp = new pt(xend, yend);
	rp = new rctg(xleft, xright, ybottom, ytop);
	return 1;
}

bool getAns(){
	if(inside(*qdp, *rp) || inside(*zdp, *rp)) return 1;
	if(qdp->x == zdp->x){
		return qdp->x >= rp->xl && qdp->x <= rp->xr && zdp->y >= rp->yb && rp->yt >= qdp->y;
	}
	if(qdp->y == zdp->y){
		return qdp->y >= rp->yb && qdp->y <= rp->yt && zdp->x >= rp->xl && rp->xr >= qdp->x;
	}
	double k = (zdp->y - qdp->y) * 1.0 / (zdp->x - qdp->x);
	double y1 = k * (rp->xl - qdp->x) + qdp->y, y2 = k * (rp->xr - qdp->x) + qdp->y;
	double x1 = (1/k) * (rp->yb - qdp->y) + qdp->x, x2 = (1/k) * (rp->yt - qdp->y) + qdp->x;
	return (x1 >= rp->xl && x1 <= rp->xr && x1 >= qdp->x && x1 <= zdp->x) ||
		   (x2 >= rp->xl && x2 <= rp->xr && x2 >= qdp->x && x2 <= zdp->x) ||
		   (y1 >= rp->yb && y1 <= rp->yt && ((y1 >= qdp->y && y1 <= zdp->y) || (y1 >= zdp->y && y1 <= qdp->y))) ||
		   (y2 >= rp->yb && y2 <= rp->yt && ((y2 >= qdp->y && y2 <= zdp->y) || (y2 >= zdp->y && y2 <= qdp->y)));
}

void ghq(){
	delete qdp;
	delete zdp;
	delete rp;
}

int main() {
	initT();
	while(initC()){
		printf("%c\n", answers[getAns()]);
		ghq();
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator