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 ...
随机推荐
- JVM 源码分析(三):深入理解 CAS
前言 什么是 CAS Java 中的 CAS JVM 中的 CAS 前言 在上一篇文章中,我们完成了源码的编译和调试环境的搭建. 鉴于 CAS 的实现原理比较简单, 然而很多人对它不够了解,所以本篇将 ...
- 【SpringBoot1.x】SpringBoot1.x 分布式
SpringBoot1.x 分布式 分布式应用 Zookeeper&Dubbo ZooKeeper 是用于分布式应用程序的高性能协调服务.它在一个简单的界面中公开了常见的服务,例如命名,配置管 ...
- 剑指offer 面试题7:重建二叉树
题目描述 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7, ...
- 天梯赛练习 L3-007 天梯地图 (30分) Dijkstra
题目分析: 本题的题意比较清晰,就是有一个起点和一个终点,给出m条路径,可能是单向的可能是双向的,同时一条路有两个权重,分别是通过这条路需要的时间和这条路的路径长度,题目需要求出两条路径,一条是在最快 ...
- 手把手教你搭建一个跟vue官方同款文档(vuepress)
前言 VuePress 由两部分组成:第一部分是一个极简静态网站生成器 (opens new window),它包含由 Vue 驱动的主题系统和插件 API,另一个部分是为书写技术文档而优化的默认主题 ...
- Java 使用URL类通过url下载网络资源
主要用到的类 地址类: URL http类: HttpURLConnection 输入流: InputStream 输出流: FileOutputStream 上代码 package com.demo ...
- Docker Hub公共镜像仓库的使用
创建账号并登陆这里是登陆入口 登陆账号 登陆进入之后里面目前仓库,现在去创建一个 下面我选的是公共仓库,别人也可以访问到 在服务器上登陆进来,进行上传镜像到仓库 [root@docker ~]# do ...
- python--or 和 and 表达式
or表达式: 两边为一真一假,返回真: 两边都为假,返回右边: 两边都为真,返回左边: and表达式: 两边为一真一假,返回假: 两边都为假,返回左边: 两边都为真,返回右边:
- 【ELK】elastalert 日志告警
一.环境 系统:centos7 elk 版本:7.6.2 1.1 ElastAlert 工作原理 周期性的查询Elastsearch并且将数据传递给规则类型,规则类型定义了需要查询哪些数据. 当一个规 ...
- 与图论的邂逅07:K短路
在做最短路的题时我们不免会碰到许多求次短路的题,然而我们也能很快地想到解决的办法: 用dijkstra跑一遍最短路,当终点第二次被取出时就是次短路了.时间复杂度为O((N+M)logN).实际上前面得 ...