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: 残缺的棋盘的更多相关文章

  1. CSU 1511 残缺的棋盘 第十届湖南省赛题

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1511 题目大意:在一个8*8的棋盘中,给你一个起点位置和一个终点位置,同时也给你一个陷阱 ...

  2. TYVJ1035 棋盘覆盖

    时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 给出一张n*n(n<=100)的国际象棋棋盘,其中被删除了一些点,问可以使用多少1*2的多米诺骨牌进行掩 ...

  3. POJ 1321 棋盘问题(dfs)

    传送门 棋盘问题 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 38297   Accepted: 18761 Descri ...

  4. 设计一个自动生成棋盘格子的JS小程序

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  5. BZOJ1057[ZJOI2007]棋盘制作 [单调栈]

    题目描述 国际象棋是世界上最古老的博弈游戏之一,和中国的围棋.象棋以及日本的将棋同享盛名.据说国际象棋起源于易经的思想,棋盘是一个8*8大小的黑白相间的方阵,对应八八六十四卦,黑白对应阴阳. 而我们的 ...

  6. 【BZOJ-3039&1057】玉蟾宫&棋盘制作 悬线法

    3039: 玉蟾宫 Time Limit: 2 Sec  Memory Limit: 128 MBSubmit: 753  Solved: 444[Submit][Status][Discuss] D ...

  7. 【ZJOI2007】棋盘制作 BZOJ1057

    Description 国 际象棋是世界上最古老的博弈游戏之一,和中国的围棋.象棋以及日本的将棋同享盛名.据说国际象棋起源于易经的思想,棋盘是一个8*8大小的黑白相间的方 阵,对应八八六十四卦,黑白对 ...

  8. Unity手撸2048小游戏——自动生成4*4棋盘

    1.新建文件夹,命prefabs,将刚刚做成的Chessman拖入该文件下,做成预制体 2.删除panel下的Chessman 3.在panel下,新建一个空对象,命名为Chessboard,大小设置 ...

  9. CentOS 7.2.1511编译安装Nginx1.10.1+MySQL5.7.14+PHP7.0.11

    准备篇 一.防火墙配置 CentOS 7.x默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop firewalld.se ...

随机推荐

  1. 【BZOJ2049】 [Sdoi2008]Cave 洞穴勘测 LCT/并查集

    两种方法: 1.LCT 第一次LCT,只有link-cut和询问,无限T,到COGS上找了数据,发现splay里的父亲特判出错了(MD纸张),A了,好奇的删了反转T了.... #include < ...

  2. Oracle数据库合并行记录,WMSYS.WM_CONCAT 函數的用法

    Sql代码 select t.rank, t.Name from t_menu_item t; 10 CLARK    10 KING    10 MILLER    20 ADAMS    20 F ...

  3. About_AJAX_02

    学习AJAX基础: 首先要:掌握AJAX技术.掌握AJAX开发步骤.掌握采用AJAX进行实例开发 AJAX应用到的技术: AJAX(Asynchronous JavaScript And XML)涉及 ...

  4. 关于 微软必应词典客户端(pc) 的案例分析

    第一部分 调研,评测 ●评测 bug one 在词典界面中搜完单词后,将鼠标移到英文例句上的单词时,会显示对应的中文翻译,而当移到短语时则不对应中文翻译. bug two 用orc强力取词,查询如上图 ...

  5. Linux_几个常用的命令

    一.基本命令 查看当前路径:pwd 切换文件夹:cd 查看当前用户: who/whoami 取文件前3行:head -3 文件 取文件尾3行:tail -3 文件 切换用户: su - [用户名] 查 ...

  6. HDU3177 贪心

    Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  7. 解析私有IP地址和公网IP地址

    局域网私有IP地址上外网的原理 IP地址分为两部分,网络号和主机号,这种分法应用在私有和公有IP地址上.一个局域网中,为了该局域网的安全,我们应用了私有IP地址,为了和Internet中的其他主机进行 ...

  8. Mysql的一些常用命令

    Mysql基本操作 创建表: create table test01_02(id varchar(50) not null auto_increment primary key, name nvarc ...

  9. Lua语言

    下载使用Subline作为编辑器 1. 2.函数使用 function sayHello() print ('hello torch') end 3.定义变量 a print (a) 4.引入文件 r ...

  10. Android课程---Android Studio安装及使用

    2013年Google I/O 大会首次发布了Android Studio IDE(Android平台集成开发环境).它基于Intellij IDEA 开发环境,旨在取代Eclipse和ADT(And ...