Codeforces Round #323 (Div. 2) C GCD Table 582A (贪心)
对角线上的元素就是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 (贪心)的更多相关文章
- 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 map
题目链接:http://codeforces.com/contest/583/problem/C C. GCD Table time limit per test 2 seconds memory l ...
- 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 #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 ...
- 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 ...
随机推荐
- One-Hot独热编码
One-Hot独热编码 Dummy Encoding VS One-Hot Encoding二者都可以对Categorical Variable做处理,定性特征转换为定量特征,转换为定量特征其实就是将 ...
- [Xcode 实际操作]四、常用控件-(6)UISwitch开关控件的使用
目录:[Swift]Xcode实际操作 本文将演示开关控件的基本用法. 开关控件有两个互斥的选项,它是用来打开或关闭选项的控件. 在项目导航区,打开视图控制器的代码文件[ViewController. ...
- CSS(一)清除浮动
问题1:关于清除浮动 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...
- 源码分析String
hashCode 计算每个char值,并移位累加 计算后的hash值会缓存
- 注意ie6的盒模型
浏览器版本多了,也是一个累,特别是ie家族的. 网上搜罗了一大堆,发现说的和我看到的不一样啊,结果才发现原来是对方表述有问题,省略了几个字就产生了歧义了. 按照网上说的ie6对盒模型解释不符合W3C标 ...
- 004 Median of Two Sorted Arrays 两个有序数组的中位数
There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two ...
- deep copy and shallow copy
链接A:浅拷贝就是成员数据之间的一一赋值:把值赋给一一赋给要拷贝的值.但是可能会有这样的情况:对象还包含资源,这里的资源可以值堆资源,或者一个文件..当值拷贝的时候,两个对象就有用共同的资源,同时对资 ...
- Linux利用iptables实现真-全局代理
对于经常要浏览油管等被墙网站的人而言,利用代理来实现fq是非常有必要的.现在fq的方法中,最为主流的应该要数ssr了,因此本教程都是基于ssr的socks5代理而言的. 在windows中,ssr客户 ...
- Python 将IP转换为int
import socket import struct if __name__ == '__main__': ip = '127.0.0.1' int_ip = struct.unpack('!I', ...
- android 开发-(Contextual Menu)上下文菜单的实现
在android3.0以后,安卓设备不在提供物理的菜单按键,同时,android应用提供了另外的菜单实现机制,来替代之前的菜单创建方式.安卓设备中,平常可以使用长按住某个内容弹出菜单选项.这就是我们需 ...