[Codeforces]Codeforces Round #490 (Div. 3)
Mishka and Contest
#pragma comment(linker, "/STACK:102400000,102400000")
#ifndef ONLINE_JUDGE
#include "stdafx.h"
#else
#include<bits/stdc++.h>
#endif
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI;
typedef map<int, int> MII; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} int a[]; int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
int n, k;
cin >> n >> k;
for (int i = ; i < n; i++) cin >> a[i];
int l = n, r = -;
for (int i = ; i < n; i++) {
if (a[i] > k) {
l = i;
break;
}
}
for (int i = n - ; i >= ; i--) {
if (a[i] > k) {
r = i;
break;
}
}
if (l > r) cout << n << endl;
else cout << (n - (r - l + )) << endl;
return ;
}
Reversing Encryption
splay树,模拟也可以
#pragma comment(linker, "/STACK:102400000,102400000")
#ifndef ONLINE_JUDGE
#include "stdafx.h"
#else
#include<bits/stdc++.h>
#endif
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI;
typedef map<int, int> MII; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} class SplayNode {
public:
SplayNode *child[];
char value;
int size;
bool flip;
SplayNode(char c) : value(c), size(), flip(false) {
child[] = child[] = NULL;
}
int getPosition()const {
return child[] ? child[]->size + : ;
}
void maintain() {
size = ;
if (child[]) {
size += child[]->size;
}
if (child[]) {
size += child[]->size;
}
}
void pushDown() {
if (flip) {
swap(child[], child[]);
for (int i = ; i < ; i++) {
if (child[i]) {
child[i]->flip ^= ;
}
}
flip = false;
}
}
};
class SplayTree {
public:
SplayNode *root;
void init(char *a, int n);
void build(SplayNode *&node, char *begin, char *end);
void rotate(SplayNode *&node, int direction);
void splay(SplayNode *&node, int position);
void reverse(int begin, int end);
void traverse(SplayNode *u);
void traverse();
};
void SplayTree::init(char *a, int n) {
build(root, a, a + n - );
}
void SplayTree::build(SplayNode *&node, char *begin, char *end) {
if (begin > end) {
return;
}
char *middle = begin + ((end - begin) >> );
node = new SplayNode(*middle);
build(node->child[], begin, middle - );
build(node->child[], middle + , end);
node->maintain();
} void SplayTree::rotate(SplayNode *&node, int direction) {
SplayNode *child = node->child[direction ^ ];
node->child[direction ^ ] = child->child[direction];
child->child[direction] = node;
node->maintain();
child->maintain();
node = child;
}
void SplayTree::splay(SplayNode *&node, int position) {
node->pushDown();
if (node->getPosition() != position) {
int d = node->getPosition() < position;
SplayNode *node2 = node->child[d];
position -= d ? node->getPosition() : ;
node2->pushDown();
if (node2->getPosition() != position) {
int d2 = node2->getPosition() < position;
position -= d2 ? node2->getPosition() : ;
splay(node2->child[d2], position);
if (d == d2) {
rotate(node, d ^ );
} else {
rotate(node->child[d], d);
}
}
rotate(node, d ^ );
}
}
void SplayTree::reverse(int begin, int end) {
splay(root, begin);
splay(root->child[], end - begin + );
root->child[]->child[]->flip ^= ;
}
void SplayTree::traverse(SplayNode *u) {
if (!u) {
return;
}
u->pushDown();
traverse(u->child[]);
if (u->value) {
printf("%c", u->value);
}
traverse(u->child[]);
}
void SplayTree::traverse() {
traverse(root);
}
SplayTree st;
char a[]; int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
int n;
cin >> n;
for (int i = ; i <= n; i++) cin >> a[i];
st.init(a, n + );
for (int i = ; i <= n; i++) {
if (n % i == )
st.reverse(, i);
}
st.traverse();
return ;
}
Alphabetic Removals
#pragma comment(linker, "/STACK:102400000,102400000")
#ifndef ONLINE_JUDGE
#include "stdafx.h"
#else
#include<bits/stdc++.h>
#endif
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI;
typedef map<int, int> MII; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} string s;
VI v[], u;
bool f[]; int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
int n, k;
cin >> n >> k;
cin >> s;
for (int i = ; i < n; i++) v[s[i] - 'a'].push_back(i);
for (int i = ; i < ; i++) {
for (int j = ; j < v[i].size(); j++) {
u.push_back(v[i][j]);
}
}
memset(f, true, sizeof(f));
for (int i = ; i < k; i++) f[u[i]] = false;
for (int i = ; i < n; i++) {
if (f[i]) cout << s[i];
}
return ;
}
Equalize the Remainders
贪心
#pragma comment(linker, "/STACK:102400000,102400000")
#ifndef ONLINE_JUDGE
#include "stdafx.h"
#else
#include<bits/stdc++.h>
#endif
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI;
typedef map<int, int> MII; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} int cnt[], nex[];
int n, m, x, r, p, q, t;
VI v;
int getNext(int r) {
if (cnt[nex[r]] < q) return nex[r];
else {
nex[r] = getNext(nex[r]);
return nex[r];
}
} int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
lint ans = ;
cin >> n >> m;
q = n / m;
memset(cnt, , sizeof(cnt));
for (int i = ; i < m; i++) nex[i] = i + ;
nex[m - ] = ;
for (int i = ; i < n; i++) {
cin >> x;
r = x % m;
if (cnt[r] < q) p = r;
else p = getNext(r);
cnt[p]++;
ans += (p + m - r) % m;
v.push_back(x + (p + m - r) % m);
}
cout << ans << endl;
for (int i = ; i < n; i++) cout << v[i] << ' ';
return ;
}
Reachability from the Capital
染色,色块数减一
#pragma comment(linker, "/STACK:102400000,102400000")
#ifndef ONLINE_JUDGE
#include "stdafx.h"
#else
#include<bits/stdc++.h>
#endif
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI;
typedef map<int, int> MII; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} VI G[];
int color[];
bool f[]; void dfs(int x, int c) {
for (int i = ; i < G[x].size(); i++) {
int v = G[x][i];
if (color[v] != c) {
color[v] = c;
dfs(v, c);
}
}
} int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
int n, m, s, u, v;
cin >> n >> m >> s;
for (int i = ; i < m; i++) {
cin >> u >> v;
if (v == s) continue;
G[u].push_back(v);
}
memset(color, , sizeof(color));
for (int i = ; i <= n; i++) {
if (color[i] == ) {
color[i] = i;
dfs(i, i);
}
}
memset(f, false, sizeof(f));
int ans = ;
for (int i = ; i <= n; i++) {
if (!f[color[i]]) ans++;
f[color[i]] = true;
}
cout << ans - << endl;
return ;
}
Cards and Joy
分成若干个子问题,动态规划
#pragma comment(linker, "/STACK:102400000,102400000")
#ifndef ONLINE_JUDGE
#include "stdafx.h"
#else
#include<bits/stdc++.h>
#endif
using namespace std;
typedef long long lint;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef queue<int> QI;
typedef map<int, int> MII; void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
} int f[][];
int p[], h[], c[], k;
int dp(int n, int m) {
int rtn = ;
for (int i = ; i <= k; i++) f[][i] = ;
for (int i = ; i <= n; i++) f[i][] = ;
for (int i = ; i <= n; i++) {
for (int j = ; j <= m && j <= i * k; j++) {
f[i][j] = ;
for (int q = ; q <= k && q <= j; q++) {
f[i][j] = max(f[i][j], f[i - ][j - q] + h[q]);
}
rtn = max(rtn, f[i][j]);
}
}
return rtn;
} int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
//makedata();
std::ios::sync_with_stdio(), cin.tie();
int n, x;
cin >> n >> k;
for (int i = ; i < n * k; i++) {
cin >> x;
c[x]++;
}
for (int i = ; i < n; i++) {
cin >> x;
p[x]++;
}
for (int i = ; i <= k; i++) cin >> h[i];
int ans = ;
for (int i = ; i <= ; i++) {
if (p[i] == || c[i] == ) continue;
else ans += dp(p[i], c[i]);
}
cout << ans << endl;
return ;
}
[Codeforces]Codeforces Round #490 (Div. 3)的更多相关文章
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
- Codeforces Beta Round #73 (Div. 2 Only)
Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...
- Codeforces Beta Round #72 (Div. 2 Only)
Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...
- Codeforces Beta Round #70 (Div. 2)
Codeforces Beta Round #70 (Div. 2) http://codeforces.com/contest/78 A #include<bits/stdc++.h> ...
随机推荐
- 【Codeforces 300C】Beautiful Numbers
[链接] 我是链接,点我呀:) [题意] 让你找到长度为n的数字 这个数字只由a或者b组成 且这n个数码的和也是由a或者b组成的 求出满足这样要求的数字的个数 [题解] 枚举答案数字中b的个数为y,那 ...
- [luoguP1095] 守望者的逃离(DP)
传送门 这题....得考虑一些奇奇怪怪的复杂情况 不过也有简便方法. 枚举时间,先算出来只用魔法走的时间. 然后再枚举一遍时间,再算只走的时间,两个比较一下,取最游值. 代码 #include < ...
- node.js 利用流实现读写同步,边读边写
//10个数 10个字节,每次读4b,写1b let fs=require("fs"); function pipe(source,target) { //先创建可读流,再创建可写 ...
- vue.js 利用组件之间通讯,写一个弹出框例子
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- H3c 配置ssh acl
http://www.h3c.com/cn/d_201108/723349_30005_0.htm
- 基于.NET平台常用的框架整理(转)
基于.NET平台常用的框架整理 分布式缓存框架: Microsoft Velocity:微软自家分布式缓存服务框架. Memcahed:一套分布式的高速缓存系统,目前被许多网站使用以提升网站的访问 ...
- 基于FFI模块CAPI与JavaScript的各种类型匹配总结
0.写在前面: 1)涉及的关键词定义: 传入:JavaScript向CAPI传值 传出:CAPI向JavaScript传值 2)关于类和结构体的封装,需要严格执行内存对齐,以防止读取越界,但是避免不了 ...
- 由文字生成path后制作写字的动画
在看以下这个开源组件的时候,发现一个非常棒的方法,能够将文字生成path,这样就能够作出用笔写字的效果了. https://github.com/MP0w/MPParallaxCollection 关 ...
- 500万url的es 批删除
bash 循环 算术计算 读写文件 [root@hadoop2 ~]# sh looh.sh1234LIZ1 2 3 4 0 1 2 3 4 5 6 7 8 9 10 0games:x:12:100 ...
- 20170410 --- Linux备课资料 --- 压缩与解压缩
这节课我们来学习一下压缩与解压缩,那什么是压缩与解压缩呢? 联想一下Windows系统: 选中文件,右键选择即可 如果压缩,可以选择要压缩的格式,而解压缩直接选择就可以完成了 Linux是通过命令的方 ...