cf583C. GCD Table
来源:互联网 发布:淘宝所有宝贝链接地址 编辑:程序博客网 时间:2024/05/16 08:20
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<algorithm>#include<cmath>#include<queue>#include<list>#include<vector>#include<map>using namespace std;const int maxn=250010;int ans[510];int num[maxn];map<int,int >vis;int gcd(int a,int b){return b==0?a:gcd(b,a%b);}bool cmp(int a,int b){return a>b;}int main(){int t,i,j,k,n,m,cnt=0;scanf("%d",&n);vis.clear();for(i=0;i<n*n;++i){scanf("%d",&num[i]);vis[num[i]]++;}if(n==1){printf("%d\n",num[0]);return 0;}sort(num,num+n*n,cmp);vis[gcd(num[0],num[1])]-=2;ans[cnt++]=num[0];ans[cnt++]=num[1];vis[num[0]]--;vis[num[1]]--;for(i=2;i<n*n;++i){if(vis[num[i]]!=0){for(j=0;j<cnt;++j){vis[gcd(ans[j],num[i])]-=2;}ans[cnt++]=num[i];vis[num[i]]--;}}for(i=0;i<cnt;++i){if(i)printf(" %d",ans[i]);else printf("%d",ans[i]);}printf("\n");return 0;}
0 0
- cf583C. GCD Table
- CF582A GCD Table
- 【CF583C】【Password】【数论】
- Codeforces 583C GCD Table 【gcd + 构造】
- cf 582A GCD Table
- Codeforces 583c GCD Table
- codeforce 582-A GCD Table
- Codeforces 582A GCD Table
- codeforces 582A GCD Table
- codeforces 583C GCD Table
- 贪心+map Codeforces583C GCD Table
- codeforce 582 A. GCD Table
- Codeforces 582A:GCD Table
- codeforces 338D GCD Table
- codeforces 338D GCD Table
- codeforces 582A GCD Table
- CF#323-DIV2-C - GCD Table - 贪心GCD
- CF 338 D GCD Table(CRT)
- List去重复元素
- 持续化集成: Jenkins + 蒲公英
- Linearlayout
- makefile 模板
- C++实现插入排序
- cf583C. GCD Table
- MySQL主从复制数据库升级完成后检查项
- 如何在页面中添加打印功能
- Android使用Handler防止内存泄漏
- 6-2 Verilog Mealy状态机之自动售货机
- poj 1037 A decorative fence dp+序列构造
- myeclipse连接Access数据库
- 颜色转换
- AndroidStudio常用设置