【ACMclub周赛5】Problem A——购物停车

来源:点击打开链接

水题一道,由推断可知,如果停车点在首尾两个点的外边,那么会至少行进2*(Pi-P0)+K(i为最右面的商铺,K不定反正大于0),而设在内部,只需要行进最多2*(Pi-P0)的距离,而一个来回是一定要走的,关键是第二个来回怎么尽可能的省出来,数据不大,暴搜就行了。

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;

int store[22];

int main()
{
	int testcase;
	cin>>testcase;
	while(testcase--)
	{
		memset(store,0,sizeof(store));
		int numofstore;
		cin>>numofstore;
		for(int i=0;i<numofstore;i++)
		{
			cin>>store[i];
		}
		int minn=0x3f3f3f3f,lf=0,rt=0,tmp=0;
		sort(store,store+numofstore);
		for(int p=store[0];p<=store[numofstore-1];p++)
		{
			tmp=store[numofstore-1]-store[0];
			lf=p-store[0];
			rt=store[numofstore-1]-p;
			tmp=tmp+lf+rt;
			if(tmp<minn)
				minn=tmp;
		}
		cout<<tmp<<endl;
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值