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. 马悦:《Linux内核分析》MOOC课程

    http://www.cnblogs.com/20135235my/p/5237267.html

  2. Vim tips——Working with external commands

    A common sequence of events when editing files is to make a change and then need to test by executin ...

  3. HDU 5305 Friends(简单DFS)

    Friends Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Su ...

  4. LeetCode 443. String Compression (压缩字符串)

    题目标签:String 这一题需要3个pointers: anchor:标记下一个需要存入的char read:找到下一个不同的char write:标记需要存入的位置 让 read指针 去找到下一个 ...

  5. 怎样编辑LRC歌词

    恭喜恭喜歌词 唐嫣 - 音乐巴士 http://www.yy8844.cn/geci/mswcn/nvunns.shtml 恭喜恭喜歌词感谢 音乐巴士 珍妮 编辑歌词匹配时间为: 03 分 06 秒 ...

  6. UVA1602 Lattice Animals 搜索+剪枝

    题目大意 给出一个$w\times h$的网格,定义一个连通块为一个元素个数为$n$的方格的集合$A,\forall x\in A, \exists y\in A$,使得$x,y$有一条公共边.现要求 ...

  7. oc84--单利

    // Tools.h #import <Foundation/Foundation.h> @interface Tools : NSObject<NSCopying, NSMutab ...

  8. ZOJ 1860:Dog & Gopher

    Dog & Gopher Time Limit: 2 Seconds      Memory Limit: 65536 KB A large field has a dog and a gop ...

  9. https://github.com/Boris-Em/BEMCheckBox

    https://github.com/Boris-Em/BEMCheckBox BEMCheckBox BEMCheckBox is an open source library making it ...

  10. Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/util/POILogFactory

    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/poi/util/POILogFacto ...