[USACO1.3]滑雪课程设计Ski Course Design 枚举

2 篇文章 0 订阅

题目

Farmer John has N hills on his farm (1 <= N <= 1,000), each with an integer elevation in the range 0 … 100. In the winter, since there is abundant snow on these hills, FJ routinely operates a ski training camp.

Unfortunately, FJ has just found out about a new tax that will be assessed next year on farms used as ski training camps. Upon careful reading of the law, however, he discovers that the official definition of a ski camp requires the difference between the highest and lowest hill on his property to be strictly larger than 17. Therefore, if he shortens his tallest hills and adds mass to increase the height of his shorter hills, FJ can avoid paying the tax as long as the new difference between the highest and lowest hill is at most 17.

If it costs x^2 units of money to change the height of a hill by x units, what is the minimum amount of money FJ will need to pay? FJ can change the height of a hill only once, so the total cost for each hill is the square of the difference between its original and final height. FJ is only willing to change the height of each hill by an integer amount.

农民约翰的农场里有N座山峰(1<=N<=1000),每座山都有一个在0到100之间的整数的海拔高度。在冬天,因为山上有丰富的积雪,约翰经常开办滑雪训练营。

不幸的是,约翰刚刚得知税法在滑雪训练营方面有新变化,明年开始实施。在仔细阅读法律后,他发现如果滑雪训练营的最高和最低的山峰海拔高度差大于17就要收税。因此,如果他改变山峰的高度(使最高与最低的山峰海拔高度差不超过17),约翰可以避免支付税收。

如果改变一座山x单位的高度成本是x^2单位,约翰最少需要付多少钱?约翰只愿意改变整数单位的高度。

题解

所以只要枚举1-100里要选的山高度区间(长度为17),对每一个区间计算在区间外的山高度改变成本之和并更新答案就可以了?枚举

代码

/*
ID: yjy_aii1
TASK: skidesign
LANG: C++
*/
#include <cstdio>

using namespace std;

int n,ans;
int a[105];

int main(){
	freopen("skidesign.in","r",stdin);
	freopen("skidesign.out","w",stdout);
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		a[x]++;
	}
	ans=1000000000;
	for (int l=0;l<=100-17;l++){
		int r=l+17,k=0;
		for (int i=0;i<l;i++)
			k+=a[i]*(l-i)*(l-i);
		for (int i=r+1;i<=100;i++)
			k+=a[i]*(i-r)*(i-r);
		if (k<ans) ans=k;
	}
	printf("%d\n",ans);
}

子时星熹念长庚

注:
子时:23时至次日凌晨1时
星熹:星光明亮,熹,指明亮
念:思念,想念
长庚:又称启明星、金星,日出前后出现称启明,傍晚在西边的天空出现称长庚

诗句大意:夜半之时,漫天繁星,可不知怎的忽然就想念起了傍晚时分在西方闪烁的长庚星

这个也不是什么奇奇怪怪的东西,比如cp名什么的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值