思维题 2017.3.3
来源:互联网 发布:java中 voliate原理 编辑:程序博客网 时间:2024/05/29 09:59
1、Codeforces 570C Replacement
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>#include <map>#include <queue>#include <stack>#include <set>#include <bitset>#include <ctime>#include <cctype>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair<int, int> Pair;const ll mod = 1e9 + 7;const int INF = 0x7fffffff;const int maxn = 3e5 + 10;int n, m, sum = 0, x;char c;char s[maxn];int main(){#ifdef __AiR_H freopen("in.txt", "r", stdin);#endif // __AiR_H_ scanf("%d %d %s", &n, &m, s); int cnt = 0; for (int i = 0; i < n; ++i) { if (s[i] == '.') { ++cnt; if (cnt >= 2) { ++sum; } } else { cnt = 0; } } while (m--) { scanf("%d %c", &x, &c); if (c != '.' && s[x - 1] == '.') { if (x > 1 && s[x - 2] == '.') { --sum; } if (x < n + 1 && s[x] == '.') { --sum; } } else if (c == '.' && s[x - 1] != '.') { if (x > 1 && s[x - 2] == '.') { ++sum; } if (x < n + 1 && s[x] == '.') { ++sum; } } s[x - 1] = c; printf("%d\n", sum); } return 0;}
2、Codeforces 713A Sonya and Queries
参考:http://codeforces.com/contest/713/standings
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>#include <map>#include <queue>#include <stack>#include <set>#include <bitset>#include <ctime>#include <cctype>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair<int, int> Pair;const ll mod = 1e9 + 7;const int INF = 0x7fffffff;const int maxn = 5e5 + 10;int t;int cnt[maxn];char cmd[10], s[30];int main(){#ifdef __AiR_H freopen("in.txt", "r", stdin);#endif // __AiR_H_ scanf("%d", &t); while (t--) { scanf("%s %s", cmd, s); int len = strlen(s); int key = 0; for (int i = 0; i < len; ++i) { key = key << 1 | ((s[i] - '0') & 1); } if (cmd[0] == '+') { ++cnt[key]; } else if (cmd[0] == '-') { --cnt[key]; } else { printf("%d\n", cnt[key]); } } return 0;}
3、Codeforces 704A Thor
参考:http://codeforces.com/contest/704/standings
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>#include <map>#include <queue>#include <stack>#include <set>#include <bitset>#include <ctime>#include <cctype>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair<int, int> Pair;const ll mod = 1e9 + 7;const int INF = 0x7fffffff;const int maxn = 3e5 + 10;int n, q, type, x, cur = 1;vector<int> V[maxn];bool vis[maxn];int main(){#ifdef __AiR_H freopen("in.txt", "r", stdin);#endif // __AiR_H_ scanf("%d %d", &n, &q); int ans = 0, cnt = 0; for (int i = 1; i <= q; ++i) { scanf("%d %d", &type, &x); if (type == 1) { ++ans; V[x].push_back(++cnt); } else if (type == 2) { int Size = V[x].size(); for (int i = 0; i < Size; ++i) { if (!vis[V[x][i]]) { vis[V[x][i]] = true, --ans; } } V[x].clear(); } else { for (int i = cur; i <= x; ++i) { if (!vis[i]) { vis[i] = true, --ans; } } cur = max(cur, x + 1); } printf("%d\n", ans); } return 0;}
4、Codeforces 518C Anya and Smartphone
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>#include <map>#include <queue>#include <stack>#include <set>#include <bitset>#include <ctime>#include <cctype>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair<int, int> Pair;const ll mod = 1e9 + 7;const int INF = 0x7fffffff;const int maxn = 1e5 + 10;int n, m, k;int a[maxn], b[maxn], belong[maxn], pos[maxn];int main(){#ifdef __AiR_H freopen("in.txt", "r", stdin);#endif // __AiR_H_ ll ans = 0; scanf("%d %d %d", &n, &m, &k); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); pos[a[i]] = i + 1; belong[a[i]] = i / k + 1; } for (int i = 0; i < m; ++i) { scanf("%d", &b[i]); ans += (ll)belong[b[i]]; if (pos[b[i]] != 1) { int l = a[pos[b[i]] - 2], r = b[i]; int pos_r = pos[r], pos_l = pos[l]; swap(a[pos_l - 1], a[pos_r - 1]); ++pos[l], --pos[r]; belong[l] = (pos[l] - 1) / k + 1; belong[r] = (pos[r] - 1) / k + 1; } } printf("%lld\n", ans); return 0;}
5、POJ 3276 Face The Right Way
参考:《挑战程序设计竞赛》P152
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <queue>#include <vector>#include <stack>#include <map>#include <set>#include <cmath>#include <cctype>#include <ctime>#include <cassert>using namespace std;#define REP(i, n) for (int i = 0; i < (n); ++i)#define eps 1e-9typedef long long ll;typedef pair<int, int> pii;const int INF = 0x7fffffff;const int maxn = 5e3 + 10;int N;int dp[maxn], key[maxn];char face[2];int main() {#ifdef __AiR_H freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);#endif // __AiR_H scanf("%d", &N); REP(i, N) { scanf("%s", face); if (face[0] == 'F') { key[i] = 1; } else { key[i] = 0; } } int sum = 0, cur = 0, pos = 0, ans_t = 0, ans_M = INF, ans_K = 0; bool flag = true; for (int i = 1; i <= N; ++i) { ans_t = 0; cur = 0; pos = 0; flag = true; memset(dp, 0, sizeof(dp)); REP(j, N) { if (j >= i && j - i >= pos) { sum -= dp[j - i]; } if (cur <= j) { sum = 0; pos = j; if (key[j] == 0) { dp[j] = 1; ++sum; ++ans_t; cur = j + i; } else { cur = max(cur, j + 1); } } else if (((sum & 1) && key[j] == 1) || (!(sum & 1) && key[j] == 0)) { dp[j] = 1; ++sum; ++ans_t, cur = j + i; } if (cur > N) { flag = false; break; } if (ans_t > ans_M) { break; } } if (flag && ans_t < ans_M) { ans_M = ans_t; ans_K = i; } } printf("%d %d\n", ans_K, ans_M);#ifdef __AiR_H printf("Time used = %.2fs\n", (double)clock() / CLOCKS_PER_SEC);#endif // __AiR_H return 0;}
0 0
- 思维题 2017.3.3
- 思维题
- 暑假第三期---思维题3
- HDU 5596 思维题(逆向思维)*
- 有意思的思维题
- HDU4357(数学思维题)
- Number Sequence(思维题)
- Acdreamoj1115(数学思维题)
- Java思维题
- zoj 3672 思维题
- zoj 3672 思维题
- ACdreamoj 1417 思维题
- hdu 5101 思维题
- hdu4932(思维题)
- hdu4982(思维题)
- CF18B 思维题
- [思维题]Bored Qishen
- poj1083 思维题
- PHP实现二叉树的深度优先遍历(前序、中序、后序)和广度优先遍历(层次)
- MySQL my.cnf参数配置优化详解
- 老鸟的Python入门教程
- 钩子够不上来第一条消息
- JQuery中ajax()方法参数详解
- 思维题 2017.3.3
- 威利方舟 TCI-Ⅲ-B 支持的靶控药物以及药代动力学模型
- 26种提高ASP.NET网站访问性能的优化方法
- BZOJ3709 [PA2014]Bohater
- 【Codeforces 444A DZY Loves Physics】
- jdbc连接
- angularJs select用法详解
- 第5天
- 【GIT】 git rebase 使用