比赛 |
20120722 |
评测结果 |
AWWWWWWWTT |
题目名称 |
切割矩形 |
最终得分 |
10 |
用户昵称 |
了反取字名我擦 |
运行时间 |
2.018 s |
代码语言 |
C++ |
内存使用 |
3.97 MiB |
提交时间 |
2012-07-22 11:23:02 |
显示代码纯文本
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<string>
#include<list>
#include<vector>
#include<deque>
#include<queue>
#include<map>
using namespace std;
ifstream fi("cutting.in");
ofstream fo("cutting.out");
typedef struct line
{
double x1,x2,y1,y2;
};
struct jx
{
line l1,l2,l3,l4;
void add_jx(double x1,double y1,double x2,double y2)
{
l1.x1=x1;l1.x2=x2;l1.y1=y1;l1.y2=y1;
l2.x1=x2;l2.x2=x2;l2.y1=y1;l2.y2=y2;
l3.x1=x1;l3.x2=x2;l3.y1=y2;l3.y2=y2;
l4.x1=x1;l4.x2=x1;l4.y1=y1;l4.y2=y2;
}
}N[30001];
bool xjxd(line l1,line l2)
{
double r1,r2,r,t;
r1=(l2.y1-l1.y1)*(l2.x2-l2.x1)+(l1.x1-l2.x1)*(l2.y2-l2.y1);
r2=(l1.y2-l1.y1)*(l2.x2-l2.x1)+(l2.x2-l2.x1)*(l2.y2-l2.y1);
r=r1/r2;
t=(l1.x1-l2.x1+r*(l1.x2-l1.x1))/(l2.x2-l2.x1);
return r>=0&&r<=1&&t>=0&&t<=1;
}
int main()
{
int t,n,k;
double t1,t2,t3,t4;
fi>>t;
int ans=0;
bool fg;
line x;
while(t--)
{
fi>>n;
for(int i=0;i<n;i++)
{
fi>>t1>>t2>>t3>>t4;
N[i].add_jx(t1,t2,t3,t4);
}
fi>>k;
for(int i=0;i<k;i++)
{
fi>>t1>>t2>>t3>>t4;
x.x1=t1;x.y1=t2;x.x2=t3;x.y2=t4;
for(int i=0;i<n;i++)
{
fg=0;
if(xjxd(N[i].l1,x))
fg=1;
if(xjxd(N[i].l2,x))
fg=1;
if(xjxd(N[i].l3,x))
fg=1;
if(xjxd(N[i].l4,x))
fg=1;
if(fg)
ans++;
}
}
}
fo<<ans;
fi.close();
fo.close();
return 0;
}