hdu 5032 树状数组+极角排序
2015-03-05 21:24
225 查看
裸题
#include <iostream> #include <cstring> #include <algorithm> #include <cstdio> #define MAX 1007 #define eps 1e-8 using namespace std; typedef long long LL; int t,A,B,m; struct Point { int x,y; LL ans; double angle; }p[MAX*MAX],q[MAX*MAX]; bool cmp1 ( Point a , Point b ) { return a.angle < b.angle; } bool cmp2 ( Point a , Point b ) { return a.y < b.y; } LL c[MAX]; int lowbit ( int x ) { return x&-x; } void add ( int x , LL v ) { while ( x <= 1000 ) { c[x] += v ; x += lowbit ( x ); } } LL sum ( int x ) { LL ret = 0; while ( x ) { ret += c[x]; x -= lowbit ( x ); } return ret; } int main ( ) { scanf ( "%d" , &t ); int cc = 1; int cnt = 0; for ( int i = 1 ; i <= 1000 ; i++ ) for ( int j = 1 ; j <= 1000 ; j++ ) { p[cnt].x = i , p[cnt].y = j; p[cnt++].angle = j*1.0/(i*1.0); } sort ( p , p + cnt , cmp1 ); while ( t-- ) { memset ( c , 0 , sizeof ( c ) ); scanf ( "%d%d" , &A , &B ); scanf ( "%d" , &m ); for ( int i = 0 ; i < m ; i++ ) { int a , b; scanf ( "%d%d%d" , &a , &b , &q[i].x ); q[i].y = i; q[i].angle = b*1.0/(a*1.0); } sort ( q , q + m , cmp1 ); int num = 0; for ( int i = 0 ; i < m ; i++ ) { while ( num!= cnt ) { if ( p[num].angle > q[i].angle ) break; add ( p[num].x , ((LL)( p[num].x + A )) * ((LL) ( p[num].y + B )) ); num++; } q[i].ans = sum ( q[i].x ); } sort ( q , q + m , cmp2 ); printf ( "Case #%d:\n" , cc++ ); for ( int i = 0 ; i < m ; i++ ) printf ( "%I64d\n" , q[i].ans ); } }
相关文章推荐
- HDU 5032 Always Cook Mushroom(极角排序, 树状数组)
- HDU 5032 Always Cook Mushroom (极角排序 x 树状数组)
- HDU 5032 Always Cook Mushroom 极角排序 数状数组 姿势
- hdu--4911--归并排序||树状数组
- hdu 1541 Stars(排序+树状数组)
- hdu 5032 Always Cook Mushroom 离线树状数组
- HDU ~ 1394 ~ Minimum Inversion Number(暴力||归并排序||线段树||树状数组)
- [hdu 5032]2014北京网络赛Always Cook Mushroom 离线线段树/树状数组
- HDU 3074 Multiply game 逆元 树状数组
- hdu 1209 clocks wrong answer 我的错误代码(没审好题唉,角度一样后,还要按小时排序。
- hdu 3789 奥运排序问题
- HDU 2492pingpong--树状数组
- 杭电 hdu 2000 ASCII码排序
- ACM 算法总结 --- 排序 HDOJ HDU 2094 产生冠军 ACM 2094 IN HDU
- HDU 1106 排序
- hdu 1106 排序
- hdu 1166 树状数组
- hdu 1541 树状数组版)——咯咯
- sort 1425 hdu(hash 和 sort排序)
- [hdu]1166敌兵布阵-线段树&树状数组