TOYS

题目链接:https://vjudge.net/problem/POJ-2318#author=0

题意:在一个盒子里放入n块纸板进行分割,所有纸板不相交,并是按从左到右的排序顺序指定的,已知m个玩具的坐标,问每个区间内有多少个玩具。

思路:简单几何题,遍历所有纸板和玩具即可,根据他们的差积来判断在哪个区域内。

//#include <bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
struct node
{
    int x,y;
}a[5005];
int book[5005];
int fun(int x1,int y1,int x2,int y2)
{
    return x1*y2-y1*x2;
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        if(n==0)
            break;
        memset(book,0,sizeof(book));
        int m,x1,y1,x2,y2;
        cin>>m>>x1>>y1>>x2>>y2;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i].x>>a[i].y;
        }
        for(int i=1;i<=m;i++)
        {
            int x,y;
            cin>>x>>y;
            int v=n;
            for(int j=1;j<=n;j++)
            {
                int s=a[j].y-a[j].x;
                int w=y2-y1;
                if(fun(s,w,x-a[j].x,y-y1)<0)
                {
                    v=j-1;
                    break;
                }
            }
            book[v]++;
        }
        for(int i=0;i<=n;i++)
          printf("%d: %d
",i,book[i]);
        cout<<endl;
    }
}
原文地址:https://www.cnblogs.com/zcb123456789/p/13645160.html