POJ2318

  本题需要运用to left test不断判断点处于哪个分区,并统计分区的点个数(保证点不在边界和界外),用来做叉积入门题很合适

//计算几何-叉积入门题
//Time:157Ms Memory:828K
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 5005
struct Point{
int x,y;
Point(int xx=0, int yy=0):x(xx), y(yy){}
friend bool operator < (Point p1, Point p2){
return (p1.x < p2.x) || (p1.x == p2.x && p1.y < p2.y);
}
}ul, lr, p[2*MAXN], toy[MAXN];
int n, m;
int num[MAXN];
int cross(Point a, Point b, Point s)//叉积-(s在ab左侧返回>0)
{
return (a.x-s.x) * (b.y-s.y) - (a.y-s.y) * (b.x-s.x);
}
int main()
{
//freopen("in.txt", "r", stdin);
while(scanf("%d", &n), n)
{
memset(num, 0, sizeof(num));
scanf("%d%d%d%d%d", &m, &ul.x, &ul.y, &lr.x, &lr.y);
for(int i=0; i<n; i++)
{
int u,l;
scanf("%d%d", &u,&l);
p[2*i] = Point(u, ul.y);
p[2*i+1] = Point(l, lr.y);
}
p[2*n] = Point(lr.x, ul.y);
p[2*n+1] = Point(lr.x, lr.y);
for(int i=0; i<m; i++)
scanf("%d%d", &toy[i].x, &toy[i].y);
sort(toy, toy+m);
int cur = 0;
for(int i=0; i<m; i++)
{
for(int j=cur; j<=n; j++)
{
if(cross(p[j*2+1], p[j*2], toy[i]) > 0) //to left test
{
num[j]++; break;
}
}
while(toy[i].x > max(p[cur*2+1].x, p[cur*2].x))
cur++;
}
for(int i = 0; i <= n;i++)
printf("%d: %d\n", i, num[i]);
printf("\n");
}
return 0;
}

  POJ2398

  题意同上,不同在于线段是随机的(需对线段排序),且要求输出为相同统计数的格子数量

  

//计算几何-叉积入门题-需对线段排序
//题意同POJ2318
//Time:0Ms Memory:724K
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 1005
struct Point{
int x,y;
Point(int xx=0, int yy=0):x(xx), y(yy){}
friend bool operator < (Point p1, Point p2){
return (p1.x < p2.x) || (p1.x == p2.x && p1.y < p2.y);
}
}ul, lr, toy[MAXN];
struct Line{
int a,b,c,d;
Line(int aa=0, int bb=0, int cc=0, int dd=0):a(aa),b(bb),c(cc),d(dd){}
friend bool operator < (Line l1, Line l2){
return (l1.a < l2.a) || (l1.a == l2.a && l1.c < l2.c);
}
}line[MAXN];
int n, m;
int num[MAXN], cnt[MAXN];
int cross(Point a, Point b, Point s)//叉积-(s在ab左侧返回>0)
{
return (a.x-s.x) * (b.y-s.y) - (a.y-s.y) * (b.x-s.x);
}
int main()
{
//freopen("in.txt", "r", stdin);
while(scanf("%d", &n), n)
{
memset(num, 0, sizeof(num));
memset(cnt, 0, sizeof(cnt));
scanf("%d%d%d%d%d", &m, &ul.x, &ul.y, &lr.x, &lr.y);
for(int i=0; i<n; i++)
{
int u,l;
scanf("%d%d", &u,&l);
line[i] = Line(u, ul.y, l, lr.y);
}
line[n] = Line(lr.x, ul.y, lr.x, lr.y);
sort(line, line+n+1);
for(int i=0; i<m; i++)
scanf("%d%d", &toy[i].x, &toy[i].y);
sort(toy, toy+m);
int cur = 0;
for(int i=0; i<m; i++)
{
for(int j=cur; j<=n; j++)
{
if(cross(Point(line[j].c, line[j].d), Point(line[j].a,line[j].b), toy[i]) > 0) //to left test
{
num[j]++; break;
}
}
while(toy[i].x > max(line[cur].a, line[cur].c))
cur++;
}
for(int i=0; i<=n; i++)
cnt[num[i]]++;
printf("Box\n");
for(int i = 1; i <= n;i++)
if(cnt[i]) printf("%d: %d\n", i, cnt[i]);
}
return 0;
}

