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. Hibernate+EhCache配置二级缓存

    步骤: 第一步:加入ehcache.jar 第二步: 在src目录下新建一个文件,名为:ehcache.xml 第三步:在hibernate配置文件的<session-factory>下配 ...

  2. Leetcode分类刷题答案&心得

    Array 448.找出数组中所有消失的数 要求:整型数组取值为 1 ≤ a[i] ≤ n,n是数组大小,一些元素重复出现,找出[1,n]中没出现的数,实现时时间复杂度为O(n),并不占额外空间 思路 ...

  3. secureCRT

    配色方案 1

  4. Java学习笔记之JNDI(六)

    JNDI 是什么 JNDI是 Java 命名与目录接口(Java Naming and Directory Interface),在J2EE规范中是重要的规范之一,不少专家认为,没有透彻理解JNDI的 ...

  5. Sass学习笔记

    语法 @each $var in <list>//循环就是去遍历一个列表,然后从列表中取出对应的值 @while $types > 0 //循环直到函数不成立 SASS函数 To-u ...

  6. css 文字超出部分显示省略号(原)

    单行超出省略号 #word1{width: 100px; text-overflow: ellipsis; overflow: hidden;} 几行超出省略号(只兼容webkit内核) #wordN ...

  7. JavaScript系列文章:变量提升和函数提升

    第一篇文章中提到了变量的提升,所以今天就来介绍一下变量提升和函数提升.这个知识点可谓是老生常谈了,不过其中有些细节方面博主很想借此机会,好好总结一下. 今天主要介绍以下几点: 1. 变量提升 2. 函 ...

  8. JavaScript系列文章:从let和const谈起

    注册博客园账号也有好些年了,有事没事经常来逛逛,感觉博客园的同学们一直都很活跃,相比国内其他社区来讲,这里的技术氛围很浓,非常适合学习和交流,所以博主我也决定在这里驻扎了,在这里,博主希望能坚持写一些 ...

  9. Android Studio解决未识别Java文件(出现红J)问题

    1.问题:java文件出现了红J的问题,正常情况下应该是显示蓝色的C标识. 2.解决方案:切换到project视图下,找到app这个module里的build.gradle,在android结构里插入 ...

  10. github 相关英语

    github 相关英语 repository n. 仓库 A repository contains all the files for your project, including the rev ...