poj 2318TOYS
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的更多相关文章
- POJ 2318--TOYS(二分找点,叉积判断方向)
TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17974 Accepted: 8539 Description ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2255. Tree Recovery
Tree Recovery Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11939 Accepted: 7493 De ...
- 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 ...
随机推荐
- Python pip install 默认路径修改。
pip动不动就下载数百M的文件.这些文件默认在C:盘,那么为了节省空间需要修改这些路径: 打开cmd命令窗口.输入: python -m site C:\Users\hewei>python - ...
- yum -y install gnuplot
[root@test~]# yum -y install gnuplotLoaded plugins: fastestmirrorLoading mirror speeds from cached h ...
- 如何跑通第一个 SQL 作业
简介: 本文由阿里巴巴技术专家周凯波(宝牛)分享,主要介绍如何跑通第一个SQL. 一.SQL的基本概念 1.SQL 分类 SQL分为四类,分别是数据查询语言(DQL).数据操纵语言(DML).数据定义 ...
- 爬虫系列 | 6、详解爬虫中BeautifulSoup4的用法
bs4,全称BeautifulSoup 4 , 它是Python独有的一种解析方式.也就是说只有Python语言才可以通过这种方式去解析数据. BeautifulSoup 3 只支持Python2,所 ...
- AQS之ReentrantReadWriteLock精讲分析上篇
1.用法 1.1 定义一个安全的list集合 public class LockDemo { ArrayList<Integer> arrayList = new ArrayList< ...
- 【Not BUG】微软Winform窗体中设计上的Bug,会导致程序编译失败?不,这不是BUG!
这不是BUG!!! 原文地址: https://www.cnblogs.com/thanks/p/14302011.html 现在让我们回忆一下原文 原文的操作步骤: 1. 新建一个Window Fo ...
- postgresql-12编译安装
1 准备环境 修改yum源 mkdir -p /etc/yum.bak mv /etc/yum.repos.d/* /etc/yum.bak/ &&\ curl -o /etc/yum ...
- 2021 Duilib最新入门教程(一)Duilib简介
目录 Duilib解决什么问题? 方案一.自己画界面 方案二.使用标准控件 方案三.使用Duilib框架 Duilib是什么? 先看下Duilib官方简介 再看下DirectUI 百度百科 比起介 ...
- .NET Core 问题记录
前言: 最近在项目中遇到了遇到了写部署步骤过多的问题,为了减少.net core项目部署步骤:需要对一些基础问题进行验证: 如端口设置.单页应用程序(angluar)合并部署方式等相关问题,特将解决过 ...
- 第2章_神经网络入门_2-5&2-6 数据处理与模型图构建
目录 神经元的TF实现 安装 神经网络的TF实现 神经元的TF实现 安装 版本: Python 2.7 tf 1.8.0 Linux 略 demo 神经网络的TF实现 # py36 tf 2.1. # ...