HDU 5032 Always Cook Mushroom

题意:

一块田地坐标从(1,1)到(1000,1000)  每块田地能种(x+A)*(y+B)的蘑菇  问  形似(0,0)(p,0)(p,q)这样的三角形区域能种的蘑菇的数量

思路:

其实很简单  枚举x  根据输入的向量  我们可以求出每个x对应最高的y  然后对于y可以用等差数列求和  再加上y个B  最后乘(x+A)就好了  但是这题时间卡得挺恶心的…

一开始写完T了  输入开挂还T  看了别人的代码发现y那个部分可以提出来打表做(就是代码中的f数组)  本以为稳A了  还是T…  仔细考虑后发现有些变量没必要定义成long long  改完才A…  没什么思维含量  要细心!!

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<cassert>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;
typedef long long LL;
#define N 1010

int T, t, a, b, m, dx, dy, x;
LL ans;
int f[N];

inline void scand(int &ret) {
	char c;
	ret = 0;
	while ((c = getchar()) < '0' || c > '9')
		;
	while (c >= '0' && c <= '9')
		ret = (ret << 3) + (ret << 1) + (c - '0'), c = getchar();
}

int main() {
	int i, Y;
	scand(T);
	for (t = 1; t <= T; t++) {
		printf("Case #%d:\n", t);
		scand(a);
		scand(b);
		scand(m);
		for (i = 1; i <= 1000; i++)
			f[i] = (i + 1) * i / 2 + i * b;
		while (m--) {
			scand(dx);
			scand(dy);
			scand(x);
			ans = 0;
			for (i = 1; i <= x; i++) {
				Y = i * dy / dx;
				ans += (LL) f[Y] * (a + i);
			}
			printf("%I64d\n", ans);
		}
	}
	return 0;
}
时间: 2024-07-31 23:15:17

HDU 5032 Always Cook Mushroom的相关文章

Hdu 5032 Always Cook Mushroom (树状数组)

题目大意: 在一个1000*1000的二维平面上,每一个整点都有一个权值,权值大小是 the production in the grid points (x, y) is (x + A)(y + B) where A, B are two constant. 思路分析: 先离线处理出所有的询问,对于每一个询问都有一个极角,按照极角排序. 然后对于平面上每一个点,都依次的加入到BIT中,当当前的这个询问的极角比这个点到原点的对应极角要大的时候,就将这个点加进去. 可以理解成有一根线,按照逆时针的

[hdu 5032]2014北京网络赛Always Cook Mushroom 离散化+离线线段树/树状数组

Always Cook Mushroom Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 196    Accepted Submission(s): 54 Problem Description Matt has a company, Always Cook Mushroom (ACM), which produces high-q

HDU Always Cook Mushroom (极角排序+树状数组)

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 numbe

HDU 4946 Area of Mushroom(凸包)

如果一个人能统治无穷远处,那么他的速度一定是最大的.除了那几种很坑的数据,比如同一个点速度相同的两个人.永远都是不可能.所以你要处理出来所有速度最大的点,然后用他们构成一个凸包,你把端点的点求出来了,还得判断一下在边上的情况.然后顶点和在边上的点所构成的就是可以到达无穷远处的人. PS:抄了芳姐的模版..哈哈哈 Area of Mushroom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/

HDU 4946 Area of Mushroom 凸包 第八次多校

Problem Description Teacher Mai has a kingdom with the infinite area. He has n students guarding the kingdom. The i-th student stands at the position (xi,yi), and his walking speed is vi. If a point can be reached by a student, and the time this stud

HDU 4946 Area of Mushroom 共线凸包

题意是在二维平面上 给定n个人 每个人的坐标和移动速度v 若对于某个点,只有 x 能最先到达(即没有人能比x先到这个点或者同时到这个点) 则这个点称作被x占有 若有人能占有无穷大的面积 则输出1 ,否则输出0 思路: 1.把所有点按速度排个序,然后把不是最大速度的点去掉 剩下的点才有可能是占有无穷大的面积 2.给速度最大的点做个凸包,则只有在凸包上的点才有可能占有无穷大 若一个位置有多个人,则这几个人都是不能占有无穷大的. 凸包上边里共线的点是要保留的,, 附赠一波数据 #include <cs

【凸包】HDU 4946 Area of Mushroom

注意: 1.重合的点 2.速度为0的点 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> #include <ctype.h> #include <math.h> #include <string> #include <iostream> #include <algorithm> using

hdu5032 Always Cook Mushroom

题意是这样,给定一个1000x1000的点阵,m组询问,每次询问一个由(0,0).(x,0)点一以及从原点出发的方向向量(a,b)构成的直角三角形包围的点的权值和. 点的权值是(x+A)(y+B),其中A,B是给定的常数 做法也很显然,将查询离线下来按照方向向量排序,之后的操作就相当于用一根端点在原点的线从x轴开始往y轴扫,不断地把扫到的点的权值加入到树状数组中.每次扫到某个查询的方向向量时,用这个三角形的底边求前缀和,记录下来就好了. 权值会爆int,注意下就好了 #include<map>

hdu 4946 Area of Mushroom

题意: 在二维平面上,给定n个人 每个人的坐标和移动速度v 若对于某个点,只有 x 能最先到达(即没有人能比x先到这个点或者同时到这个点) 则这个点称作被x占有,若有人能占有无穷大的面积 则输出1 ,否则输出0 思路: 1.把所有点按速度排个序,然后把不是最大速度的点去掉 剩下的点才有可能是占有无穷大的面积 2.给速度最大的点做个凸包,则只有在凸包上的点才有可能占有无穷大 若一个位置有多个人,则这几个人都是不能占有无穷大的. 凸包上边里共线的点是要保留的. #易错点: 1.凸包边上要保留共线的点