- 浏览: 380146 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (229)
- java编程 (4)
- java实用程序 (2)
- 算法设计 (34)
- 数据库 (8)
- ACM模板 (12)
- 技术术语 (1)
- java_web (3)
- php (22)
- eclipse (3)
- linux (25)
- linux命令使用心得 (3)
- web服务器 (8)
- IT知识 (2)
- 前端技术 (17)
- 开源软件 (5)
- vim (3)
- linux多线程 (9)
- web开发经验 (3)
- lua (5)
- linux编程 (3)
- smarty (1)
- mysql (4)
- Hive (2)
- 数据挖掘 (9)
- python (2)
- 生活 (1)
- C++ (2)
- 计算机 (1)
- objective-c (11)
- css (2)
- 游戏 (1)
- Mac (1)
最新评论
-
lr544463316:
我的怎么不行呀.....
Mysql Access denied for user ''@'localhost' to database 的一种解决方法 -
babaoqi:
使用时需要注意group_concat函数返回值的最大长度=g ...
mysql中的group_concat函数 -
代码能力弱成渣:
可以帮我看下我的代码么?我自己写的sam,也有ac过题的,但是 ...
求两个字符串的最长公共连续子序列(SAM实现) -
atgoingguoat:
有1000个?不过还是收藏下。
jquery常用的插件1000收集(转载)
/* 刚开始打了个记录上下左右四个点的,一直tle。 研究了isun大牛的代码后发现原来可以更简单………… */ #include <cstdio> #include <algorithm> #include <cmath> using namespace std; typedef double typev; const int N=105; const int Q=1005; const int M=10005; const double eps=1e-8; const double pi=acos(-1.0); int sign(double d){ return d<-eps?-1:(d>eps); } struct point{ typev x, y; point(double _x=0, double _y=0):x(_x), y(_y){} point operator-(point tp){ return point(x-tp.x, y-tp.y); } double operator^(point tp){ return x*tp.y-y*tp.x; } void read(){ scanf("%lf%lf", &x, &y); } }hull[N][Q], ps[Q]; struct ray{ point st, v; double ang; int id; bool operator<(const ray& _ray)const{ return ang<_ray.ang; } }; int hn[N], n, m; int ls[N], rs[N]; int ans[M]; ray rays[M]; bool cmp(point d1, point d2){ return d1.x < d2.x || (d1.x == d2.x && d1.y < d2.y); } typev xmul(point st1, point ed1, point st2, point ed2){ return (ed1.x-st1.x) * (ed2.y-st2.y) - (ed1.y-st1.y) * (ed2.x-st2.x); } //对ps求凸包,结果放在hull里 void graham(point* ps, int n, point* hull, int& hn){ int i; if(n<=2){ hn=n; for(i=0; i<n; i++){ hull[i]=ps[i]; } return; } sort(ps, ps+n, cmp); hull[0] = ps[0]; hull[1] = ps[1]; int top = 1; for(i = 2; i < n; i++){ while(top > 0 && xmul(ps[i], hull[top-1], ps[i], hull[top]) >= 0) top--; hull[++top] = ps[i]; } int tmp = top; for(i = n-2; i >= 0; i--){ while(top > tmp && xmul(ps[i], hull[top-1], ps[i], hull[top]) >= 0) top--; hull[++top] = ps[i]; } hn = top; hull[hn] = hull[0]; } bool input(){ scanf("%d", &n); int i, j, qn; for(i=0; i<n; i++){ scanf("%d", &qn); for(j=0; j<qn; j++){ ps[j].read(); } graham(ps, qn, hull[i], hn[i]); //保证点是逆时针方向的 reverse(hull[i], hull[i]+hn[i]); } scanf("%d", &m); for(i=0; i<m; i++){ rays[i].st.read(); rays[i].v.read(); rays[i].id=i; rays[i].ang=atan2(rays[i].v.y, rays[i].v.x); } return true; } void solve(){ sort(rays, rays+m); int i, j, u; point *h; point a, b, c, d; ray r; for(i=0; i<n; i++){ ls[i]=rs[i]=0; } for(i=0; i<m; i++){ u=-1; r=rays[i]; for(j=0; j<n; j++){ h=hull[j]; while((r.v^h[(ls[j]+1)%hn[j]]-h[ls[j]]) > 0){ ls[j]=(ls[j]+1)%hn[j]; } while((r.v^h[(ls[j]-1+hn[j])%hn[j]]-h[ls[j]]) > 0){ ls[j]=(ls[j]-1+hn[j])%hn[j]; } while((r.v^h[(rs[j]+1)%hn[j]]-h[rs[j]])<0){ rs[j]=(rs[j]+1)%hn[j]; } while((r.v^h[(rs[j]-1+hn[j])%hn[j]]-h[rs[j]])<0){ rs[j]=(rs[j]-1+hn[j])%hn[j]; } if((h[rs[j]]-h[ls[j]]^r.st-h[ls[j]])>0) continue; if(sign(r.v^h[ls[j]]-r.st)*sign(r.v^h[rs[j]]-r.st)>0) continue; if(u==-1){ u=j; }else{ a=h[ls[j]]; b=h[rs[j]]; c=hull[u][ls[u]]; d=hull[u][rs[u]]; if(((b-a^c-a)>0 && (b-a^c-a)>0) || ((d-c^a-c)<0 && (d-c^b-c)<0)){ u=j; } } } ans[r.id]=u; } for(i=0; i<m; i++){ if(ans[i]==-1){ printf("MISS\n"); }else{ printf("HIT %d\n", ans[i]); } } printf("*****\n"); } int main(){ // freopen("in.txt", "r", stdin); int t; scanf("%d", &t); while(t--){ input(); solve(); } return 0; }
发表评论
-
升序数组中求一个key出现的次数
2013-01-09 23:08 1068算法思路: 在排好序的数组,相同的数字是排列在一起的,所以只需 ... -
判断单链表是否有环
2013-01-08 19:07 888算法思路: 指针p1和p2的起始值均为链表的表头,指针p1每次 ... -
hdu3686
2011-11-14 20:43 1006/* 无向图边的双连通分量,在同一个连通分量里的边之间 ... -
poj3968
2011-11-14 04:45 1379source: http://poj.org/problem ... -
uva2819
2011-11-13 02:20 863source: http://livearchive.onli ... -
manacher算法
2011-11-11 00:06 2412const int LEN=110005; const ... -
hdu4118
2011-11-09 21:53 1163枚举每条边最多被经过的次数即可 #include ... -
hdu4115
2011-11-09 16:27 998source: http://acm.hdu.edu.cn/ ... -
uva(Transitive Closure)
2011-11-08 14:45 884source: http://livearchive.onli ... -
zoj3500
2011-11-07 17:41 926求两个球的体积交或者并 #include <cs ... -
zoj3545
2011-11-04 18:18 842/* AC自动机 相当暴力的 解法: mark[i ... -
zoj3190
2011-11-04 17:34 1254/* * AC自动机,先对资源串和病毒串构成的字符串 ... -
zoj3228
2011-11-04 16:12 928/* * AC自动机,每个节点 添加一个d表示节点代 ... -
poj3691(DNA Repair)
2011-11-04 13:18 1454/* AC自动机,增设虚拟节点,求长度为n的字符串中包 ... -
hdu2825
2011-11-04 11:53 961/* AC自动机,增设虚拟节点,求长度为n的字符 ... -
hdu4095
2011-11-03 13:19 991/* 第一步,构建BST,用第一个数作为bst的 ... -
zoj3540
2011-11-02 21:33 894/* 其实就是把总共的 放置次数减去不能放置的那些就行 ... -
poj1741(树的分治,基于边的 分治)
2011-11-02 20:25 3326/* 树基于边的分治算法,计算树中距离小于等于k的点 ... -
hdu2939
2011-10-29 18:36 823source: http://acm.hdu.edu.cn/s ... -
hdu3982
2011-10-29 10:20 909//半平面交+多边形和圆的交的面积 #include ...
相关推荐
HDU的1250,主要是利用高精度加法,但是代码有点繁琐,效率不是很高
HDU1059的代码
杭电ACMhdu1163
hdu1001解题报告
hdu 1574 passed sorce
HDU的一题........HDU DP动态规
hdu acm 教案 搜索入门 hdu acm 教案 搜索入门
hdu2101AC代码
搜索 dfs 解题代码 hdu1241
hdu acm 教案 动态规划(1) hdu acm 教案 动态规划(1)
ACM HDU题目分类,我自己总结的大概只有十来个吧
hdu 5007 Post Robot 字符串枚举。 暴力一下就可以了。
HDU最全ac代码
hdu 1166线段树代码
hdu动态规划算法集锦
hdu-acm源代码(上百题)hdu-acm源代码、hdu-acm源代码hdu-acm源代码
hdu题目分类
HDU图论题目分类
自己做的HDU ACM已经AC的题目
hdu 1005.比较简单的一道题,有兴趣的可以看看。