Codeforces Round #323 (Div. 2)
被进爷坑了,第二天的比赛改到了12点
/************************************************
* Author :Running_Time
* Created Time :2015/10/3 星期六 21:53:09
* File Name :A.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 55;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
bool r[N], c[N]; int main(void) {
memset (r, false, sizeof (r));
memset (c, false, sizeof (c));
int n; scanf ("%d", &n);
vector<int> ans;
n = n * n;
for (int x, y, i=1; i<=n; ++i) {
scanf ("%d%d", &x, &y);
if (!r[x] && !c[y]) {
r[x] = c[y] = true;
ans.push_back (i);
}
}
for (int i=0; i<ans.size (); ++i) {
printf ("%d%c", ans[i], (i == ans.size () - 1) ? '\n' : ' ');
} return 0;
}
/************************************************
* Author :Running_Time
* Created Time :2015/10/3 星期六 21:53:24
* File Name :B.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e3 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
int a[N]; int main(void) {
int n; scanf ("%d", &n);
for (int i=1; i<=n; ++i) {
scanf ("%d", &a[i]);
}
int ans = 0, d = 1, m = 0, p = 0;
bool flag = false;
while (true) {
if (d == 1) {
for (int i=p+1; i<=n; ++i) {
if (m >= a[i]) {
a[i] = INF;
m++; p = i;
flag = true;
}
}
if (m == n) break;
d ^= 1; ans++;
}
else {
for (int i=p-1; i>=1; --i) {
if (m >= a[i]) {
a[i] = INF;
m++; p = i;
flag = true;
}
}
if (m == n) break;
d ^= 1; ans++;
}
}
printf ("%d\n", ans); return 0;
}
题意:给了一张GCD表,问原来的求GCD的那些数
分析:从大到小找,最大的数和其他的数的GCD都不大于它,每次找到一个就能把它和已知的答案的GCD给删除,map+暴力就可以了
/************************************************
* Author :Running_Time
* Created Time :2015/10/3 星期六 21:53:35
* File Name :C.cpp
************************************************/
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 5e2 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
int a[N*N];
int ans[N];
map<int, int> cnt; int GCD(int a, int b) {
return b ? GCD (b, a % b) : a;
} int main(void) {
int n; scanf ("%d", &n);
int m = n;
n = n * n;
for (int i=1; i<=n; ++i) {
scanf ("%d", &a[i]);
cnt[-a[i]]++;
}
int pos = m;
map<int, int>::iterator it;
for (it=cnt.begin (); it!=cnt.end (); ++it) {
int x = -it -> first;
while (it -> second) {
ans[pos] = x;
--it -> second;
for (int i=pos+1; i<=m; ++i) {
cnt[-GCD (ans[pos], ans[i])] -= 2;
}
pos--;
}
} for (int i=1; i<=m; ++i) {
printf ("%d%c", ans[i], (i == m) ? '\n' : ' ');
} return 0;
}
Codeforces Round #323 (Div. 2)的更多相关文章
- Codeforces Round #323 (Div. 1) B. Once Again... 暴力
B. Once Again... Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/582/probl ...
- 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 ...
- 重复T次的LIS的dp Codeforces Round #323 (Div. 2) D
http://codeforces.com/contest/583/problem/D 原题:You are given an array of positive integers a1, a2, . ...
- Codeforces Round #323 (Div. 2) D. Once Again... 乱搞+LIS
D. Once Again... time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- 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 #323 (Div. 2) E - Superior Periodic Subarrays
E - Superior Periodic Subarrays 好难的一题啊... 这个博客讲的很好,搬运一下. https://blog.csdn.net/thy_asdf/article/deta ...
- Codeforces Round #323 (Div. 2) D 582B Once Again...(快速幂)
A[i][j]表示在循环节下标i开头j结尾的最长不减子序列,这个序列的长度为p,另外一个长度为q的序列对应的矩阵为B[i][j], 将两序列合并,新的序列对应矩阵C[i][j] = max(A[i][ ...
- Codeforces Round #323 (Div. 2) C GCD Table 582A (贪心)
对角线上的元素就是a[i],而且在所在行和列中最大, 首先可以确定的是最大的元素一定是a[i]之一,这让人想到到了排序. 经过排序后,每次选最大的数字,如果不是之前更大数字的gcd,那么只能是a[i] ...
随机推荐
- Printf可变參数使用
參考文档: http://bbs.csdn.net/topics/70288067 Owed by: 春夜喜雨 http://blog.csdn.net/chunyexiyu 转载请标明来源 本文的二 ...
- Mahout 0.5部署
Mahout下载与安装 1.下载Mahout.到地址[1]可以找到镜像地址.我们下载Mahout 0.5.请将mahout-distribution-0.5.tar.gz和mahout-distrib ...
- 使用Android Studio查看API文档
在使用Android Studio编码时,若要查看某个类或函数的释义, 只需将光标移动至要查看释义的代码处,然后按下Ctrl+Q,便会弹出文档描述. 然而,有时候会出现如下状况: 因为默认查看的是在线 ...
- 微信小程序 新手入门教程
因为工作需要,最近学习了一下微信小程序,在此分享一下大概的流程. 强烈建议大家先去看微信小程序简易教程:点我进入 起步: 安装微信web开发软件者工具,需要破解的同学可以网上找破解教程,很简单的,这里 ...
- MySQL数据库设计常犯的错以及对性能的影响
1.过分的反范式化为表建立太多的列 我们在设计数据库的结构时,比较容易犯的第一个错误就是对表进行了过分的反范式化的设计,这就容易造成了表中的列过多,虽然说Mysql允许为一个表建立很多的列,但是由于M ...
- hive 中 Order by, Sort by ,Dristribute by,Cluster By 的作用和用法
order by order by 会对输入做全局排序,因此只有一个reducer(多个reducer无法保证全局有序) 只有一个reducer,会导致当输入规模较大时,需要较长的计算时间. set ...
- OCCI编程接口介绍
OCCI简介 Oracle® C++ Call Interface (OCCI) 是一套应用程序编程接口,它允许C++程序与一个或者多个Oracle数据库进行交互.OCCI给予你强大的数据库操作能力, ...
- 使用lsyncd配置数据库备份多异地同步
lsyncd配置文件 settings { logfile = "/var/log/lsyncd.log", --日志路径 status = "/var/log/lsyn ...
- CodeBlocks+Qt(MinGW)配置
1.安装CodeBlocks 官网:http://www.codeblocks.org/ 下载地址:http://www.codeblocks.org/downloads/26 有以下两种选择 cod ...
- ASP.NET Core:WebAppCoreReact
ylbtech-ASP.NET Core:WebAppCoreReact 1.返回顶部 1. 2. 3. 4. 5. 6. 7. 2. wwwroot 返回顶部 3. Clie ...