[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> ...
随机推荐
- [BZOJ2120] 数颜色 && [bzoj2453] 维护队列(莫队 || 分块)
传送门 只有第一个,第二个权限题. 分块,然而wa,没看出来错在哪里,有时间再看. #include <cmath> #include <cstdio> #include &l ...
- hdu 2602 简单0-1背包模板题
#include<stdio.h> #include<string.h> #define N 1100 int dp[N]; int main() { int n,t,m,a[ ...
- JS中showModalDialog 详细使用方法
基本介绍: showModalDialog() (IE 4+ 支持) showModelessDialog() (IE 5+ 支持) window.showModalDialog() 方法用来创建一个 ...
- [USACO5.3]校园网Network of Schools 缩点
题目描述 一些学校连入一个电脑网络.那些学校已订立了协议:每个学校都会给其它的一些学校分发软件(称作“接受学校”).注意即使 B 在 A 学校的分发列表中, A 也不一定在 B 学校的列表中. 你要写 ...
- 多项式输出 2009年NOIP全国联赛普及组
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 一元 n 次多项式可用如下的表达式表示:数,请按照如下规定的格式要求输出该多项式 ...
- 为什么Java使用System.getenv()获取刚刚设置的环境变量时为空
场景: 在Ubuntu下已经启动了Eclipse,然后通过终端设置了环境变量(export $ENV=123),然后通过System.getenv()获取时显示为空. 解释: 环境变量仅在进程树下方, ...
- FAST_START_MTTR_TARGET
Release 9i introduced a new parameter, FAST_START_MTTR_TARGET, that makes controlling instance recov ...
- 第5章 Cisco测试命令和TCP/IP连接故障处理
第5章 Cisco测试命令和TCP/IP连接故障处理 一.故障处理命令 1.show命令: 1) 全局命令: show version :显示系统硬件和软件版本.DRAM.Flash show sta ...
- 编程规范(一 之kmalloc,fflush,fclose,char_init)
1. kmalloc函数接口: 在我们使用的时候常常使用该接口,可是我们非常少注意过这个接口的一些比較重要的 内核接口.比如: /*申请一个HASH表的大小*/ #define HASH_MALLOC ...
- POJ 题目2761 Feed the dogs(主席树||划分树)
Feed the dogs Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 16860 Accepted: 5273 De ...