Home  >  Article  >  Web Front-end  >  Codeforces Round #267 (Div. 2)_html/css_WEB-ITnose

Codeforces Round #267 (Div. 2)_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:57:34942browse

Codeforces Round #267 (Div. 2)

A:签到题,直接for一遍

B:取异或就是不同的数,然后bitcount一下判断即可

C:dp,dp[i]表示到i的最大值,然后对取与不取当前位置进行转移即可,要先把前缀和预处理出来

D:先利用map,把字符串hash掉,然后建图,现场在做的时候是直接记忆化搜索,不过这样处理不了环的情况,果断fst了,后来换了下姿势,先求强连通进行缩点,缩点完就是一个dag了,然后记忆化搜索即可

代码:

A:

#include <cstdio>int main() {	int n, p, q;	int ans = 0;	scanf("%d", &n);	while (n--) {		scanf("%d%d", &p, &q);		if (q - p >= 2) ans++;	}	printf("%d\n", ans);	return 0;}</cstdio>

B:

#include <cstdio>#include <cstring>int n, m, k;int bitcount(int x) {	int ans = 0;	while (x) {		ans += (x&1);		x >>= 1;	}	return ans;}const int N = 1005;int x[N];int main() {	scanf("%d%d%d", &n, &m, &k);	for (int i = 0; i   <br> C:  <p></p>  <p> </p>  <pre name="code" class="sycode">#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 5005;const long long INF = 0x3f3f3f3f3f3f3f;long long dp[N][N];int n, m, k;long long num[N], pre[N];int main() {	scanf("%d%d%d", &n, &m, &k);	for (int i = 1; i = m)				dp[i][j] = max(dp[i][j], dp[i - m][j - 1] + pre[i] - pre[i - m]);			dp[i][j] = max(dp[i][j], dp[i - 1][j]);		}	}	printf("%lld\n", dp[n][k]);	return 0;}</algorithm></cstring></cstdio>

D:

#include <cstdio>#include <cstring>#include <vector>#include <stack>#include <algorithm>#include <string>#include <iostream>#include <map>using namespace std;typedef long long ll;const int N = 1000005;vector<int> g[N], scc[N];int pre[N], lowlink[N], sccno[N], dfs_clock, scc_cnt;stack<int> S;typedef pair<ll ll> pii;int n, m, hn;map<string int> hash;string str[N];pii s[N];pii p[N];pii dp[N];int vis[N];vector<int> g2[N];void dfs_scc(int u) {	pre[u] = lowlink[u] = ++dfs_clock;	S.push(u);	for (int i = 0; i = 'A' && str[i] > str[i];		get(str[i]);	}	scanf("%d", &m);	string u, v;	while (m--) {		cin >> u >> v;		int uu = get(u);		int vv = get(v);		g[uu].push_back(vv);	}	find_scc(hn);	ll ans1 = 0, ans2 = 0;	for (int i = 0; i   <br>  <br>  <p></p> </int></string></ll></int></int></map></iostream></string></algorithm></stack></vector></cstring></cstdio>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn