CSU1459:Chess
Description
Input
Output
Sample Input
3 E 2 E 3 F 1 E 8 A 3 A 3
Sample Output
Impossible 2 F 1 B 5 E 8 0 A 3
HINT
Source
GCPC 2013
题意:给出两个点,教皇如果能走到则输出走法,否则输出Impossible
思路:分类讨论,我们可以得出,只有0,1,2三种情况
0,1,不难推出
而2的话,证明两个点不在同一斜线上
那么有两个方程
x+y = a
y-x = b
可以得到两直线相交的点
x = (a+b)/2
y = (a-b)/2
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;char str[4][2];
int a[4],c[4];int main()
{int n,i;scanf("%d",&n);while(n--){for(i = 0; i<4; i++)scanf("%s",str[i]);c[0] = str[0][0]-'A';c[1] = str[1][0]-'1';c[2] = str[2][0]-'A';c[3] = str[3][0]-'1';a[0] = c[0]+c[1];a[1] = c[0]-c[1];a[2] = c[2]+c[3];a[3] = c[2]-c[3];if((a[0]) % 2 != (a[2]) % 2)printf("Impossible\n");else if(c[0] == c[2] && c[1] == c[3])printf("0 %c %c\n", c[0] + 'A', c[1] + '1');else if(a[0] == a[2] || a[1] == a[3])printf("1 %c %c %c %c\n", c[0] + 'A', c[1] + '1', c[2] + 'A', c[3] + '1');else if(a[0] + a[3] >= 0 && a[0] + a[3] < 16 && a[0] - a[3] >= 0 && a[0] - a[3] < 16)printf("2 %c %c %c %c %c %c\n", c[0] + 'A', c[1] + '1', (a[0] + a[3])/2 + 'A', (a[0] - a[3])/2 + '1', c[2] + 'A', c[3] + '1');elseprintf("2 %c %c %c %c %c %c\n", c[0] + 'A', c[1] + '1', (a[1] + a[2])/2 + 'A', (a[2] - a[1])/2 + '1', c[2] + 'A', c[3] + '1');}return 0;
}
CSU1459:Chess相关推荐
- HDU 6114 Chess 【组合数】(2017百度之星程序设计大赛 - 初赛(B))
Chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- hdu-5794 A Simple Chess(容斥+lucas+dp)
题目链接: A Simple Chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- Codeforces 38B - Chess
38B - Chess 思路:懂点象棋的规则就可以,看看哪些点可以放马. 代码: #include<bits/stdc++.h> using namespace std; #define ...
- BZOJ1801: [Ahoi2009]chess 中国象棋
BZOJ1801: [Ahoi2009]chess 中国象棋 Description 在N行M列的棋盘上,放若干个炮可以是0个,使得没有任何一个炮可以攻击另一个炮. 请问有多少种放置方法,中国像棋中炮 ...
- HDU 4832 Chess 排列组合 DP
Chess Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- Aeroplane chess HDU - 4405(期望dp)
题意: 飞行棋.有n+1格,开始时在0号格子,每一步都要扔一个dice(六个面,概率相同)哪一面朝上他就会向前走x+i步.当x+i大于等于N的时候,游戏结束.另外,地图上有m条航线.第i条航线可以直接 ...
- Codeforces Round #732 (Div. 2) D. AquaMoon and Chess 组合数学 + 找规律
传送门 文章目录 题意: 思路: 题意: 给你一个010101串,当且仅当某个111的某一边i+1,i−1i+1,i-1i+1,i−1有111,这个111可以跟i+2,i−2i+2,i-2i+2,i− ...
- 数论五之容斥——硬币购物,Gerald and Giant Chess,幸运数字,Sky Full of Stars,已经没有什么好害怕的了
容斥的神 [HAOI2008]硬币购物 problem solution code CF559C Gerald and Giant Chess problem solution code [SCOI2 ...
- HDU5794 - A Simple Chess
HDU5794 - A Simple Chess 做法:首先的想法就是用总方案数减去,经过过障碍的方案数A.第一个思路就是容斥,但是显然不符合数据规模.另一个思路就是将障碍物从左上到右下排序,dp[i ...
最新文章
- 【连载】优秀程序员的45个习惯之39——架构师必须写代码
- Apache ServiceComb — Overview
- 前端基础知识整理汇总(上)
- linux之cp/scp命令+scp命令详解
- Flask--SQLAlchemy
- java中注解的解析_全面解析Java中的注解与注释
- python中的数学模块
- Dev TextEdit 输入提示
- caffe:制作自己的数据集train.txt和val.txt,生成lmdb文件
- python svm向量_支持向量机(SVM)及其Python实现
- 黑马vue实战项目-(四)商品分类页面的开发
- 如何在Java项目中定义并调用自己编写的native方法?
- 我要注册一个邮箱,如何注册邮箱正确格式?
- license.xml
- SPSS(十五)spss之聚类分析(图文+数据集)
- nRF52283开发板 基于ble_peripheral\ble_app_blinky_c (LED Button Service Client) 针对服务端的新增LED1子服务
- python winrar 密码_python+winrar 指令压缩文件
- Time-Series Representation Learning via Temporal and Contextual Contrasting
- PS将一张图片裁剪/划分为多块
- pygame-KidsCanCode系列jumpy-part5-屏幕滚动