[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> ...
随机推荐
- Docker定制镜像
定制镜像 除了使用定制好的镜像外,我们也可以通过定制实现符合自己环境的镜像. 在docker里面通过build方法来生成镜像,在生成镜像之前,我们需要一个Dockerfile脚本,脚本中包含的是一条一 ...
- vue用js部分控制动画实现
上次我们提到用vue实现过渡动画,其实只讲了vue动画的一部分,用vue自带的css状态控制动画实现,不带js http://www.cnblogs.com/null11/p/7081506.html ...
- Oracle删除约束和主键的语句
https://blog.csdn.net/xue_yanan/article/details/78210654?locationNum=8&fps=1
- 最小生成树 D - Constructing Roads
There are N villages, which are numbered from 1 to N, and you should build some roads such that ever ...
- HDU1530(最大团)
Given a graph G(V, E), a clique is a sub-graph g(v, e), so that for all vertex pairs v1, v2 in v, th ...
- 3、Java并发性和多线程-多线程的代价
以下内容转自http://ifeve.com/costs-of-multithreading/: 从一个单线程的应用到一个多线程的应用并不仅仅带来好处,它也会有一些代价.不要仅仅为了使用多线程而使用多 ...
- Java实现打印功能-AWT Graphics2D
Java实现打印功能 用java实现打印,java.awt中提供了一些打印的API,要实现打印,首先要获得打印对象,然后继承Printable实现接口方法print,以便打印机进行打印,最后用用Gra ...
- Material-design icon生成插件
在使用android studio开发android应用的过程.会遇到一些非常不错的插件,当中android-material-design-icon-generator-plugin 是一个Mate ...
- 表格属就用treegrid
http://maxazan.github.io/jquery-treegrid/ 如果想ajax后台动态添加表格数据然后再形成treegrid,那么可以通过后台给一个对应行索引的数组, 进行动态改变 ...
- 跟我一起写Makefile:概述
什么是makefile?也许非常多Winodws的程序猿都不知道这个东西.由于那些Windows的集成开发环境(integrateddevelopment environment,IDE)都为你做了这 ...