csuoj 1511: 残缺的棋盘
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1511
1511: 残缺的棋盘
时间限制: 1 Sec 内存限制: 128 MB
题目描述

输入
输入包含不超过10000 组数据。每组数据包含6个整数r1, c1, r2, c2, r3, c3 (1<=r1, c1, r2, c2, r3, c3<=8). 三个格子A, B, C保证各不相同。
输出
对于每组数据,输出测试点编号和最少步数。
样例输入
1 1 8 7 5 6
1 1 3 3 2 2
样例输出
Case 1: 7
Case 2: 3
提示
来源
分析:
8 x 8 的棋盘,BFS搜索可以解决,一开始队友写错了条件导致TLE , 后来又写了一个笛卡尔坐标模拟的,但是pc^2判错啦 , 后来在csuoj上提交也是错的,对照数据没有发现错误,真是无语啦,把其他队的AC代码提交到csuoj上也是WA,真是服了,但是搜索做的都过啦,,,orz
AC代码:
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<string.h>
#define ll long long
#define oo 1000007
#define pi acos(-1.0)
#define MAXN 500005
using namespace std;
struct node
{
int x,y,k;
}h,p;
int m,n,k,ex,ey,num[][][];
bool used[][][];
queue<node> myqueue;
int main()
{
while (~scanf("%d%d%d%d%d%d%d",&n,&m,&h.x,&h.y,&ex,&ey,&k))
{
while (!myqueue.empty()) myqueue.pop();
h.k=;
myqueue.push(h);
memset(num,,sizeof(num));
memset(used,false,sizeof(used));
used[h.y][h.x][]=true;
num[h.y][h.x][]=;
while (!myqueue.empty())
{
h=myqueue.front();
myqueue.pop();
if (h.k==k) continue;
if (h.y+<=m)
{
p.x=h.x,p.y=h.y+,p.k=h.k+;
if (!used[p.y][p.x][p.k]) myqueue.push(p),used[p.y][p.x][p.k]=true;
num[p.y][p.x][p.k]=(num[p.y][p.x][p.k]+num[h.y][h.x][h.k])%oo;
}
if (h.x->=)
{
p.x=h.x-,p.y=h.y,p.k=h.k+;
if (!used[p.y][p.x][p.k]) myqueue.push(p),used[p.y][p.x][p.k]=true;
num[p.y][p.x][p.k]=(num[p.y][p.x][p.k]+num[h.y][h.x][h.k])%oo;
}
if (h.x+<=n)
{
p.x=h.x+,p.y=h.y,p.k=h.k+;
if (!used[p.y][p.x][p.k]) myqueue.push(p),used[p.y][p.x][p.k]=true;
num[p.y][p.x][p.k]=(num[p.y][p.x][p.k]+num[h.y][h.x][h.k])%oo;
}
}
printf("%d\n",num[ey][ex][k]);
}
return ;
}
数组模拟:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<iostream>
#include<stack>
#include<map>
#include <math.h>
#include<string> using namespace std; double area(double x1 , double y1 , double x2 , double y2 , double x3 , double y3)
{return x1 * y2 + x3 * y1 + x2 * y3 - x3 * y2 - x1 * y3 - x2 * y1 ;} int main()
{
//freopen("i.in" , "r" , stdin);
//freopen("o.out" , "w" , stdout);
int x1 , x2 , x3 , y1 , y2 , y3 , first = ;
while(~scanf("%d %d %d %d %d %d" , &x1 ,&y1 , &x2 , &y2 , &x3 , &y3))
if(!area(x1 , y1 , x2 , y2 , x3 , y3) && !( ((x1 == x2) && (x2 == x3) && (x1 == x3)) || (y1 == y2 && y1 == y3 && y2 == y3))
&& ( (x3 > x1 && x3 < x2) || (x3 > x2 && x3 < x1)) )
printf("Case %d: %.0lf\n" , first ++ , max(fabs(x1 - x2) , fabs(y1 - y2)) + ) ;
else
printf("Case %d: %.0lf\n" , first ++ , max(fabs(x1 - x2) , fabs(y1 - y2)) ) ;
return ;
}
其他队的:
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std; int main()
{
int x1, y1, x2, y2, x3, y3, cnt = ;
while(scanf("%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &x3, &y3) != EOF)
{
int res = abs(x2 - x1) > abs(y2 - y1) ? abs(x2 - x1) : abs(y2 - y1); if((x3 >= x1 && x3 <= x2) || (x3 <= x1 && x3 >= x2))
{
if((y1 - x1 == y2 -x2 && y1 - x1 == y3 - x3) ||(x1 + y1 == x2 + y2 && x1 + y1 == x3 + y3) || (x1 == x2 && x1 == x3) || (y1 == y2 && y1 == y3)) res++;
}
printf("Case %d: %d\n", ++cnt, res);
}
}
官方标程:
// Rujia Liu
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std; #define dist(a,b) (max(abs(r[a]-r[b]),abs(c[a]-c[b]))) int main() {
int r[], c[], kase = ;
while(cin>>r[]>>c[]>>r[]>>c[]>>r[]>>c[]) {
int dr = abs(r[]-r[]);
int dc = abs(c[]-c[]);
int d = max(dr, dc);
if(dr == dc && dist(,) == dist(,) + dist(,)) d++;
printf("Case %d: %d\n", ++kase, d);
}
return ;
}
csuoj 1511: 残缺的棋盘的更多相关文章
- CSU 1511 残缺的棋盘 第十届湖南省赛题
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1511 题目大意:在一个8*8的棋盘中,给你一个起点位置和一个终点位置,同时也给你一个陷阱 ...
- TYVJ1035 棋盘覆盖
时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 给出一张n*n(n<=100)的国际象棋棋盘,其中被删除了一些点,问可以使用多少1*2的多米诺骨牌进行掩 ...
- POJ 1321 棋盘问题(dfs)
传送门 棋盘问题 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 38297 Accepted: 18761 Descri ...
- 设计一个自动生成棋盘格子的JS小程序
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- BZOJ1057[ZJOI2007]棋盘制作 [单调栈]
题目描述 国际象棋是世界上最古老的博弈游戏之一,和中国的围棋.象棋以及日本的将棋同享盛名.据说国际象棋起源于易经的思想,棋盘是一个8*8大小的黑白相间的方阵,对应八八六十四卦,黑白对应阴阳. 而我们的 ...
- 【BZOJ-3039&1057】玉蟾宫&棋盘制作 悬线法
3039: 玉蟾宫 Time Limit: 2 Sec Memory Limit: 128 MBSubmit: 753 Solved: 444[Submit][Status][Discuss] D ...
- 【ZJOI2007】棋盘制作 BZOJ1057
Description 国 际象棋是世界上最古老的博弈游戏之一,和中国的围棋.象棋以及日本的将棋同享盛名.据说国际象棋起源于易经的思想,棋盘是一个8*8大小的黑白相间的方 阵,对应八八六十四卦,黑白对 ...
- Unity手撸2048小游戏——自动生成4*4棋盘
1.新建文件夹,命prefabs,将刚刚做成的Chessman拖入该文件下,做成预制体 2.删除panel下的Chessman 3.在panel下,新建一个空对象,命名为Chessboard,大小设置 ...
- CentOS 7.2.1511编译安装Nginx1.10.1+MySQL5.7.14+PHP7.0.11
准备篇 一.防火墙配置 CentOS 7.x默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop firewalld.se ...
随机推荐
- Linux 下找出超過某些容量的檔案
找目前所在位置下,所有檔案大小超過3M的file,並列出檔名:大小 find . -type f -size +3M -exec ls -alh {} \; | awk '{print$9 " ...
- Red KV数据 庫设計模式
转:http://blog.nosqlfan.com/html/3033.html NoSQL带给我们的东西很多,高性能,水平扩展性,还有不一样的思维方式.本文来自@hoterran的个人博客运维与开 ...
- Hibernate中主键生成策略
主键生成策略 increment identity sequence native uuid assigned 1) increment 由hibernate完成 主键递增, 原理:select ma ...
- mac终端命令大全全全全全全全全全
OSX 的文件系统 OSX 采用的Unix文件系统,所有文件都挂在跟目录 / 下面,所以不在要有Windows 下的盘符概念. 你在桌面上看到的硬盘都挂在 /Volumes 下. 比如接上个叫做 US ...
- jQuery获取cookie
之前一直以为获取cookie的方法封装在了jQuery包中...没想到还得单独下jquery.cookie.js插件,不太好找,备份一份: /*! * jQuery Cookie Plugin v1. ...
- 测试的程序 test.php,保存放IIS的根目录下
IIS+PHP的配置的方法,试过之后很多都不能达到效果.于是总结了大部分的文章后就得出了这样的方法 一.下载必须的程序:(1) 先到PHP的官方网站下载一个PHP(本文就以PHP 4.4.2为例).网 ...
- Exception在方法继承中的限制
问题: 父类或接口中定义了方法应该抛出的异常,那么当子类重写方法时应该怎样定义将要抛出的异常: 首先定义异常和父类: class Exception1 extends Exception {} cla ...
- Linux学习笔记---用户管理---组group
组管理: (1)/etc/group 格式: 组名:密码:GID:组员
- Windows内核 WDM驱动程序的基本结构和实例
WDM驱动的基本结构: WDM驱动模型是建立在NT式驱动程序模型基础之上的.对于WDM驱动程序来说,一般都是基于分层的,即完成一个设备的操作,至少要由两个驱动设备共同完成. 1)物理设备对象和功能设备 ...
- (一)jvm
jvm,作为java平台通用性的实现基础,重要性不言而喻. 1.开发新项目,写运行脚本时要运用相关知识,确定jvm参数 2.维护老项目,需要对jvm进行性能调优 jvm内存划分: 1.程序计数器 2. ...