对角线上的元素就是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. JS中的参数搜寻机制

    1: var color="blue"; function changecolor(color){ if(color=="blue"){ color=" ...

  2. js对象转换为json字符串

    JavaScript的对象是一组由键-值组成的无序集合,例如: var person = { name: 'Bob', age: 20, tags: ['js', 'web', 'mobile'], ...

  3. 51nod1119(除法取模/费马小定理求组合数)

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1119 题意:中文题诶- 思路:这题数据比较大直接暴力肯定是不 ...

  4. Zjoi2011 看电影

    最近在学习一些概率的东西.. 一个随机试验称为 Laplace 试验,当且仅当它满足如下两个条件: (ⅰ) 试验结果 (样本点) 的个数是有限的.(Ω 是有限集) (ⅱ) 任意两个基本事件的概率均相等 ...

  5. web综合案例01

    web综合案例01 ... .... 内容待添加

  6. CentOS编译安装GCC 4.9.2成功

    在Linux上编译安装gcc是个寻烦恼的活,对于像我这样习惯于在Windows上面使用二进制安装包的人来说,自已编译安装gcc是个相当大的挑战,今天直接挑战最新版的gcc,是4.9.2版本的,做之前查 ...

  7. UDP可靠传输简易设计

    UDP,鉴于其丢包和乱序(后发先至)问题,为保证其可靠性设计如下报头协议,供大家参考 数据包设计 数据包总大小按照MTU设计设置,小于1500字节 数据包示意图 包头类型说明 1.类型(1字节) 数值 ...

  8. Luogu P3265 [JLOI2015]装备购买

    好吧刚开始不知道自己在写什么,,,后来写了线性方程组,又过了一天一上午终于明白了... 当然题意很显然:求代价最小的极大线性无关组. 那就高斯消元(好吧刚开始我不会用它来解这道题qwq) 第一个循环是 ...

  9. codeforces1016 D. Vasya And The Matrix(思维+神奇构造)

    D. Vasya And The Matrix time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  10. java 单例模式之线程安全的饿汉模式和懒汉模式

    转载博主:thankyou https://blog.csdn.net/twj13162380953/article/details/53869983 理解: 饿汉式获取实例的步骤简单所以线程更安全. ...