Bayan 2015 Contest Warm Up
来源:互联网 发布:php ajax返回html标签 编辑:程序博客网 时间:2024/05/16 02:14
Bayan 2015 Contest Warm Up
题目链接
A:水题,把对应位置和标号一一匹配上,然后每次k多少对应就去坐多少即可
B:其实只要找周围4条,看能不能形成一个环,因为如果不成环,肯定有一个点会到不了,如果成环,那么中间任意点,就可以到达
C:找出左上角的点,然后以一边为长,枚举另一边的长度,然后dfs一遍,dfs的过程利用容斥可以加速
D:记录下gcd,每次多一个数字,就和前面的数字都取gcd,然后合并掉,下次利用这些已有的gcd去做,然后合并的过程要利用到gcd的递减性质,就可以直接从头往后找即可
代码:
A:
#include <cstdio>#include <cstring>#include <vector>#include <algorithm>#include <string>#include <iostream>using namespace std;int k;string ans[6];int x[35], y[35];int main() {ans[0] = "+------------------------+";ans[1] = "|#.#.#.#.#.#.#.#.#.#.#.|D|)";ans[2] = "|#.#.#.#.#.#.#.#.#.#.#.|.|";ans[3] = "|#.......................|";ans[4] = "|#.#.#.#.#.#.#.#.#.#.#.|.|)";ans[5] = "+------------------------+";x[0] = 1; y[0] = 1;x[1] = 2; y[1] = 1;x[2] = 3; y[2] = 1;x[3] = 4; y[3] = 1;int cnt = 3;for (int i = 4; i < 34; i++) {if ((i - 4) % 3 == 0) {x[i] = 1; y[i] = cnt;}if ((i - 4) % 3 == 1) {x[i] = 2; y[i] = cnt;}if ((i - 4) % 3 == 2) {x[i] = 4; y[i] = cnt;cnt += 2;}}int k;scanf("%d", &k);for (int i = 0; i < k; i++)ans[x[i]][y[i]] = 'O';for (int i = 0; i < 6; i++)cout << ans[i] << endl;return 0;}
B:
#include <cstdio>#include <cstring>#include <vector>using namespace std;int n, m;char a[25], b[25];bool judge(char up, char down, char left, char right) {if (up == down) return false;if (left == right) return false;if (up == '<' && left == '^') return false;if (down == '<' && left == 'v') return false;if (up == '>' && right == '^') return false;if (down == '>' && right == 'v') return false;return true;}int main() {scanf("%d%d", &n, &m);scanf("%s%s", a, b);char up = a[0], down = a[n - 1];char left = b[0], right = b[m - 1];if (judge(up, down, left, right)) printf("YES\n");else printf("NO\n");return 0;}
C:
#include <cstdio>#include <algorithm>#include <cstring>#include <queue>using namespace std;#define sum(x1,y1,x2,y2) (g[x2][y2] - g[x1 - 1][y2] - g[x2][y1 - 1] + g[x1 - 1][y1 - 1])const int INF = 0x3f3f3f3f;const int N = 1005;int n, m, g[N][N], ans = INF;char str[N][N];int dfs(int x,int y,int wx,int wy) {if(sum(x, y + 1, x + wx - 1, y + wy) == wx * wy) return wx + dfs(x, y + 1, wx, wy);if(sum(x + 1, y, x + wx, y + wy - 1) == wx * wy) return wy + dfs(x + 1, y, wx, wy);return 0;}int main() {scanf("%d%d",&n,&m);int flag = 0,px,py;for(int i = 1; i <= n; i++) scanf("%s",str[i] + 1);for(int i = 1; i <= n; i++)for(int j = 1; j <= m; j++) {if(str[i][j] == 'X') {if(!flag) {flag = 1; px = i; py = j;}g[i][j] = g[i - 1][j] + g[i][j - 1] - g[i - 1][j - 1] + 1;}else g[i][j] = g[i - 1][j] + g[i][j - 1] - g[i - 1][j - 1];}int tmp,wx,wy;for(tmp = px; str[tmp][py] == 'X'; tmp++);wx = tmp - px;for(int i = py; str[px][i] == 'X'; i++)if(dfs(px, py, wx, i - py + 1) + wx * (i - py + 1) == g[n][m])ans = min(ans, wx * (i - py + 1));for(tmp = py; str[px][tmp] == 'X'; tmp++);wy = tmp - py;for(int i = px; str[i][py] == 'X'; i++)if(dfs(px, py, i - px + 1, wy) + (i - px + 1) * wy == g[n][m]) ans = min(ans, (i - px + 1) * wy);if (ans == INF) ans = -1;printf("%d\n", ans);return 0;}
D:
#include <cstdio>#include <cstring>#include <algorithm>#include <map>using namespace std;typedef long long ll;typedef pair<int, ll> pii;const int N = 100005;int a[N];pii save[N];map<int, ll> ans;int n;int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}void build() {int top = 0;for (int i = 1; i <= n; i++) {for (int j = 0; j < top; j++) save[j].first = gcd(save[j].first, a[i]);save[top++] = make_pair(a[i], 1LL);int sn = 1;for (int j = 1; j < top; j++) {if (save[sn - 1].first == save[j].first) save[sn - 1].second += save[j].second;else save[sn++] = save[j];}top = sn;for (int j = 0; j < top; j++) {ans[save[j].first] += save[j].second;}}}int main() {scanf("%d", &n);for (int i = 1; i <= n; i++)scanf("%d", &a[i]);build();int q;scanf("%d", &q);while (q--) {int x;scanf("%d", &x);printf("%lld\n", ans[x]);}return 0;}
1 0
- Bayan 2015 Contest Warm Up
- Bayan 2015 Contest Warm Up
- Bayan 2015 Contest Warm Up (D题)
- Bayan 2015 Contest Warm Up D题(GCD)
- CF Bayan 2015 Contest Warm Up A.(模拟+预处理)
- CF Bayan 2015 Contest Warm Up B.(dfs+暴力)
- Bayan 2015 Contest Warm Up C题(DP+模拟)
- codeforce Bayan 2015 Contest Warm Up D CGCDSSQ
- Bayan 2015 Contest Warm Up D. CGCDSSQ (数论)
- Bayan 2015 Contest Warm Up(C,D)
- map+pair Bayan 2015 Contest Warm Up D题
- CF Bayan 2015 Contest Warm Up B. Kamal-ol-molk's Painting
- CODEFORCES Bayan 2015 Contest Warm Up A题= =WA啦!~~!!!
- CF Bayan 2015 Contest Warm Up B题 Strongly Connected City
- Bayan 2015 Contest Warm Up E题(双连通分量缩点+DP计数)
- 2015 HNU Warm Up 01
- 2015 HNU warm up 02
- 2015 HNU warm up 03
- Android多个Activity之间共享类(数据)——Application Context
- 利用mysql内置函数加锁
- Linux 的启动流程
- 1156. Binary tree
- 面向对象编程的两顶帽子
- Bayan 2015 Contest Warm Up
- Android开发系列(十四):ListView用法、对ListView监听的三种方法以及ListView中Adapter的使用方法
- 婴幼儿食谱
- (4)Launcher客制化之 workspace长按事件弹出Widgets界面
- Node.js的调试
- 获取安卓百度地图两点间的直线距离并画线
- SQL不同服务器数据库之间的数据操作整理(完整版)
- 关于dll和lib(傻乎乎的我 又学到一点)
- rsh 无秘钥登陆配置