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 ...
 
随机推荐
- Android -- ListView(SimpleAdapter) 自定义适配器
			
aaarticlea/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBA ...
 - iOS应用内付费(IAP)开发步骤列表
			
iOS应用内付费(IAP)开发步骤列表 前两天和服务端同事一起,完成了应用内付费(以下简称IAP, In app purchase)的开发工作.步骤繁多,在此把开发步骤列表整理如下.因为只是步骤列表, ...
 - 基于canvas的前端图片压缩
			
/*common*/ /** * canvas图片压缩 * @param {[Object]} opt [配置参数] * @param {[Function]} cbk [回调函数] * @retur ...
 - 在mapreduce中做分布式缓存的问题
			
一.问题描述: 主要解决一个问题,就是两个表做join,两个表都够大,单个表都无法装入内存. 怎么做呢?思路就是对做join的字段做排序两个表都排序,然后针对一个表a逐行读取,希望能够在内存中加载到另 ...
 - HTML--JS练习小游戏(别踩白块儿)
			
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
 - Winform程序以Icon的形式显示在任务栏右下角
			
Form最小化是指整个Form都缩小到任务栏上,但是是以Form的标题栏形式显示的, 若是想让Form以Icon的形式显示在任务栏右下角,则需要给Form添加一个NotifyIcon控件, 在使窗体最 ...
 - SQL server 链接查询
			
一.链接查询 1.join on 左右链接 2.左右查询 left right 3.union 上下链接
 - rdp爆破工具 Fast RDP Brute
			
http://stascorp.com/load/1-1-0-58 Fast RDP Brute dservers.ru/wp-content/uploads/2013/11/frdpb2.zip
 - asl 和 lgpl的区别
			
按照使用条件的不同,开源软件许可证可以分为三类(严苛程度递减) 1. 使用该开源软件的代码再散布(redistribute)时,源码也必须以相同许可证公开. 代表许可类型:GPL, AGPL 2. 使 ...
 - log4j日志输出级别高低
			
Log4j是Apache的开源项目一个功能强大的日志组件,提供方便的日志记录.日志记录器(Logger)是日志处理的核心组件Log4j建议只使用四个级别,优先级从高到低分别是FATAL, ERROR. ...