POJ 2977 Box walking 长方体表面两点距离
POJ2977 小学生的考试题,暴力得出O(1)的解法
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std; int ans;
void turn(int i,int j,int x,int y,int z,int x0,int y0,int L,int W,int H)
{
if(z==0)ans=min(ans,(x-x0)*(x-x0)+(y-y0)*(y-y0));
else
{
if(i>=0&&i<2)
turn(i+1,j,H-z,y,x,x0+H,y0,H,W,L);
if(j>=0&&j<2)
turn(i,j+1,x,H-z,y,x0,y0+H,L,H,W);
if(i<=0&&i>-2)
turn(i-1,j,z,y,L-x,x0-L,y0,H,W,L);
if(j<=0&&j>-2)
turn(i,j-1,x,z,W-y,x0,y0-W,L,H,W);
}
} int rect_dist(int L,int W,int H,int x1,int y1,int z1,int x2,int y2,int z2)
{
if(z1!=0&&z1!=H)
if(y1==0||y1==W)
swap(y1,z1),swap(y2,z2),swap(W,H);
else
swap(x1,z1),swap(x2,z2),swap(L,H);
if(z1==H)
z1=0,z2=H-z2;
ans=1<<30;
turn(0,0,x2,y2,z2,x1,y1,L,W,H);
return ans;
} int main()
{//freopen("t.txt","r",stdin);
int L,W,H,x,y,z;
while(scanf("%d%d%d%d%d%d",&L,&W,&H,&x,&y,&z))
{
if(L==0&&W==0&&H==0&&x==0&&y==0&&z==0)return 0;
printf("%d\n",rect_dist(L,W,H,0,0,0,x,y,z));
}
return 0;
}
POJ 2977 Box walking 长方体表面两点距离的更多相关文章
- POJ 2977 Box walking
题目链接:http://poj.org/problem?id=2977 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 222 ...
- 计算两点距离 ios
//计算两点距离 -(float)distanceBetweenTwoPoint:(CGPoint)point1 point2:(CGPoint)point2 { ) + powf(point1.y ...
- 【百度地图API】如何根据摩卡托坐标进行POI查询,和计算两点距离
原文:[百度地图API]如何根据摩卡托坐标进行POI查询,和计算两点距离 摘要: 百度地图API有两种坐标系,一种是百度经纬度,一种是摩卡托坐标系.在本章你将学会: 1.如何相互转换这两种坐标: 2. ...
- 高德地图测两点距离android比较精确的
/////参考资料:高德官方:[http://lbs.amap.com/api/android-location-sdk/guide/android-location/getlocation] 主要三 ...
- HDU 5723 Abandoned country(kruskal+dp树上任意两点距离和)
Problem DescriptionAn abandoned country has n(n≤100000) villages which are numbered from 1 to n. Sin ...
- 模板倍增LCA 求树上两点距离 hdu2586
http://acm.hdu.edu.cn/showproblem.php?pid=2586 课上给的ppt里的模板是错的,wa了一下午orz.最近总是被坑啊... 题解:树上两点距离转化为到根的距离 ...
- hdu6446 网络赛 Tree and Permutation(树形dp求任意两点距离之和)题解
题意:有一棵n个点的树,点之间用无向边相连.现把这棵树对应一个序列,这个序列任意两点的距离为这两点在树上的距离,显然,这样的序列有n!个,加入这是第i个序列,那么这个序列所提供的贡献值为:第一个点到其 ...
- js根据经纬度计算两点距离
js版-胡老师 google.maps.LatLng.prototype.distanceFrom = function(latlng) { var lat = [this.lat(), lat ...
- HDU_5723_最小生成树+任意两点距离的期望
Abandoned country Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
随机推荐
- Linux学习笔记(一) 文件系统
对于每一个 Linux 学习者来说,了解 Linux 文件系统的结构是十分有必要的 因为在 Linux 中一切皆文件,可以说只有深入了解 Linux 的文件系统,才会对 Linux 有更深刻的理解 L ...
- MapReduce架构与执行流程
一.MapReduce是用于解决什么问题的? 每一种技术的出现都是用来解决实际问题的,否则必将是昙花一现,那么MapReduce是用来解决什么实际的业务呢? 首先来看一下MapReduce官方定义: ...
- 当java web项目部署到服务器上时,无法将图片等媒体文件保存到服务器的最终奥义
今天,我在部署web项目至云服务器上(Tomcat8.0)时,突然发现我的应用,无法上传图片,视频等多媒体文件了,一再检查自己的代码逻辑没有问题之后,逐一排查,首先想到的就是看一下控制台打印的日志,日 ...
- table JS合并单元格
function _w_table_rowspan(_w_table_id,_w_table_colnum){ _w_table_firsttd = ""; _w_table_cu ...
- LeetCode(50) Pow(x,n)
题目 Implement pow(x, n). Show Tags Show Similar Problems 分析 一个不利用标准幂次函数的,求幂算法实现. 参考了一个很好的解析博客:Pow(x,n ...
- node.js 读取文件--createReadStream
createReadStream 是fs模块里面读流的一个方法 这个方法基于fs模块的,所以我们先要引进fs模块 let fs=require("fs"); createReadS ...
- struts2开发action 的三种方法以及通配符、路径匹配原则、常量
struts2开发action 的三种方法 1.继承ActionSupport public class UserAction extends ActionSupport { // Action中业务 ...
- PatentTips - Universal RAID Class Driver
BACKGROUND OF THE INVENTION The present invention relates to the field of data storage devices. Comp ...
- [bzoj2463][中山市选2009]谁能赢呢?_博弈论
博弈论 bzoj-2463 中山市选-2009 题目大意:题目链接. 注释:略. 想法: 如果$n$是偶数的话就可以被多米诺骨牌恰好覆盖,这样的话只需要先手先走向(1,1)对应的第二段,后者必定会将棋 ...
- Swap Nodes in Pairs(链表操作)
Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2-&g ...