JZOJ5885. 【NOIP2018模拟9.27】物理实验

JZOJ5885. 【NOIP2018模拟9.27】物理实验_第1张图片
JZOJ5885. 【NOIP2018模拟9.27】物理实验_第2张图片

题解

这题,只要猜对结论,就可以了。
因为有三个变量,
不好找他们之间的关系,就先固定一个。
在固定 a z a_z az的情况下,
很容易发现对于每个 a x a_x ax只有最靠近它的 a y a_y ay才最优。
也就是说y=x+1,考虑固定下x,即也固定下来了y,什么时候z最优,
可以证明,在z依次变化中,这个利用率是单调的,可能递增也可能递减。
只有找到紧紧挨着的那一个,还有最远的那一个来判断一下就可以了。

code

#include 
#include 
#include 
#include 
#include 
#include 
#define N 100003
#define ldb long double
#define G getchar
using namespace std;
char ch;
void read(int &n)
{
	n=0;
	ch=G();
	while((ch<'0' || ch>'9') && ch!='-')ch=G();
	int w=1;
	if(ch=='-')w=-1,ch=G();
	while('0'<=ch && ch<='9')n=(n<<3)+(n<<1)+ch-'0',ch=G();
	n*=w;
}

int n,m,a[N],T,id;
ldb ans;

int main()
{
	freopen("atom.in","r",stdin);
	freopen("atom.out","w",stdout);
	
	for(read(T);T;T--)
	{
		read(n);read(m);ans=-1;
		for(int i=1;i<=n;i++)read(a[i]);
		sort(a+1,a+1+n);id=1;
		for(int i=1;i

你可能感兴趣的:(题解)