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. 期望dp BZOJ3450+BZOJ4318

    BZOJ3450 概率期望DP f[i]表示到i的期望得分,g[i]表示到i的期望长度. 分三种情况转移: ① s[i]=‘x’:f[i]=f[i-1],g[i]=0 ② s[i]=‘o’:f[i]= ...

  2. hbases索引技术:Lily HBase Indexer介绍

    Lily HBase Indexer 为hbase提供快速查询,他允许不写代码,快速容易的把hbase行索引到solr.Lily HBase Indexer drives HBase indexing ...

  3. hdu1241 dfs

    链接改天再补 杭电又崩了... 题意:求“@”组成了多少个联通区域,每个点的8个方向都认为是相连的 思路:对每一个点进行搜索 当Map == @ && vis == 0 时 可进入搜索 ...

  4. 禁止浏览器直接访问php文件

    框架中很多php文件并不是用来如果熟悉框架的路径就能直接访问这个文件,虽然访问到了也不能看到什么(他看到的是编译过后的html文件),但还是觉的很不安全. 可以通过下面这种方法拒绝他人的从浏览器中的访 ...

  5. Pl/Sql 导入dmp文件时窗口一闪而过

    做如下设置: 点击“导入”,ok

  6. 判断两个IP是否属于同一子网

    描述 子网掩码是用来判断任意两台计算机的IP地址是否属于同一子网络的根据.子网掩码与IP地址结构相同,是32位二进制数,其中网络号部分全为“1”和主机号部分全为“0”.利用子网掩码可以判断两台主机是否 ...

  7. 关于Response.redirect()方法

    1. sendRedirect 后面要加上return.2. sendRedirect 执行过程是先转向还是先执行后续代码再转向?答: 先执行代码再转向,在一个sendRedirect后面不能再有其他 ...

  8. VS 调试

    Vs 单步调试 在vs中的单步调试: 调试重要的几个键: F9在当前光标所在的行下断点,如果当前行已经有断点,则取消断点. F5调试状态运行程序,程序执行到有断点的地方会停下来. F10单步执行程序. ...

  9. IOS第八天(7:UITableViewController新浪微博,cell 复用的简单写法优化和cell高度从模型中获取)

    *********** #import "HMViewController.h" #import "HMStatus.h" #import "HMSt ...

  10. SaveData Functions

    Here are some save function for some situations: Yes/No /// <summary> ///保存数据到WCF /// </sum ...