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] ...
随机推荐
- Ajax的简单实现
Ajax的实现需要服务器端和客户端配合来实现 下面看服务器端的代码,也就是用php编写的一个后台脚本文件 <?php //设置页面内容,编码格式是utf8 header("Conten ...
- 设计模式学习笔记——Chain of Responsibility职责链模式
重点在链.一条链,如果本节点处理不了,则传递给下一个节点处理. 关键是如何传给下一个节点? 主要是由本节点决定传给哪一个节点. public class Client { public static ...
- liberOJ #2033. 「SDOI2016」生成魔咒 后缀数组
#2033. 「SDOI2016」生成魔咒 题目描述 魔咒串由许多魔咒字符组成,魔咒字符可以用数字表示.例如可以将魔咒字符 1 11.2 22 拼凑起来形成一个魔咒串 [1,2] [1, 2] ...
- 报错:out of memory java heap space
PermGen space的全称是Permanent Generation space,是指内存的永久保存区域OutOfMemoryError: PermGen space从表面上看就是内存益出,解决 ...
- 自己写的canvas 手写画板
<!DOCTYPE html> <html> <head> <title>canvas</title> <meta charset=& ...
- uCOS-II模拟(VS2010&WIN32)
转自http://www.amobbs.com/thread-5462878-1-1.html 自学uCOS-II源码,在论坛上上看到大神在WIN7 Visual Studio 2010环境下调试uC ...
- import data from excel to sql server
https://www.c-sharpcorner.com/article/how-to-import-excel-data-in-sql-server-2014/ 需要注意的是,第一次是选择sour ...
- Could not load file or assembly 'MyAssembly.XmlSerializers
https://stackoverflow.com/questions/17755559/could-not-load-file-or-assembly-myassembly-xmlserialize ...
- Could not load file or assembly 'System.Web.Http
使用FusLogVw https://stackoverflow.com/questions/4469929/could-not-load-file-or-assembly-or-one-of-its ...
- cassandra在服务端像leveldb一样进行插入初试成功
经过研究,决定在 cql3/QueryProcessor.java 里面下手. 这里有两个函数,第一个是 public ResultMessage process(String queryString ...