【叉积性质】POJ 2318 TOYS && POJ 2398 Toy Storage
来源:互联网 发布:apache ab工具 编辑:程序博客网 时间:2024/05/16 12:54
http://acm.pku.edu.cn/JudgeOnline/problem?id=2318
//#pragma comment(linker, "/STACK:102400000,102400000")#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;typedef long long LL;#define mem(a, b) memset(a, b, sizeof(a))/*poj 2318给出一个矩形抽屉,然后有n个板子放在其中,连接上下底。给出m个玩具的坐标(视作点),问n+1个区间内,每个区间中有多少玩具。二分,叉乘判点在线段左边或右边*/const int N = 5010;struct Point{ double x,y; }; //点坐标struct V{ Point start,endd; }; //两点式V line[N];int ans[N];double xmult(Point a,Point b,Point c) //(ca)×(cb){ return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);}bool pan(Point p,V ve){ if(xmult(p,ve.endd,ve.start) > 0) return true; return false;}int n,m;void solve(Point p){ if(!pan(p,line[n])){ ans[n]++; return ; } int L = 1, R = n; while(L < R){ int mid = L + (R-L>>1); if(pan(p,line[mid])) R = mid; else L = mid+1; } ans[L-1]++; return ;}int main(){ while(~scanf("%d",&n) && n) { memset(ans,0,sizeof(ans)); double x1,y1,x2,y2; scanf("%d%lf%lf%lf%lf",&m,&x1,&y1,&x2,&y2); for(int i = 1; i <= n; i++) { Point tmp1,tmp2; tmp1.y = y1; tmp2.y = y2; scanf("%lf%lf",&tmp1.x,&tmp2.x); line[i].start = tmp1; line[i].endd = tmp2; } Point p; for(int i = 1; i <= m; i++){ scanf("%lf%lf",&p.x,&p.y); solve(p); } for(int i = 0; i <= n; i++) printf("%d: %d\n",i,ans[i]); puts(""); } return 0;}
http://acm.pku.edu.cn/JudgeOnline/problem?id=2398
//#pragma comment(linker, "/STACK:102400000,102400000")#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;typedef long long LL;#define mem(a, b) memset(a, b, sizeof(a))/*poj 2398给一个矩形,用N条线段将矩形分区域,撒一堆点,找每个区域的点个数有多少。这次给的线段没有按照顺序,所以要对线段排序。输出也有变化,输出的是 点的个数为x的区域个数有多少个Box点的个数x:拥有x个点的区域个数当然x不能等于0二分,叉乘判点在线段左边或右边*/const int N = 5010;struct Point{ double x,y; }; //点坐标struct V{ Point start,endd; }; //两点式V line[N];int ans[N],res[N];double xmult(Point a,Point b,Point c) //(ca)×(cb){ return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);}bool pan(Point p,V ve){ if(xmult(p,ve.endd,ve.start) > 0) return true; return false;}bool cmp(V x,V y){ return pan(x.start,y);}int n,m;void solve(Point p){ if(!pan(p,line[n])){ ans[n]++; return ; } int L = 1, R = n; while(L < R){ int mid = L + (R-L>>1); if(pan(p,line[mid])) R = mid; else L = mid+1; } ans[L-1]++; return ;}int main(){ while(~scanf("%d",&n) && n) { memset(ans,0,sizeof(ans)); memset(res,0,sizeof(res)); double x1,y1,x2,y2; scanf("%d%lf%lf%lf%lf",&m,&x1,&y1,&x2,&y2); for(int i = 1; i <= n; i++) { Point tmp1,tmp2; tmp1.y = y1; tmp2.y = y2; scanf("%lf%lf",&tmp1.x,&tmp2.x); line[i].start = tmp1; line[i].endd = tmp2; } sort(line+1,line+n+1,cmp); Point p; for(int i = 1; i <= m; i++){ scanf("%lf%lf",&p.x,&p.y); solve(p); } for(int i = 0; i <= n; i++) {// printf("%d: %d\n",i,ans[i]); res[ans[i]]++; } puts("Box"); for(int i = 1; i <= m; i++) if(res[i]) printf("%d: %d\n",i,res[i]); } return 0;}
阅读全文
0 0
- 【叉积性质】POJ 2318 TOYS && POJ 2398 Toy Storage
- POJ 2318 TOYS && POJ 2398 Toy Storage
- POJ 2318 TOYS || POJ 2398 Toy Storage
- poj 2318 TOYS & poj 2398 Toy Storage (叉积)
- POJ 2318:TOYS & POJ 2398:Toy Storage 计算几何
- POJ 2398:Toy Storage _叉积性质
- POJ 2318 TOYS + 2398 Toy Storage(计算几何叉积)
- POJ 2318 TOYS + POJ 2398 Toy Storage (点与直线的位置关系)
- POJ 2318 TOYS && POJ 2398 Toy Storage [判断点在四边形中]
- poj 2398 Toys storage
- poj 2398 Toy Storage
- poj 2398 Toy Storage
- POJ 2398 Toy Storage
- POJ 2398 Toy Storage
- poj 2398 toy storage
- poj 2398 Toy Storage
- POJ 2398 Toy Storage
- poj 2398Toy Storage
- 大众点评CAT安装部署记录
- Tomcat 9 + Let's encrypt 免费 SSL 升级 https
- c语言操作符
- AsyncTask,在studio中会用到子节流转换字符串
- FM1702 13.56MHz RF PCB天线调试经验记录
- 【叉积性质】POJ 2318 TOYS && POJ 2398 Toy Storage
- 二维码扫描
- 进程间通讯——信号量(一)
- 51nod 1019 逆序数 (归并排序)
- 单词,紫书P169UVa10129(有向图求欧拉路径问题,并查集求连通分支)
- 句子的逆序 -- 算法小结
- 【AC梦工厂】广工华工联合训练6 K
- PAT乙级1064. 朋友数(20)
- SpringMVC中的/*和/的区别