HDU 5032 Always Cook Mushroom

67 篇文章 0 订阅

题意:

一块田地坐标从(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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值