兩個case裡面記得要有空白行 orzzzzzzz
//====================================================================||
// ||
// ||
// Author : GCA ||
// 6AE7EE02212D47DAD26C32C0FE829006 ||
//====================================================================||
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cctype>
#include <utility>
using namespace std;
#ifdef ONLINE_JUDGE
#define ll "%lld"
#else
#define ll "%I64d"
#endif
typedef unsigned int uint;
typedef long long int Int;
#define Set(a,s) memset(a,s,sizeof(a))
#define Write(w) freopen(w,"w",stdout)
#define Read(r) freopen(r,"r",stdin)
#define Pln() printf("\n")
#define I_de(x,n)for(int i=0;i<n;i++)printf("%d ",x[i]);Pln()
#define De(x)printf(#x"%d\n",x)
#define For(i,x)for(int i=0;i<x;i++)
#define CON(x,y) x##y
#define Pmz(dp,nx,ny)for(int hty=0;hty<ny;hty++){for(int htx=0;htx<nx;htx++){\
printf("%d ",dp[htx][hty]);}Pln();}
#define M 1005
#define PII pair<int,int>
#define PB push_back
#define oo INT_MAX
#define Set_oo 0x3f
#define Is_debug true
#define debug(...) if(Is_debug)printf("DEBUG: "),printf(__VA_ARGS__)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define eps 1e-6
bool xdy(double x,double y){return x>y+eps;}
bool xddy(double x,double y){return x>y-eps;}
bool xcy(double x,double y){return x<y-eps;}
bool xcdy(double x,double y){return x<y+eps;}
int min3(int x,int y,int z){
int tmp=min(x,y);
return min(tmp,z);
}
int max3(int x,int y,int z){
int tmp=max(x,y);
return max(tmp,z);
}
int test;
struct line{
int x1,x2,y1,y2;
double m,b;
int tox;
int toy;
void build(){
if(x1>x2){
swap(x1,x2);
swap(y1,y2);
}
m=1.0*(y1-y2)/(x1-x2);
b=y1-m*x1;
if(m>0){
tox=x1;
}
else tox=x2;
toy=min(y1,y2);
}
}lines[M];
int lnum;
int pnum;
int px[M],py[M];
int mz[M];
void solve(){
for(int i=0;i<lnum;i++){
int x=lines[i].tox;
int y=lines[i].toy;
double my=0,cy;
int index=-1;
for(int j=0;j<lnum;j++){
if(i==j)continue;
if(x<lines[j].x1||x>lines[j].x2)continue;
cy=lines[j].m*x+lines[j].b;
if(cy<y&&cy>my){
my=cy;
index=j;
}
}
// debug("%d %d\n",i,index);
mz[i]=index;
}
//
for(int i=0;i<pnum;i++){
int x=px[i];
int y=py[i];
int index=-1;
double my=0;
for(int j=0;j<lnum;j++){
double cy=lines[j].m*x+lines[j].b;
if(x<lines[j].x1||x>lines[j].x2)continue;
if(cy<y&&cy>my){
my=cy;
index=j;
}
}
// debug(">>%d\n",index);
// int ansx=x;
int j;
if(index!=-1){
for(j=index;mz[j]!=-1;j=mz[j]);
// debug("%d\n",j);
printf("%d\n",lines[j].tox);
}
else printf("%d\n",x);
}
}
void init(){
Set(mz,-1);
}
int main() {
ios_base::sync_with_stdio(0);
scanf("%d",&test);
while(test--){
init();
scanf("%d",&lnum);
for(int i=0;i<lnum;i++){
scanf("%d%d%d%d",&lines[i].x1,&lines[i].y1,&lines[i].x2,&lines[i].y2);
lines[i].build();
}
scanf("%d",&pnum);
for(int i=0;i<pnum;i++){
scanf("%d%d",&px[i],&py[i]);
}
solve();
if(test)Pln();
}
}
留言
張貼留言