向前走莫回头❤

【NOIP 模拟题】[T1]return(模拟)


【题解】【模拟】

【将序列读入、排序、去重,枚举查找原序列dream中的每一元素在已处理好的序列tm中的位置,并判断tm中的前一个元素加当前元素mod大质数后是否等于tm中的后一个元素(tm是一个环)】

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=2147483647;
long long n,dream[10010],tm[10010],ans;
int tmp(long long a,long long b)
{
	return a<b;
}
int main()
{
	freopen("return.in","r",stdin);
	freopen("return.out","w",stdout);
	int l=0;
	while(scanf("%d",&n)==1)
	 {
	 	l++; ans=0;
	 	for(int i=1;i<=n;++i) 
		 scanf("%d",&dream[i]),tm[i]=dream[i];
	 	sort(tm+1,tm+n+1,tmp);
 	 	int tot=unique(tm+1,tm+n+1)-tm; tot--; 
	 	if(tot==1) {printf("Case #%d: %d\n",l,-1); continue; }
		tm[0]=tm[tot]; tm[tot+1]=tm[1];
	 	for(int i=1;i<=n;++i)
	 	 {
	 	 	int x=lower_bound(tm+1,tm+tot,dream[i])-tm;
	 	 	if((tm[x-1]+dream[i])%mod==tm[x+1]) ans++;
		  }
		printf("Case #%d: %d\n",l,ans);
	 }
	return 0;
}

[谨以此题膜拜学长的文风及语言功底……]
posted @ 2016-10-05 17:47  lris0-0  阅读(94)  评论(0编辑  收藏  举报
过去的终会化为美满的财富~o( =∩ω∩= )m