poj 2398 Toy Storage
来源:互联网 发布:东软医保软件收费 编辑:程序博客网 时间:2024/05/16 19:16
题意:跟2318一样的,就是给你的纸板没有排序而已。输出为包含这个玩具数的区域有多少个,按升序输出。例如测试数据2: 5,表示最终结果有5个区域的玩具数为2。
分析:将输入的纸板排序后,然后输出改一下即可。
以下附上代码:
#include <algorithm>#include <iostream>#include <cstdio>using std::cout;using std::sort;const int maxn = 1005;struct Point{ int x,y; Point(){} Point(int _x, int _y) : x(_x), y(_y) {}};struct Vec{ Point a,b; Vec(){} Vec(Point _a, Point _b) : a(_a), b(_b) {} Vec(const Vec &t){ a = t.a; b = t.b; } bool operator < (const Vec &t) const{ return a.x < t.a.x; }};int n,m;int x1,y1,x2,y2;Vec box[maxn]; //纸板 int cnt[maxn]; //toys cnt int res[maxn]; //结果 int Cross(Vec a, Point t){ Vec b(a.a,t); int ax = a.b.x - a.a.x; int ay = a.b.y - a.a.y; int bx = b.b.x - b.a.x; int by = b.b.y - b.a.y; return ax * by - ay * bx;}bool input(){ int tx1,tx2; int tx,ty; int i; scanf("%d",&n); if(n == 0) return false; scanf("%d",&m); scanf("%d%d%d%d",&x1,&y1,&x2,&y2); box[0] = Vec(Point(x1, y1), Point(x1, y2)); box[n+1] = Vec(Point(x2, y2), Point(x2, y1)); for(i = 1; i <= n; i++){ scanf("%d%d",&tx1,&tx2); box[i] = Vec(Point(tx1, y1), Point(tx2, y2)); } sort(box,box+n+2); for(i = 0; i <= n; i++){ res[i] = 0; cnt[i] = 0; } return true;}int find(Point t){ int l = 0; int r = n+1; int m; while(r - l > 1){ m = l + (r - l) / 2; if(Cross(box[m], t) < 0){ r = m; } else{ l = m; } } return l;}void solve(){ int x,y; int i; for(i = 0; i < m; i++){ scanf("%d%d",&x,&y); cnt[find(Point(x, y))]++; } for(i = 0; i < maxn; i++){ if(cnt[i]) res[cnt[i]]++; } for(i = 1; i < maxn; i++){ if(res[i]){ printf("%d: %d\n",i,res[i]); } }}int main(){ while(input()){ puts("Box"); solve(); }return 0;}
0 0
- 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
- 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 2398 Toy Storage
- Toy Storage(poj 2398)
- POJ 2398 Toy Storage
- 获取TextView每行的内容 (涉及getLineCount为0,getLineEnd问题)
- GitHub使用教程for Eclipse
- 安装Android Studio出现的问题 SDK无法加载的问题
- iOS webView和JS简单交互处理
- Android WebView Long Press长按保存图片到手机
- poj 2398 Toy Storage
- CSS3 HTML
- [leetcode] Min Stack
- Android4.2.2下Stagefright多媒体架构中的A31的OMX插件和Codec组件
- 监察用户对SharePoint做的操作
- LeetCode(Permutations)
- 在django中使用 mysql 数据库
- HDU_5224 Tom and paper
- openfire