Codeforces Beta Round #3
来源:互联网 发布:雷电法术升级数据2017 编辑:程序博客网 时间:2024/04/28 17:56
A. Shortest path of the king
题意:在给定国际象棋上王的起始位置,求王到另一位置走的最少步数。并一种移动方案。王走的八个方向分别为用(L,R,U,D,LR,RD,LU,LD)表示
输入:给定起点和终点
输出:要走的最少路和一种走的方式。
题解:假设王的开始的坐标为(x0,y0),终点为(x1,y1),则容易得到下一步要尽量靠尽,所以要让(x,y)都有变化,即尽量走斜线。
代码:
//written by nothi//话说写麻烦了#include <math.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#define MAX(a,b) ((a)>(b)?(a):(b))struct Cood{ int x; int y;};Cood begin, end;//L R U D LU LD RU RDint maxp = 8;const int dx[] = {-1,+1,0,0,-1,-1,+1,+1};const int dy[] = {0,0,+1,-1,+1,-1,+1,-1};void print(int i){ if(i == 0) printf("L"); if(i == 1) printf("R"); if(i == 2) printf("U"); if(i == 3) printf("D"); if(i == 4) printf("LU"); if(i == 5) printf("LD"); if(i == 6) printf("RU"); if(i == 7) printf("RD"); printf("\n");}int main(){ char a, b; int i, j, x, y, ans; scanf(" %c%d %c%d",&a, &x, &b, &y); begin.x = a - 'a' + 1; begin.y = x; end.x = b - 'a' + 1; end.y = y; ans = MAX(abs(begin.x - end.x),abs(begin.y - end.y)); printf("%d\n",ans); int cur_x = begin.x; int cur_y = begin.y; for(i = 0; i < ans; i++){int min = ans+1, now;for(j = maxp-1; j >= 0; j--){ int u = cur_x + dx[j]; int v = cur_y + dy[j]; int cur = MAX(abs(u - end.x),abs(v - end.y)); if(cur == ans - i - 1){min = cur;now = j; }}print(now);cur_x += dx[now];cur_y += dy[now]; } return 0;}
B. Lorry
暂没做
C. Tic-tac-toe
题意:给定一 个一字棋的局面,让你判断是一下列局面中的哪一种
1、是否合法、
2、第一个人胜了
3、第二个人胜了
4、下一个是第一个人
5、下一个是第二个人
6、完了
输入:一个一字棋的局面:"0" 代表 第一个人下的棋,"X"代表第二个人下的棋,"."代表空
输出:是哪种局面
题解:很烦的权举,注意我认为最发的是把所有的情况都写出来,再看看读入的局面是否在其中。不过,当时没有而是写了各种if。代码各种长...
代码:
#include <stdio.h>#include <stdlib.h>#include <string.h>const int maxn = 3;char grid[maxn][maxn];int can = 1;int won = 0;int ok1[2] = {0,0};char get(){ char c = getchar(); while(c != '.' && c != '0' && c != 'X'){if(c != '\n' && c != ' '){ can = 0; printf("illegal\n"); exit(0);}c = getchar(); } return c;}int line(){ int now = 0; int i, j, k; for(i = 0; i < 3; i++){if(grid[i][0] != '.'){ int ok = 1; for(j = 1; j < 3; j++)if(grid[i][j] != grid[i][0]) ok = 0; now += ok; if(ok) {won = grid[i][0];if(grid[i][0] == '0') ok1[0] = 1;else ok1[1] = 1; }}if(grid[0][i] != '.'){ int ok = 1; for(j = 1; j < 3; j++)if(grid[j][i] != grid[0][i]) ok = 0; now += ok; if(ok){ won = grid[0][i];if(grid[0][i] == '0') ok1[0] = 1;else ok1[1] = 1; }} } if(grid[0][0] == grid[1][1] && grid[1][1] == grid[2][2] && grid[0][0] != '.'){now++;won = grid[0][0];if(grid[1][1] == '0') ok1[0] = 1;else ok1[1] = 1; } if(grid[0][2] == grid[1][1] && grid[1][1] == grid[2][0] && grid[0][2] != '.'){now++;won =grid[0][2];if(grid[1][1] == '0') ok1[0] = 1;else ok1[1] = 1; } return now;}int main(){ int i, j, n = maxn; int* ok = ok1; for(i = 0; i < n; i++)for(j = 0; j < n; j++) grid[i][j] = get(); int first, second; first = second = 0; for(i = 0; i < n; i++)for(j = 0; j < n; j++) if(grid[i][j] == 'X') first++; else if(grid[i][j] == '0') second++; int l = line(); if(can == 0){printf("illegal\n"); }else if(first < second || first-second > 1 || ok[0] == 1 && ok[1] == 1)printf("illegal\n"); else if(l == 1 || first + second == 9 || ok[0] || ok[1]) if(l == 0) printf("draw\n");else if(ok[1]) if(first > second)printf("the first player won\n"); elseprintf("illegal\n");else { if(first == second)printf("the second player won\n"); else printf("illegal\n");} else if(first > second)printf("second\n"); else printf("first\n"); return 0;}
D. Least Cost Bracket Sequence
暂没做
- Codeforces Beta Round #3
- Codeforces Beta Round #3
- Codeforces Beta Round #3
- Codeforces Beta Round #3
- Codeforces Beta Round #3
- Codeforces Beta Round #3
- Codeforces Beta Round #3 练习
- Codeforces Beta Round #3 B
- Codeforces Beta Round #3 B. Lorry
- Codeforces Beta Round #3 B. Lorry
- Codeforces Beta Round #2
- Codeforces Beta Round #24
- Codeforces Beta Round #64
- Codeforces Beta Round #23
- Codeforces Beta Round #88
- Codeforces Beta Round #88
- Codeforces Beta Round #91
- Codeforces Beta Round #93
- 黑帽SEO和白帽SEO区别
- Linq动态排序扩展方法
- WebSites
- 一个大专毕业生毕业3个月后的个人感想及总结
- 本地wordpress 上传不能和 ftp问题
- Codeforces Beta Round #3
- Servlet过滤器Filter使用
- 反思
- Visual C++ 2005 Express 配置 Microsoft Platform SDK
- 强力推荐Linux下的五大BT下载工具
- S 1.2 palsquare C程序
- Qucs中文应用手册-03(入门)
- 2012ACM杭州站
- CentOs 忘记MySQLroot密码的解决方案