POJ 2977 Box walking
题目链接:http://poj.org/problem?id=2977
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 2229 | Accepted: 598 |
Description
You are given a three-dimensional box of integral dimensions lx × ly × lz The edges of the box are axis-aligned, and one corner of the box is located at position (0, 0, 0). Given the coordinates (x, y, z) of some arbitrary position on the surface of the box, your goal is to return the square of the length of the shortest path along the box’s surface from (0, 0, 0) to (x, y, z).
If lx = 1, ly = 2, and lz = 1, then the shortest path from (0, 0, 0) to (1, 2, 1) is found by walking from (0, 0, 0) to (1, 1, 0), followed by walking from (1, 1, 0) to (1, 2, 1). The total path length is √8.
Input
The input test file will contain multiple test cases, each of which consists of six integers lx, ly, lz, x, y, z where 1 ≤ lx, ly, lz ≤ 1000. Note that the box may have zero volume, but the point (x, y, z) is always guaranteed to be on one of the six sides of the box. The end-of-file is marked by a test case with lx = ly = lz = x = y = z = 0 and should not be processed.
Output
For each test case, write a single line with a positive integer indicating the square of the shortest path length. (Note: The square of the path length is always an integer; thus, your answer is exact, not approximate.)
Sample Input
1 1 2 1 1 2
1 1 1 1 1 1
0 0 0 0 0 0
Sample Output
8
5 如果你觉得这是一道很简单的题然后你WA的话
可以看下面我画的这张图

唉我画图真的画的太好了哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈(无限得意中
下面放代码
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<limits.h>
using namespace std;
int a(int x)
{
return x*x;
}
int main()
{
int lx,ly,lz,x,y,z;
int res;
while(cin>>lx>>ly>>lz>>x>>y>>z)
{
if(lx==&&ly==&&lz==&&x==&&y==&&z==)
break;
res=INT_MAX;
if(x==||y==||z==)//相邻面上
res=x*x+y*y+z*z;
else if(z==lz)//上面
{
res=min(min(a(x)+a(lz+y),a(y)+a(lz+x)),res);
res=min(res,min(a(y+lx)+a(lx+lz-x),a(x+ly)+a(ly+lz-y)));
}
else if(y==ly)//后面
{
res=min(min(a(x)+a(z+ly),a(z)+a(ly+x)),res);
res=min(res,min(a(x+lz)+a(ly+lz-z),a(z+lx)+a(ly+lx-x)));
}
else if(x==lx)//右面
{
res=min(min(a(z)+a(lx+y),a(y)+a(z+lx)),res);
res=min(res,min(a(lz+y)+a(lx+lz-z),a(z+ly)+a(ly+lx-y)));
}
cout<<res<<endl;
}
return ;
}
POJ 2977 Box walking的更多相关文章
- POJ 2977 Box walking 长方体表面两点距离
POJ2977 小学生的考试题,暴力得出O(1)的解法 #include<iostream> #include<cstdio> #include<cstdlib> ...
- 【POJ 3162】 Walking Race (树形DP-求树上最长路径问题,+单调队列)
Walking Race Description flymouse's sister wc is very capable at sports and her favorite event is ...
- POJ 1477:Box of Bricks
Box of Bricks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19949 Accepted: 8029 De ...
- POJ 2110 Mountain Walking 二分+bfs
传送门 昨天看到这个题还以为是个脑残的dp, 然而脑残的是我. 题目意思就是从左上角走到右下角, 设x为路径上的最大值-最小值, 求x的最小值. 二分x, 对于每一个x, 枚举下界lower, low ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- Poj 1006 / OpenJudge 2977 1006 Biorhythms/生理周期
1.链接地址: http://poj.org/problem?id=1006 http://bailian.openjudge.cn/practice/2977 2.题目: Biorhythms Ti ...
- POJ 2152 fire / SCU 2977 fire(树型动态规划)
POJ 2152 fire / SCU 2977 fire(树型动态规划) Description Country Z has N cities, which are numbered from 1 ...
- POJ 3162.Walking Race 树形dp 树的直径
Walking Race Time Limit: 10000MS Memory Limit: 131072K Total Submissions: 4123 Accepted: 1029 Ca ...
- POJ 1442 Black Box treap求区间第k大
题目来源:POJ 1442 Black Box 题意:输入xi 输出前xi个数的第i大的数 思路:试了下自己的treap模版 #include <cstdio> #include < ...
随机推荐
- 简述java程序中的main方法
简述main方法: 在java语言程序编写时都会涉及到一个main方法,它的格式为: public static void main(String[] args)(一般必须这么定义,这是java规范) ...
- Angularjs中的嵌套路由ui-router
先看看ng-router和ui-router的区别 (1)ng-route的局限性:一个页面无法嵌套多个视图,也就是说一个页面只能有包含一个页面一个控制器的切换. (2)ui-route的改进:在具 ...
- 一些常用的操作MySQL数据库的sql语句
创建数据库:create database 数据库名; 删除数据库:drop datebase 数据库名; 查看数据库:show databases;(所有数据库) 使用数据库:use 数据库名;(之 ...
- CountDownLatch使用详解
正如每个Java文档所描述的那样,CountDownLatch是一个同步工具类,它允许一个或多个线程一直等待,直到其他线程的操作执行完后再执行.在Java并发中,countdownlatch的概念是一 ...
- bat脚本-set(setlocal enabledelayedexpansion) 学习
设置本地为延迟扩展.其实也就是:延迟变量,全称延迟环境变量扩展. 事件一: @echo off set a=4 set a=5&echo %a% pause 解说:为什么是4而不是5呢?在ec ...
- js两种生成对象模式(公有成员和成员私有)
假设有个需求,创建一个book类,有isbn码,书名,作者 :可以对isbn进行数据完整性校验:--js设计模式 <script type="text/javascript" ...
- 解决vs2013下创建的python文件,到其他平台(如linux)下中文乱码(或运行时报SyntaxError: (unicode error) 'utf-8' codec can't decode byte...)
Vs2013中创建python文件,在文件中没输入中文时,编码为utf-8的,如图 接着,在里面输入几行中文后,再次用notepad++查看其编码如下,在vs下运行也报错(用cmd运行就不会): 根据 ...
- WPF中自定义绘制内容
先说结论:实现了在自定义大小的窗口中,加载图片,并在图片上绘制一个矩形框:且在窗口大小改变的情况,保持绘制的矩形框与图片的先对位置不变. 在WinForm中,我们可以很方便地绘制自己需要的内容,在WP ...
- CF Round #355 Div.2
http://codeforces.com/contest/677 B. Vanya and Food Processor 题意:有一个食物加工器,每次能加工不超过h高度的土豆,且每秒加工至多k高度的 ...
- linux(x64)下安装Matlab 2015b破解版(含安装包)
注意:在安装前请查看安装目录是否有足够空间!完全安装大概需要12G的空间!本人在安装后系统盘满了,导致无法启动图形界面.小伙伴们不要重蹈覆辙~ Environment Linux debian8 (x ...