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 ...
随机推荐
- shell之hello world
[root@localhost sh]#vi hello.sh //编辑 .sh 文件 #The first program #!/bin/bash echo 'hello world' [root@ ...
- PHP连接 redis
<?php //连接本地的 Redis 服务 $redis = new Redis(); //连接redis 地址 端口 连接超时时间 连接成功返回true 失败返回false $redis-& ...
- 洛谷P1979 华容道(70分 暴力)
P1979 华容道 题目描述 [问题描述] 小 B 最近迷上了华容道,可是他总是要花很长的时间才能完成一次.于是,他想到用编程来完成华容道:给定一种局面, 华容道是否根本就无法完成,如果能完成, 最少 ...
- 再看thinkphp5分页类使用
之前使用tp5的分页paginate类时只用到了第一个参数,也就是每页显示多少行 今天又仔细看了下手册和paginate类,发现paginate可传入的参数有很多,可以满足更多需求 比如可以指定分页的 ...
- Luogu P4551 最长异或路径 01trie
做一个树上前缀异或和,然后把前缀和插到$01trie$里,然后再对每一个前缀异或和整个查一遍,在树上从高位向低位贪心,按位优先选择不同的,就能贪出最大的答案. #include<cstdio&g ...
- GUI的最终选择 Tkinter(五):Text用法
Text组件 绘制单行文本使用Label组件,多行选使用Listbox,输入框使用Entry,按钮使用Button组件,还有Radiobutton和Checkbutton组件用于提供单选或多选的情况, ...
- (转)linux命令总结之ip命令
linux命令总结之ip命令 原文:https://www.cnblogs.com/ginvip/p/6367803.html linux命令总结之ip命令 Linux的ip命令和ifconfig ...
- 为什么我们使用Nginx而不是Apache?
我们大多数的客户在他们的服务器上使用Apache作为Web服务器,尤其是部署在一个基于PHP系统的前端并且使用mod-PHP.鉴于扩张性和性能方面的原因,我们通常会建议他们改用Nginx和FPM. A ...
- PHP 中获取文件名及路径
1. basename("/mnt/img/image01.jpg")函数:得到文件名;输出结果为:image01.jpg. 使用 basename($uriString) 我们可 ...
- pat1056. Mice and Rice (25)
1056. Mice and Rice (25) 时间限制 30 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Mice and ...