Toy Storage POJ - 2398
Toy Storage
题目链接:https://vjudge.net/problem/POJ-2398#author=Jawen
题目:





思路:跟toys那题差不多,可看上篇博客,但是这题将bc两点作为一条线,然后将所有的线排序,再来依次判断点是否在线的左边,然后用map来排序方便求出每个toy的数量大小
#include<cmath>
#include<stdio.h>
#include<algorithm>
#include<map>
//#include<bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double inf = 1e100;
const double eps = 1e-6;
const int maxn=1e4+10;
struct Point{
double x, y;
Point(double x = 0, double y = 0):x(x),y(y){}
};
typedef Point Vector;
Vector operator + (Vector A, Vector B){
return Vector(A.x+B.x, A.y+B.y);
}
Vector operator - (Point A, Point B){
return Vector(A.x-B.x, A.y-B.y);
}
Vector operator * (Vector A, double p){
return Vector(A.x*p, A.y*p);
}
Vector operator / (Vector A, double p){
return Vector(A.x/p, A.y/p);
}
double Cross(Vector A, Vector B){
return A.x*B.y-A.y*B.x;
}
bool ToLeftTest(Point a, Point b, Point c){
return Cross(b - a, c - b) > 0;
}
struct Line{
Point c, b;
Line(){}
bool operator<(const Line &other)const{
return this->b.x<other.b.x;
}
};
int main()
{
//freopen("text","r",stdin);
int n;
while(~scanf("%d",&n)&&n){
int m;
double x1,y1,x2,y2;
Point tt[maxn];
Line tt1[maxn];
scanf("%d%lf%lf%lf%lf",&m,&x1,&y1,&x2,&y2);
// cout<<n<<" "<<m<<' '<<x1<<" "<<y1<<' '<<endl;
double b, c;
int pos = 0,pos1=0;
for (int i = 0; i < n; i++) {
scanf("%lf%lf", &c, &b);
tt[pos].x = c, tt[pos].y = y1;
tt1[pos1].c=tt[pos];
pos++;
tt[pos].x = b, tt[pos].y= y2;
tt1[pos1].b=tt[pos];
pos++;
pos1++;
}
tt[pos].x = x2, tt[pos].y = y1;
tt1[pos1].c=tt[pos];
pos++;
tt[pos].x = x2, tt[pos].y = y2;
tt1[pos1].b=tt[pos];
sort(tt1,tt1+pos1);
map<int,int>mm;
int t1, t2, box[maxn] = {0};
for (int i = 0; i < m; ++i) {
scanf("%d%d", &t1, &t2);
Point a;
a.x = t1, a.y = t2;
int num = 0;
for (int j = 0; j <= n; ++j) {
if (ToLeftTest(a, tt1[j].b, tt1[j].c)) {
//cout<<"i="<<i<<","<<ToLeftTest(a,tt[j+1],tt[j])<<endl;
//cout<<"j="<<j<<endl;
num = j;
break;
}
}
box[num]++;
}
sort(box,box+n+1);
for(int i=0;i<=n;i++)
mm[box[i]]++;
for (int i = 0; i <= n;i++) {
//printf("(%d,%d)(%d,%d)\n",tt[i].x,tt[i].y,tt[i+1].x,tt[i+1].y);
if(box[i]!=0)
{
printf("Box\n");
break;
}
}
for(map<int,int>::iterator it=mm.begin();it!=mm.end();it++)
{
if(it->first!=0)
printf("%d: %d\n",it->first,it->second);
}
}
return 0;
}

浙公网安备 33010602011771号