对角线上的元素就是a[i],而且在所在行和列中最大,

首先可以确定的是最大的元素一定是a[i]之一,这让人想到到了排序。

经过排序后,每次选最大的数字,如果不是之前更大数字的gcd,那么只能是a[i]之一。

div2路漫漫。。。

#include<bits/stdc++.h>
using namespace std; typedef int ll; ll a[];
int g[*];
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
map<int,int> mp; //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
int n; scanf("%d",&n);
int sz = n*n;
for(int i = ; i < sz; i++){
scanf("%d",g+i);
}
sort(g,g+sz,greater<int>()); int c = ,j = ;
a[c++] = g[j++];
for(int i = ; i < n; i++){
while(j<sz && mp[g[j]]){
mp[g[j]]--;
j++;
}
if(j == sz) break;
for(int k = c-; k >= ; k--){
mp[gcd(a[k],g[j])] += ;
}
a[c++] = g[j++];
}
while(c--){
printf("%d",a[c]);
if(c) putchar(' ');
}
return ;
}

Codeforces Round #323 (Div. 2) C GCD Table 582A (贪心)的更多相关文章

  1. 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 ...

  2. Codeforces Round #323 (Div. 2) C. GCD Table map

    题目链接:http://codeforces.com/contest/583/problem/C C. GCD Table time limit per test 2 seconds memory l ...

  3. 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 ...

  4. 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 ...

  5. Codeforces Round #297 (Div. 2)C. Ilya and Sticks 贪心

    Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  6. 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 ...

  7. Codeforces Round #323 (Div. 2)

    被进爷坑了,第二天的比赛改到了12点 水 A - Asphalting Roads /************************************************ * Author ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 【leetcode 106. 从中序与后序遍历序列构造二叉树】解题报告

    前往 中序,后序遍历构造二叉树, 中序,前序遍历构造二叉树 TreeNode* build(vector<int>& inorder, int l1, int r1, vector ...

  2. SAS笔记(7) PROC SQL

    参考资料:<Longitudinal Data and SAS: A Programmer's Guide>

  3. 洛谷P1342 请柬

    P1342 请柬 题目描述 在电视时代,没有多少人观看戏剧表演.Malidinesia古董喜剧演员意识到这一事实,他们想宣传剧院,尤其是古色古香的喜剧片.他们已经打印请帖和所有必要的信息和计划.许多学 ...

  4. dorado 常用

    如果要设置模糊查询, 一般要在QueryCommand中这样写: var name = dsQuery.getValue("NAME"); var parameters = com ...

  5. 关于json_encode和json_decode

    json_encode将数组或者对象编码成字符串json_deode将字符串解码称对象或者数组,第二个参数为true时解码成字符串,否则解码成对象

  6. js 设置 cookie

    function setCookie(name,value){ var Days = 30; var exp = new Date(); exp.setTime(exp.getTime() + Day ...

  7. js 中的 for 循环。。。

    for (var i in data){ data[i] } 和for (var i=0;i< data.length; i++){ data[i] } 第一种可能会有bug...

  8. 牛客假日团队赛1 J.分组

    链接: https://ac.nowcoder.com/acm/contest/918/J 题意: 在Farmer John最喜欢的节日里,他想要给他的朋友们赠送一些礼物.由于他并不擅长包装礼物,他想 ...

  9. ResourceBundle 读取properties文件中文乱码

    1.确认properties文件是什么编码格式,并确认文件在该格式下中文是正常显示的2.读取时候,进行转一层,先用ISO-8859-1读取字节流,然后根据properties的文件格式进行new St ...

  10. Scrapy(爬虫应用框架)安装配置

    运行平台:Windows Python版本:Python3.x 一.Scarpy 简介 Scrapy是一个为了爬取网站数据提取结构性数据而编写的应用框架,可以应用于数据挖掘,信息处理或存储历史数据等一 ...