标签:time cli memset back 分析 and break which str
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
#include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <algorithm> #include <climits> #include <cstring> #include <string> #include <set> #include <map> #include <unordered_map> #include <queue> #include <stack> #include <vector> #include <list> #define rep(i,m,n) for(i=m;i<=n;i++) #define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++) #define mod 1000000007 #define inf 0x3f3f3f3f #define vi vector<int> #define pb push_back #define mp make_pair #define fi first #define se second #define ll long long #define pi acos(-1.0) #define pii pair<int,int> #define Lson L, mid, ls[rt] #define Rson mid+1, R, rs[rt] #define sys system("pause") #define intxt freopen("in.txt","r",stdin) const int maxn=1e3+10; using namespace std; int gcd(int p,int q){return q==0?p:gcd(q,p%q);} ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;} inline ll read() { ll x=0;int f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x*f; } int n,m,k,t,a[maxn],ok[maxn]; queue<pii>p; int main() { int i,j; scanf("%d",&t); while(t--) { memset(ok,0,sizeof(ok)); while(!p.empty())p.pop(); scanf("%d",&n); rep(i,1,n)scanf("%d",&a[i]); rep(i,1,n)rep(j,i+1,n) { k=gcd(a[i],a[j]); if(!ok[k])ok[k]=1,p.push(mp(k,2)); } while(!p.empty()) { pii q=p.front(); p.pop(); if(q.se==n-1)break; rep(i,1,n) { k=gcd(q.fi,a[i]); if(!ok[k])ok[k]=1,p.push(mp(k,q.se+1)); } } bool flag=false; rep(i,1,1000) { if(ok[i]) { if(flag)printf(" %d",i); else printf("%d",i),flag=true; } } printf("\n"); } //system("Pause"); return 0; }
标签:time cli memset back 分析 and break which str
原文地址:http://www.cnblogs.com/dyzll/p/6095576.html