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 ...
随机推荐
- ARC085F(动态规划,线段树)
#include<bits/stdc++.h>using namespace std;const int maxn = 0x3f3f3f3f;int mn[801000];int cost ...
- .txt文件转换到Excel
背景 前几天,自己在实验室里做实验,我们的大偶像肖老师看见我了,把我宣到他的办公室,问我,这个怎么办.都是数字,两列数字,怎么排版到Excel上也显示两列数字.Oh My God! 这个我怎么知 ...
- c# Relative Path convert to Absolute Path
Reference: http://stackoverflow.com/questions/4796254/relative-path-to-absolute-path-in-c http://sta ...
- 记一次工作中的小BUG
今天在调试代码的时候总是遇到一个bug,百思不得其解!先上bug图 我用的webapi 集成的swagger,错误提示是路由名称冲突,可我仔细检查了下并没有冲突的路由地址啊!于是上网查找资料,有位网友 ...
- thinkphp5.1 使用第三方扩展类库
此案例介绍的不是通过composer加载的,是手工下载放入extend目录下的扩展类库,仍然以phpspider为例 将owner888目录放入extend目录下,也可以直接将phpspider目录放 ...
- Jmeter常用线程组设置及场景运行时间计算
Jmeter中通过线程组来模拟大用户并发场景,今天主要介绍三个常用的线程组,帮助我们设计更加完善的测试场景,另外介绍下场景执行时间如何计算. 一.Thread Group 取样器错误后要执行的动作 ...
- 牛客假日团队赛1B.便便传送门(一)
链接:https://ac.nowcoder.com/acm/contest/918/B 题意: Farmer John最讨厌的农活是运输牛粪.为了精简这个过程,他制造了一个伟大的发明:便便传送门!与 ...
- 软件测试的生命周期&测试流程
一.软件的生命周期 二.软件生命周期的阶段 三.软件模型 四.软件测试的基本流程 五.软件开发流程.测试流程梳理 六.C/S与B/S架构 七.对软件测试行业的理解 八.常见笔试面试题 一.软件的生命周 ...
- HashMap遍历时的性能对比
使用KeySet和EntrySet遍历的差别 public static void main(String[] args) { HashMap<Integer, Integer> hasM ...
- SQL Server 查看分区表(partition table)的分区范围(partition range)
https://www.cnblogs.com/chuncn/archive/2009/02/20/1395165.html SQL Server 2005 的分区表(partition table) ...