10.21的毫无营养混更

因为今天月赛读入优化爆0.我很烦闷,就找了道水题(题目都没什么深意的那种),普及-。
随便写了个居然也过了。唉,数据太水了!
https://www.luogu.org/problem/show?pid=1732
这个题真的,看起来就特别水。
我认真思索了一下各种数据结构,又想用stl,但是由于我太懒太菜,都没有付诸实现。

0<= ai<=65 536

大家看到了吗,这个数据小得可怜。
用一个bool表记录下哪些数字已经出现过。
每有1个a[i]待转化成b[i],都在表中寻找距离它最近的、已经出现过的数。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
bool biao[65537];
long long a[100001],b[100001];
inline void inl(long long &p,char c=getchar())//long long读入优化
{
	while(c<'0' or c>'9')
		c=getchar();
	p=0;
	while(c>='0' and c<='9')
		p=p*10+c-'0',c=getchar();
}
inline void in(long long &p,char c=getchar())//int读入优化
{
	while(c<'0' or c>'9')
		c=getchar();
	p=0;
	while(c>='0' and c<='9')
		p=p*10+c-'0',c=getchar();
}
int main()
{
	int t;
	in(t);
	while(t--)
	{
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		memset(biao,0,sizeof(biao));
		int n;
		in(n);
		inl(a[1]);
		b[1]=a[1];
		biao[a[1]]=1;
		for(int i=2;i<=n;i++)
		{
			inl(a[i]);
			for(int l=a[i],r=a[i]+1;;)//l,r中要有一个从a[i]开始找(说不定a[i]不是第一次出现了)
			{
				if(biao[l])
				{
					b[i]=a[i]-l;
					break;
				}
				if(biao[r])
				{
					b[i]=r-a[i];
					break;
				}
				if(l>0)//防止访问非法内存
					l--;
				if(r<65536)
					r++;
			}
			biao[a[i]]=1;
		}
		for(int i=2;i<=n;i++)
			b[i]+=b[i-1];
		printf("%lld\n",b[n]);
	}
	return 0;
}

这真的很水,很适合放松身心(
啊我的博客都是好弱的内容啊,像我一样
↑其实这个没必要加删除线的

posted @ 2017-10-21 22:47  syhien  阅读(172)  评论(2编辑  收藏  举报