Codeforces Round #323 (Div. 2) C. GCD Table map
题目链接:http://codeforces.com/contest/583/problem/C
2 seconds
256 megabytes
standard input
standard output
The GCD table G of size n × n for an array of positive integers a of length n is defined by formula
Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both xand y, it is denoted as . For example, for array a = {4, 3, 6, 2} of length 4 the GCD table will look as follows:
Given all the numbers of the GCD table G, restore array a.
The first line contains number n (1 ≤ n ≤ 500) — the length of array a. The second line contains n2 space-separated numbers — the elements of the GCD table of G for array a.
All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array a.
In the single line print n positive integers — the elements of array a. If there are multiple possible solutions, you are allowed to print any of them.
4
2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2
4 3 6 2
1
42
42
2
1 1 1 1
1 1
题意:你有n个数,给你n个数相互的gcd,即 gcd(a[i],a[j]) 1<=i<=n ,1<=j<=n;
让你求原来n个数 a[i],随意输出;
思路:首先,发现对称,好像没有什么用;
显然gcd只可能变小对吧,所以我们取最大的那个是必然存在的,放入a组数中,然后继续找下一个;
记得删掉取得数,和取数之间的gcd即可;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define mk make_pair
#define eps 1e-7
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e4+,M=4e6+,inf=;
const ll INF=1e18+,mod=; /// 数组大小
map<int,int>mp;
map<int,int>::iterator it;
vector<int>ans;
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n*n;i++)
{
int x;
scanf("%d",&x);
mp[x]++;
}
for(int i=;i<=n;i++)
{
it=--mp.end();
int z=it->first;
for(int j=;j<ans.size();j++)
{
int g=__gcd(z,ans[j]);
mp[g]--;
mp[g]--;
if(!mp[g])mp.erase(mp.find(g));
}
ans.push_back(z);
mp[z]--;
if(!mp[z])mp.erase(mp.find(z));
}
for(int i=;i<n;i++)
cout<<ans[i]<<" ";
return ;
}
Codeforces Round #323 (Div. 2) C. GCD Table map的更多相关文章
- Codeforces Round #323 (Div. 2) C. GCD Table 暴力
C. GCD Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/583/problem/C ...
- Codeforces Round #323 (Div. 2) C.GCD Table
C. GCD Table The GCD table G of size n × n for an array of positive integers a of length n is define ...
- Codeforces Round #323 (Div. 1) A. GCD Table
A. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #323 (Div. 2) C GCD Table 582A (贪心)
对角线上的元素就是a[i],而且在所在行和列中最大, 首先可以确定的是最大的元素一定是a[i]之一,这让人想到到了排序. 经过排序后,每次选最大的数字,如果不是之前更大数字的gcd,那么只能是a[i] ...
- Codeforces Round #323 (Div. 2) C 无敌gcd 数学/贪心
C. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #323 (Div. 2)
被进爷坑了,第二天的比赛改到了12点 水 A - Asphalting Roads /************************************************ * Author ...
- Codeforces Round #140 (Div. 1) D. The table 构造
D. The table 题目连接: http://www.codeforces.com/contest/226/problem/D Description Harry Potter has a di ...
- Codeforces Codeforces Round #319 (Div. 2) A. Multiplication Table 水题
A. Multiplication Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/57 ...
- Codeforces Round #256 (Div. 2) D. Multiplication Table(二进制搜索)
转载请注明出处:viewmode=contents" target="_blank">http://blog.csdn.net/u012860063?viewmod ...
随机推荐
- Cobbler 自动化部署系统
yum安装 yum install -y epel-release yum install -y httpd dhcp tftp cobbler cobbler-web pykickstart xin ...
- [LeetCode] 476. Number Complement_Easy tag: Bit Manipulation
这个题目思路就是比如101 的结果是010, 可以从111^101 来得到, 那么我们就需要知道刚好比101多一位的1000, 所以利用 while i <= num : i <<= ...
- dialog提交表单
<div id="dialog" title="添加客户"> <!--表单提交--> <form id="dialogF ...
- Vue.Js添加自定义插件
基于上篇我们讲了 在window下搭建Vue.Js开发环境 我们可以开发自己的vue.js插件发布到npm上,供大家下载使用. 1.首先打开cmd命令窗口,进入我们的工作目录下 执行 cd E:\vu ...
- js中数组的字符串表示
<html> <head> <title>数组的字符串表示</title> <script type="text/javascript& ...
- CAS机制
##################################################################### 我们知道多线程操作共享资源时,会出现三个问题:可见性.有序性 ...
- POST—常见的4种提交方式
HTTP/1.1 协议规定的 HTTP 请求方法有 OPTIONS.GET.HEAD.POST.PUT.DELETE.TRACE.CONNECT 这几种.其中,POST 一般用来向服务端提交数据,本文 ...
- VS2010/MFC编程入门之四十八(字体和文本输出:文本输出)
鸡啄米在上一节中讲了CFont字体类,本节主要讲解文本输出的方法和实例. 文本输出过程 在文本输出到设备以前,我们需要确定字体.字体颜色和输出的文本内容等信息.Windows窗口的客户区由应用程序管理 ...
- MySQL Crash Course #18# Chapter 26. Managing Transaction Processing
InnoDB 支持 transaction ,MyISAM 不支持. 索引: Changing the Default Commit Behavior SAVEPOINT 与 ROLLBACK TO ...
- 什么叫集群、分布式,分布式与集群有什么区别?(康神sf讲座学习笔记)
集群是物理形态,分布式是工作方式. 只要一堆机器放在那里,就是集群.比如Nginx后面的十台服务器,就是一个集群 分布式将任务放在多个物理隔离的节点上进行. 分布式中各个子节点互不通信,统一受管控中心 ...