hdu5032 Always Cook Mushroom
题意是这样,给定一个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
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?
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).
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.
2
0 0
3
3 5 8
2 4 7
1 2 3
1 2
3
3 5 8
2 4 7
1 2 3
Case #1:
1842
1708
86
Case #2:
2901
2688
200
pid=5284" style="color:rgb(26,92,200); text-decoration:none">5284
5283hdu5032 Always Cook Mushroom的更多相关文章
- HDU5032 -- Always Cook Mushroom 树状数组 14年北京网络赛
题意:1000*1000的格子, 坐标为(1, 1) ~ (1000, 1000), 常数 A, B, 点(x, y)权值为 (x + A) * (y + B), q次询问, 每次询问(0, 0) ...
- HDU5032 Always Cook Mushroom(树状数组&&离线)
树状数组+询问离线.一个优化是需要的,就是先对1000*1000个点先排序,而不是每次都生成这1000*1000个点然后和询问一起排序,那样会tle. #include <iostream> ...
- HDU Always Cook Mushroom (极角排序+树状数组)
Problem Description Matt has a company, Always Cook Mushroom (ACM), which produces high-quality mush ...
- The 2014 ACMICPC Asia Regional Beijing Online
[A]极角排序+树状数组 [B]计算几何,凸包(队友已出) [C]-_-///不懂 [D]数论,概率密度 [E]图的连通性+Floyed传递闭包+bitset [F]贪心 [G]签到题 [H]区间维护 ...
- HDU 5038 Grade(分级)
Description 题目描述 Ted is a employee of Always Cook Mushroom (ACM). His boss Matt gives him a pack of ...
- hdu---(5038)Grade(胡搞)
Grade Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Sub ...
- 2014 ACM/ICPC Asia Regional 北京 Online
G - Grade Ted is a employee of Always Cook Mushroom (ACM). His boss Matt gives him a pack of mushroo ...
- hdu 4946 Area of Mushroom(凸包)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4946 Area of Mushroom Time Limit: 2000/1000 MS (Java/Ot ...
- Contest 20140914 Mushroom写情书 字符串雙hash 後綴數組
0111:Mushroom写情书 查看 提交 统计 提问 总时间限制: 10000ms 内存限制: 256000kB 描述 有一天,Mushroom准备向他的GF表白,为了增加表白成功率,Mush ...
随机推荐
- c#隐式转换之有符号位转换
有符号位类型的转换,额外的高位用源表达式的符号位填充.这样就维持了被转换的值的正确符号和大小. 特别注意的是负数的转换,额外的高位用1填充,因为负数的二进制表示是对应正数的二进制取反加1,所以高位用1 ...
- ASP.NET菜鸟之路之Seesion小例子
背景 我是一个ASP.NET菜鸟,暂时开始学习ASP.NET,在此记录下我个人敲的代码,没有多少参考价值,请看到的盆友们为我点个赞支持我一下,多谢了. Session介绍 Session保存特定用户相 ...
- html5 的百度地图连接
在一些网站上,我们经常会看到一些地址会有一个图标的形式展现,当你点击的时候就会加载一个你点击区域的地图出来,很神奇的一个功能,在之前是没有这样功能的,都是直接写上地址,你要去的话自己找去吧,现在有了这 ...
- sqlite3 小结
sqlite安装 DDL(数据定义语言):create.alter.drop DML(数据操作语言):insert.update.delete DQL(数据查询语言):select sqlite3 命 ...
- openstack VM可以ping外部网络,但是外部网络ping不通VM
经过无数次的尝试,终于搭建好了完整的Openstack,本来VM可以获取到IP地址,但是等到我大功告成的时候,突然发现外部网络却不能ping进VM,我可是整整折腾了我几个通宵,这是哭啊.然而,皇天不负 ...
- select 1 from table where的作用?
"SELECT 1 FROM identity_approve WHERE identity_num=' " . trim($_POST['IDnumber']) . " ...
- JS indexOf() lastIndexOf()与substring()截取字符串的区别
1. String.IndexOf 方法 (value[,startIndex]) value:要查找的 Unicode 字符. 必选项startIndex:搜索起始位置. 可选项 不写从开头查找 ...
- 浅谈intval()函数用法
<? } } 总结:intval()函数功能1.参数一定是数字否则会报错,2.如果是数字那一定是整数,如果有小点,那会省略掉,3,强调参数可以有“-”值.4.参数第一位不应为0开头,不然会自动转 ...
- python学习第十七天 --定制类
何为定制类? Python的class允许定义许多特殊方法,可以让我们非常方便地生成特定的类.在类中应用或者重写python的特殊方法,得到的类,就是定制类. 大家都知道print的用法.见下面例子 ...
- jQuery .Ajax Error Handling Function
$(function() { $.ajaxSetup({ error: function(jqXHR, exception) { if (jqXHR.status === 0) { alert('No ...