【NOIP 模擬題】[T1]return(模擬)
阿新 • • 發佈:2019-02-12
【題解】【模擬】
【將序列讀入、排序、去重,列舉查詢原序列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; }
[謹以此題膜拜學長的文風及語言功底……]