ACM/ICPC 之 计算几何入门-叉积-to left test(POJ2318-POJ2398)的更多相关文章

  1. ACM/ICPC 之 网络流入门-EK算法(参考模板)(POJ1273)

    基于残留网络与FF算法的改进-EK算法,核心是将一条边的单向残留容量的减少看做反向残留流量的增加. //网络流 //EK算法 //Time:16Ms Memory:348K #include<i ...

  2. ACM/ICPC 之 网络流入门-Ford Fulkerson与SAP算法(POJ1149-POJ1273)

    第一题:按顾客访问猪圈的顺序依次构图(顾客为结点),汇点->第一个顾客->第二个顾客->...->汇点 //第一道网络流 //Ford-Fulkerson //Time:47M ...

  3. 【转】lonekight@xmu·ACM/ICPC 回忆录

    转自:http://hi.baidu.com/ordeder/item/2a342a7fe7cb9e336dc37c89 2009年09月06日 星期日 21:55 初识ACM最早听说ACM/ICPC ...

  4. 2015 ACM / ICPC 亚洲区域赛总结(长春站&北京站)

    队名:Unlimited Code Works(无尽编码)  队员:Wu.Wang.Zhou 先说一下队伍:Wu是大三学长:Wang高中noip省一:我最渣,去年来大学开始学的a+b,参加今年区域赛之 ...

  5. 训练报告 (2014-2015) 2014, Samara SAU ACM ICPC Quarterfinal Qualification Contest

    Solved A Gym 100488A Yet Another Goat in the Garden   B Gym 100488B Impossible to Guess Solved C Gym ...

  6. POJ P2318 TOYS与POJ P1269 Intersecting Lines——计算几何入门题两道

    rt,计算几何入门: TOYS Calculate the number of toys that land in each bin of a partitioned toy box. Mom and ...

  7. 2014嘉杰信息杯ACM/ICPC湖南程序设计邀请赛暨第六届湘潭市程序设计竞赛

    比赛链接: http://202.197.224.59/OnlineJudge2/index.php/Contest/problems/contest_id/36 题目来源: 2014嘉杰信息杯ACM ...

  8. ACM/ICPC 之 BFS(离线)+康拓展开(TSH OJ-玩具(Toy))

    祝大家新年快乐,相信在新的一年里一定有我们自己的梦! 这是一个简化的魔板问题,只需输出步骤即可. 玩具(Toy) 描述 ZC神最擅长逻辑推理,一日,他给大家讲述起自己儿时的数字玩具. 该玩具酷似魔方, ...

  9. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 G. Garden Gathering

    Problem G. Garden Gathering Input file: standard input Output file: standard output Time limit: 3 se ...

随机推荐

  1. git 指令

    單獨看這個 commit id 做了什麼修改 git show CommitID or git diff CommitID^!

  2. oracle db link的查看创建与删除

    1.查看dblink select owner,object_name from dba_objects where object_type='DATABASE LINK'; 或者 select * ...

  3. ABP 索引

    官方网站 Github ABP集合贴 @ kebinet https://www.codeproject.com/articles/1115763/using-asp-net-core-entity- ...

  4. Steamroller

    FCC题目:对嵌套的数组进行扁平化处理.你必须考虑到不同层级的嵌套. 示例: steamroller([[["a"]], [["b"]]]) 应该返回 [&qu ...

  5. js函数表达式和函数声明的区别

    我们已经知道,在任意代码片段外部添加包装函数,可以将内部的变量和函数定义"隐 藏"起来,外部作用域无法访问包装函数内部的任何内容. 例如: var a = 2; function ...

  6. ionic 发布 inoc显示不正确

    前两天因为学习的问题,把本地环境给搞崩了,然后重新安装环境之后发现生成的安装包不能使用,然后找了很多原因都不能解决,因为之前发布ios的时候使用命令 ionic resources的时候就可以将图标显 ...

  7. easyUI 如何不跳转页面,只是加载替换center部分内容

    以前做的一个故障报修系统,前端框架使用easyUI框架,layout布局,center使用datagrid .点击左边树形菜单时时页面跳转,想要知道如何点击菜单时不进行页面跳转,而是只对center模 ...

  8. Html中的文本框和单选按钮

    Html中的文本框和单选按钮用来制作页面的登录注册使用.. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN& ...

  9. vim(vi)常用操作及记忆方法

    vi(vim)可以说是linux中用得最多的工具了,不管你配置服务也好,写脚本也好,总会用到它.但是,vim作为一个“纯字符”模式下的工具,它的操作和WINDOWS中的文本编辑工具相比多少有些复杂.这 ...

  10. Codis——分布式Redis服务的解决方案

    Codis——分布式Redis服务的解决方案 之前介绍过的 Twemproxy 是一种Redis代理,但它不支持集群的动态伸缩,而codis则支持动态的增减Redis节点:另外,官方的redis 3. ...