hdu5032 Always Cook Mushroom
来源:互联网 发布:淘宝推送多少钱 编辑:程序博客网 时间:2024/05/16 18:39
题意是这样,给定一个1000x1000的点阵,m组询问,每次询问一个由(0,0)、(x,0)点一以及从原点出发的方向向量(a,b)构成的直角三角形包围的点的权值和。
点的权值是(x+A)(y+B),其中A,B是给定的常数
做法也很显然,将查询离线下来按照方向向量排序,之后的操作就相当于用一根端点在原点的线从x轴开始往y轴扫,不断地把扫到的点的权值加入到树状数组中。每次扫到某个查询的方向向量时,用这个三角形的底边求前缀和,记录下来就好了。
权值会爆int,注意下就好了
#include<map>#include<string>#include<cstring>#include<cstdio>#include<cstdlib>#include<cmath>#include<queue>#include<vector>#include<iostream>#include<algorithm>#include<bitset>#include<climits>#include<list>#include<iomanip>#include<stack>#include<set>using namespace std;typedef long long ll;ll bit[1010];void update(int pos,ll val){for(int i=pos;i<=1000;i+=i&-i)bit[i]+=val;}ll psum(int pos){ll ans=0;for(int i=pos;i>0;i-=i&-i)ans+=bit[i];return ans;}struct Point{int x,y;bool operator <(Point one)const{return y*one.x<=one.y*x;}}point[1000010];struct Qu{int x,y,len,no;bool operator <(Qu one)const{return ll(y*one.x)<ll(one.y*x);}}qu[1000010];ll ans[1000010];int main(){int n=0;for(int i=1;i<=1000;i++)for(int j=1;j<=1000;j++){point[n].x=i;point[n++].y=j;}sort(point,point+n);int T;scanf("%d",&T);for(int cs=1;cs<=T;cs++){int a,b,m;scanf("%d%d%d",&a,&b,&m);for(int i=0;i<m;i++){scanf("%d%d%d",&qu[i].x,&qu[i].y,&qu[i].len);qu[i].no=i;}sort(qu,qu+m);memset(bit,0,sizeof(bit));for(int i=0,j=0;i<m;i++){Point t;t.x=qu[i].x;t.y=qu[i].y;while(j<n&&point[j]<t){update(point[j].x,ll(point[j].x+a)*(point[j].y+b));j++;}ans[qu[i].no]=psum(qu[i].len);}printf("Case #%d:\n",cs);for(int i=0;i<m;i++)cout<<ans[i]<<endl;}}
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 518 Accepted Submission(s): 157
Problem Description
Matt has a company, Always Cook Mushroom (ACM), which produces high-quality mushrooms.
ACM has a large field to grow their mushrooms. The field can be considered as a 1000 * 1000 grid where mushrooms are grown in grid points numbered from (1, 1) to (1000, 1000). Because of humidity and sunshine, the productions in different grid points are not the same. Further, the production in the grid points (x, y) is (x + A)(y + B) where A, B are two constant.
Matt,the owner of ACM has some queries where he wants to know the sum of the productions in a given scope(include the mushroom growing on the boundary). In each query, the scope Matt asks is a right angled triangle whose apexes are (0, 0), (p, 0), (p, q) 1<=p, q<=1000.
As the employee of ACM, can you answer Matt’s queries?
ACM has a large field to grow their mushrooms. The field can be considered as a 1000 * 1000 grid where mushrooms are grown in grid points numbered from (1, 1) to (1000, 1000). Because of humidity and sunshine, the productions in different grid points are not the same. Further, the production in the grid points (x, y) is (x + A)(y + B) where A, B are two constant.
Matt,the owner of ACM has some queries where he wants to know the sum of the productions in a given scope(include the mushroom growing on the boundary). In each query, the scope Matt asks is a right angled triangle whose apexes are (0, 0), (p, 0), (p, q) 1<=p, q<=1000.
As the employee of ACM, can you answer Matt’s queries?
Input
The first line contains one integer T, indicating the number of test cases.
For each test case, the first line contains two integers:A, B(0<=A, B<=1000).
The second line contains one integer M(1<=M<=10^5), denoting the number of queries.
In the following M lines, the i-th line contains three integers a, b, x (1<=a, b<=10^6, 1<=x<=1000), denoting one apex of the given right angled triangle is (x, 0) and the slope of its base is (a, b). It is guaranteed that the gird points in the given right angled triangle are all in valid area, numbered from (1, 1) to (1000, 1000).
For each test case, the first line contains two integers:A, B(0<=A, B<=1000).
The second line contains one integer M(1<=M<=10^5), denoting the number of queries.
In the following M lines, the i-th line contains three integers a, b, x (1<=a, b<=10^6, 1<=x<=1000), denoting one apex of the given right angled triangle is (x, 0) and the slope of its base is (a, b). It is guaranteed that the gird points in the given right angled triangle are all in valid area, numbered from (1, 1) to (1000, 1000).
Output
For each test case, output M + 1 lines.
The first line contains "Case #x:", where x is the case number (starting from 1)
In the following M lines, the i-th line contains one integer, denoting the answer of the i-th query.
The first line contains "Case #x:", where x is the case number (starting from 1)
In the following M lines, the i-th line contains one integer, denoting the answer of the i-th query.
Sample Input
20 033 5 82 4 71 2 31 233 5 82 4 71 2 3
Sample Output
Case #1:1842170886Case #2:29012688200
Source
2014 ACM/ICPC Asia Regional Beijing Online
Recommend
hujie | We have carefully selected several similar problems for you: 5287 5286 5285 5284 5283
0 0
- hdu5032 Always Cook Mushroom
- HDU 5032 Always Cook Mushroom
- 【树状数组】 HDOJ 5032 Always Cook Mushroom
- Hdu 5032 Always Cook Mushroom (树状数组)
- HDU Always Cook Mushroom (极角排序+树状数组)
- hdu 5032 Always Cook Mushroom 离线树状数组
- [HDU 5032 Always Cook Mushroom] 离线+极角排序+树状数组
- [hdu 5032]2014北京网络赛Always Cook Mushroom 离线线段树/树状数组
- HDU 5032 Always Cook Mushroom 极角排序 数状数组 姿势
- HDU 5032 Always Cook Mushroom(极角排序, 树状数组)
- HDU 5032 Always Cook Mushroom (2014年北京赛区现场赛A题)
- HDU 5032 Always Cook Mushroom (极角排序 x 树状数组)
- [hdu 5032]2014北京网络赛Always Cook Mushroom 离线线段树/树状数组
- HDU5032--Grade
- always @ (*)
- Mushroom Scientists
- Mushroom Introduction
- vim cook
- 嵌入式Linux module之符号导出
- Android开发——常用功能源码
- 使用MediaPlayer和SurfaceView播放视频
- Android之——AsyncTask和Handler对比
- BestCoder#48 1001 && 1002
- hdu5032 Always Cook Mushroom
- ubuntu下安装vim注意事项
- SQL UPDATE
- php5.4.43开发环境的搭建(php5.4.43,apache2.2,mysql5.6以及phpMyAdmin)
- System.Data.SQLite数据库介绍
- MFC学习笔记--组合框Combo Box一些操作
- Hadoop--Hadoop2.X编译安装和实验------练习3
- 天声人語 20150719
- 开启学习记录好习惯_篇章(一)