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)的更多相关文章

  1. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  2. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  3. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  4. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  5. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  6. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

  7. Codeforces Beta Round #74 (Div. 2 Only)

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

  8. Codeforces Beta Round #73 (Div. 2 Only)

    Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...

  9. Codeforces Beta Round #72 (Div. 2 Only)

    Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...

  10. Codeforces Beta Round #70 (Div. 2)

    Codeforces Beta Round #70 (Div. 2) http://codeforces.com/contest/78 A #include<bits/stdc++.h> ...

随机推荐

  1. swift kilo版代码更新

    今天重新搭建swift服务器,git下代码后一时好奇,进入kilo/stable branch后,与四个月前下载的swift/kilo版本做了个比较.使用diff命令完成.发现代码还是略有区别. di ...

  2. codevs1174 靶形数独

    题目描述 Description 小城和小华都是热爱数学的好学生,最近,他们不约而同地迷上了数独游戏,好胜的他们想用数独来一比高低.但普通的数独对他们来说都过于简单了,于是他们向Z 博士请教,Z 博士 ...

  3. Linux tree 命令用法

    linux下的tree就比较强大了,但一般系统并不自带这个命令,需要手动下载安装:sudo apt-get install tree .文件很小,只有31K,但功能可强大了!  tree命令的参数解释 ...

  4. I - 最少拦截系统

    #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; ],su ...

  5. Ubuntu 16.04安装Bless十六进制编辑器

    一款专注于十六进制的编辑器. 安装: sudo apt-get install bless 启动:

  6. Chrome 如何查看/修改Cookie

  7. NYOJ 16 矩形嵌套 (DAG上的DP)

    矩形嵌套 时间限制:3000 ms  |  内存限制:65535 KB 难度:4 描写叙述 有n个矩形,每个矩形能够用a,b来描写叙述.表示长和宽.矩形X(a,b)能够嵌套在矩形Y(c,d)中当且仅当 ...

  8. 第K顺序统计量的求解

    一个n个元素组成的集合中,第K个顺序统计量(Order Statistic)指的是该集合中第K小的元素,我们要讨论的是如何在线性时间(linear time)里找出一个数组的第K个顺序统计量. 一.问 ...

  9. input屏蔽历史记录 ;function($,undefined) 前面的分号是什么用处 JSON 和 JSONP 两兄弟 document.body.scrollTop与document.documentElement.scrollTop兼容 URL中的# 网站性能优化 前端必知的ajax 简单理解同步与异步 那些年,我们被耍过的bug——has

    input屏蔽历史记录   设置input的扩展属性autocomplete 为off即可 ;function($,undefined) 前面的分号是什么用处   ;(function($){$.ex ...

  10. 用NuGet安装NewtonSoft.json

    因为要在C#里读取JSON字符串,资料查来查去,发现只能用第三方的NewtonSoft.json.本来.net也有自带的类库可以处理json,但TM的不停要你将JSON读进类对象里面.我靠,我只不过想 ...