poj 2318(链接)

//第一发:莽写(利用ToLefttest)
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std; struct Point{
int x,y;
}edge[5005],point[5005]; int a[5005]; bool ToLeft(int a,int b,int c,int d,int e,int f)
{
if((a*d+b*e+c*f-d*e-b*c-a*f)<0)return true;
else return false;
} int main ()
{
int n,m;
while(cin>>n,n)
{
cin>>m;
memset(a,0,sizeof(a));
cin>>edge[0].x>>edge[0].y>>point[0].x>>point[0].y;
for(int i=1;i<=n;i++)
cin>>edge[i].x>>edge[i].y;
for(int i=1;i<=m;i++)
cin>>point[i].x>>point[i].y;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(ToLeft(edge[i].x,edge[0].y,edge[i].y,point[0].y,point[j].x,point[j].y))
a[i]++;
for(int i=0;i<n;i++)
cout<<i<<':'<<' '<<a[i+1]-a[i]<<endl;
cout<<n<<':'<<' '<<m-a[n]<<endl<<endl;
}
return 0;
}

通过ToLefttest进行判断是否在每个箱子右边界的逆时针方向的左边;

#include<cstring >
#include<iostream>
using namespace std; //第二发:参考kuangbin(利用二分+叉积)
struct Point {
int x,y;
Point (){};
Point(int _x,int _y)
{
x=_x,y=_y;
}
Point operator -(const Point &b)const
{
return Point(x-b.x,y-b.y);
}
int operator *(const Point &b)const
{
return x*b.x+y*b.y;
}
int operator ^(const Point &b)const
{
return x*b.y-y*b.x;
}
}; struct Line{
Point s,e;
Line(){};
Line(Point _s,Point _e)
{
s=_s,e=_e;
}
}; int xmult(Point p0,Point p1,Point p2)//求P0p1和 p0p2 的叉积
{
return (p1-p0)^(p2-p0);
} const int MAXN=5050;
Line line[MAXN];
int ans[MAXN]; int main ()
{
int n,m,x1,y1,x2,y2;
while(cin>>n,n)
{
cin>>m>>x1>>y1>>x2>>y2;
int U,L;
for(int i=0;i<n;i++)
{
cin>>U>>L;
line[i]=Line(Point(U,y1),Point(L,y2));
}
line[n]=Line(Point(x2,y1),Point(x2,y2));
int x,y;
Point p;
memset(ans,0,sizeof(ans));
while(m--)
{
cin>>x>>y;
p=Point(x,y);
int l=0,r=n;
while(l<r)
{
int mid=(l+r)/2;
if(xmult(p,line[mid].e,line[mid].s)>0)
r=mid;
else
l=mid+1;
}
ans[l]++;
}
for(int i=0;i<=n;i++)
cout<<i<<": "<<ans[i]<<endl;
cout<<endl;
}
return 0;
}

通过叉积进行判断:

poj 2318TOYS的更多相关文章

  1. POJ 2318--TOYS(二分找点,叉积判断方向)

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17974   Accepted: 8539 Description ...

  2. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  3. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  4. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  5. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  6. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  7. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  8. POJ 2255. Tree Recovery

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 De ...

  9. POJ 2752 Seek the Name, Seek the Fame [kmp]

    Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Ac ...

随机推荐

  1. 【JavaWeb】JSON 文件

    JSON 文件 什么是 JSON JSON(JavaScript Object Notation),即 JS 对象符号. 是一种轻量级(相对于 XML 来说)的数据交换格式,易于阅读和编写,同时也易于 ...

  2. ajax跨域访问http服务--jsonp

    在前面一篇文章<Spring Cloud 前后端分离后引起的跨域访问解决方案>里我们提到使用ajax跨域请求其他应用的http服务,使用的是后台增加注解@CrossOrigin或者增加Co ...

  3. 通过SE14重建数据库表

    通过程序中的SQL语句向数据库表中插入的内容,系统无法转换,并且已经存在于数据库表中,那么当对该表进行保存数据的修改时,可能会导致该表从数据库中的删除. 举了例子:(完全是为了方便理解) SAP系统, ...

  4. REUSE_ALV_FIELDCATALOG_MERGE函数

    今天使用REUSE_ALV_FIELDCATALOG_MERGE函数,就是获取不到fieldcat, 搞了半天才发现,原来参数要全部大写才行!!小写字符就是获取不到,唉,悲哀...

  5. 宝塔的url计划任务

    to通过url访问 就像访问你的网站一样 然后控制器/方法里面写你要做的操作 就可以了 ,简单的一批

  6. floating point

    记录浮点数的单精度和双精度(IEEE754) 1.单精度(float) ​ 1.定义:单精度占4字节/32位,其中1号位符号位,其次是8位阶码/指数(阶符+阶数),23位尾数(小数). 2.双精度(d ...

  7. OpenCV 和 Dlib 人脸识别基础

    00 环境配置 Anaconda 安装 1 下载 https://repo.anaconda.com/archive/ 考虑到兼容性问题,推荐下载Anaconda3-5.2.0版本. 2 安装 3 测 ...

  8. 人工智能"眼睛"——摄像头

    摄像头机器视觉人工智能的"眼睛",其重要性在嵌入式领域不言而喻.但是如何理解和使用摄像头却是一个非常棘手的问题.本文主要针对调试摄像头过程中遇到的问题,对摄像头的基本原理及概述进行 ...

  9. Spring 是如何解决循环依赖的?

    前言 相信很多小伙伴在工作中都会遇到循环依赖,不过大多数它是这样显示的: 还会提示这么一句: Requested bean is currently in creation: Is there an ...

  10. apk开发环境!多亏这份《秋招+金九银十-腾讯面试题合集》跳槽薪资翻倍!再不刷题就晚了!

    开头 最近很多网友反馈:自己从各处弄来的资料,过于杂乱.零散.碎片化,看得时候觉得挺有用的,但过个半天,啥都记不起来了.其实,这就是缺少系统化学习的后果. 为了提高大家的学习效率,帮大家能快速掌握An ...