标签:iostream 整数 输入 text efi ios display for size
第1行:N,N为正整数的数量(1000 <= N <= 50000)。 第2 - N+1行:N个正整数。(2<= A[i] <= 10^9) (注,真实数据中N >= 1000,输入范例并不符合这个条件,只是一个输入格式的描述)
找出一个长度 >= 200 的等差数列,如果没有,输出No Solution,如果存在多个,输出最长的那个的长度。
10 1 3 5 6 8 9 10 12 13 14
1 #include<iostream> 2 #include<algorithm> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 #include<cstdlib> 7 #include<vector> 8 using namespace std; 9 typedef long long ll; 10 typedef long double ld; 11 typedef pair<int,int> pr; 12 const double pi=acos(-1); 13 #define rep(i,a,n) for(int i=a;i<=n;i++) 14 #define per(i,n,a) for(int i=n;i>=a;i--) 15 #define Rep(i,u) for(int i=head[u];i;i=Next[i]) 16 #define clr(a) memset(a,0,sizeof(a)) 17 #define pb push_back 18 #define mp make_pair 19 #define fi first 20 #define sc second 21 #define pq priority_queue 22 #define pqb priority_queue <int, vector<int>, less<int> > 23 #define pqs priority_queue <int, vector<int>, greater<int> > 24 #define vec vector 25 ld eps=1e-9; 26 ll pp=1000000007; 27 ll mo(ll a,ll pp){if(a>=0 && a<pp)return a;a%=pp;if(a<0)a+=pp;return a;} 28 ll powmod(ll a,ll b,ll pp){ll ans=1;for(;b;b>>=1,a=mo(a*a,pp))if(b&1)ans=mo(ans*a,pp);return ans;} 29 void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); } 30 //void add(int x,int y,int z){ v[++e]=y; next[e]=head[x]; head[x]=e; cost[e]=z; } 31 int dx[5]={0,-1,1,0,0},dy[5]={0,0,0,-1,1}; 32 ll read(){ ll ans=0; char last=‘ ‘,ch=getchar(); 33 while(ch<‘0‘ || ch>‘9‘)last=ch,ch=getchar(); 34 while(ch>=‘0‘ && ch<=‘9‘)ans=ans*10+ch-‘0‘,ch=getchar(); 35 if(last==‘-‘)ans=-ans; return ans; 36 } 37 const unsigned int p=1795876373; 38 const int p_=7; 39 #define hash(i) (((unsigned int)i*p)>>p_) 40 int a[50005],ans=199; 41 bool f[40000000]; 42 void work(int x,int d){ 43 int now=1; 44 while (f[hash((1LL*x+1LL*now*d))]){ 45 now++; 46 } 47 ans=max(now,ans); 48 } 49 int main(){ 50 int n=read(),d,Max=0; 51 for (int i=1;i<=n;i++) a[i]=read(),f[hash(a[i])]=1,Max=max(Max,a[i]); 52 sort(a+1,a+n+1); 53 for (int i=1;i<n;i++) 54 for (int j=i+1;j<=n;j++){ 55 d=a[j]-a[i]; 56 if ((1LL*a[i]+1LL*ans*d)>1LL*Max) break; 57 if (f[hash((1LL*a[i]+1LL*ans*d))]) { 58 work(a[i],d); 59 } 60 } 61 if (ans>=200) printf("%d",ans); 62 else puts("No Solution"); 63 return 0; 64 }
标签:iostream 整数 输入 text efi ios display for size
原文地址:http://www.cnblogs.com/SXia/p/7592029.html