codeforces 582A. GCD Table 解题报告
题目链接:http://codeforces.com/problemset/problem/582/A
网上很多题解,就不说了,直接贴代码= =
官方题解:
http://codeforces.com/blog/entry/20692
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
using namespace std; const int maxn = + ;
map<int, int> cnt;
vector<int> ans;
int a[maxn*maxn]; int GCD(int a, int b)
{
return b == ? a : GCD(b, a%b);
} int main()
{
int n;
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE while (scanf("%d", &n) != EOF) {
ans.clear();
for (int i = ; i < n*n; i++) {
scanf("%d", &a[i]);
cnt[a[i]]++;
} sort(a, a+n*n);
for (int i = n*n-; i >= ; i--) {
if (cnt[a[i]] <= ) {
continue;
}
cnt[a[i]]--; for (int j = ; j < ans.size(); j++) {
cnt[GCD(ans[j], a[i])] -= ;
}
ans.push_back(a[i]);
}
for (int i = ; i < ans.size(); i++) {
cout << ans[i] << (i == ans.size()- ? '\n' : ' ');
}
}
return ;
}
官方解法代码(个人比较喜欢这个)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
using namespace std; const int maxn = + ; map<int, int> cnt;
int ans[maxn]; int gcd(int a, int b)
{
return b == ? a : gcd(b, a % b);
} int main()
{
int a, n; #ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE while (scanf("%d", &n) != EOF) {
for (int i = ; i < n*n; i++) {
scanf("%d", &a);
cnt[-a]++; // 为了将数组从大到小排序
} int pos = n-;
for (map<int, int>::iterator mp = cnt.begin(); mp != cnt.end(); ++mp) {
int x = -mp->first; while (mp->second) { // 当次数还有的时候
ans[pos] = x;
--mp->second;
for (int i = pos+; i < n; i++) {
cnt[-gcd(ans[i], x)] -= ;
}
pos--;
} }
for (int i = ; i < n; i++) {
printf("%d%c", ans[i], (i == n- ? '\n' : ' '));
}
}
return ;
}
codeforces 582A. GCD Table 解题报告的更多相关文章
- codeforces 582A GCD Table
题意简述: 给定一个长度为$n$的序列 将这个序列里的数两两求$gcd$得到$n^2$个数 将这$n^2$个数打乱顺序给出 求原序列的一种可能的情况 ------------------------- ...
- Codeforces Round 665 赛后解题报告(暂A-D)
Codeforces Round 665 赛后解题报告 A. Distance and Axis 我们设 \(B\) 点 坐标为 \(x(x\leq n)\).由题意我们知道 \[\mid(n-x)- ...
- Codeforces Round 662 赛后解题报告(A-E2)
Codeforces Round 662 赛后解题报告 梦幻开局到1400+的悲惨故事 A. Rainbow Dash, Fluttershy and Chess Coloring 这个题很简单,我们 ...
- Codeforces Round #277.5 解题报告
又熬夜刷了cf,今天比正常多一题.比赛还没完但我知道F过不了了,一个半小时贡献给F还是没过--应该也没人Hack.写写解题报告吧= =. 解题报告例如以下: A题:选择排序直接搞,由于不要求最优交换次 ...
- codeforces A. Table 解题报告
题目链接:http://codeforces.com/problemset/problem/359/A 题目意思:给出一个n行m列的table,你需要选择一个good cell(假设为(x, y), ...
- codeforces 798C.Mike and gcd problem 解题报告
题目意思:给出一个n个数的序列:a1,a2,...,an (n的范围[2,100000],ax的范围[1,1e9] ) 现在需要对序列a进行若干变换,来构造一个beautiful的序列: b1,b2, ...
- codeforces B. Simple Molecules 解题报告
题目链接:http://codeforces.com/problemset/problem/344/B 题目意思:这句话是解题的关键: The number of bonds of an atom i ...
- codeforces A. The Wall 解题报告
题目链接:http://codeforces.com/problemset/problem/340/A 这道题目理解不难,就是在[a, b]区间内,找出同时能够被x和y整除的个数.第一次想当然的开了两 ...
- codeforces B. Routine Problem 解题报告
题目链接:http://codeforces.com/problemset/problem/337/B 看到这个题目,觉得特别有意思,因为有熟悉的图片(看过的一部电影).接着让我很意外的是,在纸上比划 ...
随机推荐
- (二)js下拉菜单
默认的select标签比较难看,UI比较漂亮,如果想要实现UI上的下拉样式,好像必须用js写select,从网上拷贝而且修改了一个下拉框,为了方便以后引用所以记录下来. /* diy_select * ...
- 回归基础: JavaScript 变量提升
from me: javascript的变量声明具有hoisting机制,它是JavaScript一个基础的知识点,也是一个比较容易犯错的点,平时在开发中,大大小小的项目都会遇到. 它是JavaScr ...
- Oracle中的null
测试数据:公司部分员工基本信息
- Unable to add window -- token null is not for an application
导致报这个错是在于new AlertDialog.Builder(mcontext),虽然这里的参数是AlertDialog.Builder(Context context)但我们不能使用getApp ...
- mysql 查询某个日期时间段,每天同一时间段的数据
mysql 查询某个日期时间段,每天同一时间段的数据: SELECT * FROM t_a01_eltable WHERE DATE_FORMAT(acqtime,'%Y-%m-%d')>='2 ...
- BZOJ 2412: 电路检修
Description [0,x]中全是1,其余全是0,每个点有一个权值,求最坏情况下得到x的最小权值. Sol DP+单调队列. 你可以去看我的这篇Blog...开这篇纯属为了骗访问... http ...
- Android应用反破解的思路
一个Android应用要被破解,要经历:反编译->分析代码->重新编译打包的过程,反破解的思路也是从在这三个步骤上做文章: 1, 寻找反编译工具的缺陷,通过阅读其源码或者对其进行压力测试找 ...
- U盘安装ubuntu server 14.04
U盘安装ubuntu server 14.04 U盘安装ubuntu server 14.04 1.制作启动u盘 2.开始安装 1 将u盘插入主机,重启后从u盘启动 2 选择语言(随便挑,随便选),我 ...
- 9.3---魔术索引(CC150)
魔术索引1:此外下一次应该看看课本上的方法. public boolean findMagicIndex(int[] A, int n){ for(int i = 0; i < A.length ...
- 使用jar命令打war包
1.打开cmd进入web项目发布文件夹 2.,输入jar -cvf qxpt.war * (*表示当前目录下所有子目录) 3,回车等待执行完成就可以了 4.如果web项目发布文件夹有多个文件夹,而打w ...