题目链接: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 (xyz) 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 (xyz).

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 lxlylzxyz where 1 ≤ lxlylz ≤ 1000. Note that the box may have zero volume, but the point (xyz) 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的更多相关文章

  1. POJ 2977 Box walking 长方体表面两点距离

    POJ2977 小学生的考试题,暴力得出O(1)的解法 #include<iostream> #include<cstdio> #include<cstdlib> ...

  2. 【POJ 3162】 Walking Race (树形DP-求树上最长路径问题,+单调队列)

    Walking Race   Description flymouse's sister wc is very capable at sports and her favorite event is ...

  3. POJ 1477:Box of Bricks

    Box of Bricks Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19949   Accepted: 8029 De ...

  4. POJ 2110 Mountain Walking 二分+bfs

    传送门 昨天看到这个题还以为是个脑残的dp, 然而脑残的是我. 题目意思就是从左上角走到右下角, 设x为路径上的最大值-最小值, 求x的最小值. 二分x, 对于每一个x, 枚举下界lower, low ...

  5. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  6. Poj 1006 / OpenJudge 2977 1006 Biorhythms/生理周期

    1.链接地址: http://poj.org/problem?id=1006 http://bailian.openjudge.cn/practice/2977 2.题目: Biorhythms Ti ...

  7. POJ 2152 fire / SCU 2977 fire(树型动态规划)

    POJ 2152 fire / SCU 2977 fire(树型动态规划) Description Country Z has N cities, which are numbered from 1 ...

  8. POJ 3162.Walking Race 树形dp 树的直径

    Walking Race Time Limit: 10000MS   Memory Limit: 131072K Total Submissions: 4123   Accepted: 1029 Ca ...

  9. POJ 1442 Black Box treap求区间第k大

    题目来源:POJ 1442 Black Box 题意:输入xi 输出前xi个数的第i大的数 思路:试了下自己的treap模版 #include <cstdio> #include < ...

随机推荐

  1. bzoj2301: [HAOI2011]Problem b懵逼乌斯反演

    属于结果的和好求但是结果不好求的题 (轻易能得到以k的倍数为最大公约数的对数,但是不好直接求k) 所以一波反演结束 其实反演的时候完全没有反演的感觉,就是不停地恒等变形 算是懵逼乌斯反演最简单的例题 ...

  2. ESP32学习笔记(一) 环境搭建与下载

    ESP32学习笔记(一) 环境搭建与下载 作者:Nevel 博客:nevel.cnblogs.com 转载请保留出处 前几天刚入手了ESP32模块,趁着放假有时间,我们先把ESP32的编译环境搭建好 ...

  3. BTE 增强

    BTE的设计思路还是比较简单,和BADI有点类似.在标准程序中留有OPEN_FI的出口(以函数OPEN_FI_PERFORM_event id_type的形式存在),然后提供一个可配置的TABLE,可 ...

  4. 自己找到的一些比较实用比较好看的前端特效。很多是前面提供的jquery网站的

    http://www.cnblogs.com/zhangzongle/p/6034394.html webservicehttp://blog.csdn.net/wowkk/article/detai ...

  5. 上锁 - leetcode

    158. Read N Characters Given Read4 II - Call multiple times 题目: The API: int read4(char *buf) reads ...

  6. Linux的一些简单命令(四)-用户和组账户管理

    linux操作系统是一个多用户操作系统,它允许多用户同时登录到系统上并使用资源.系统会根据账户来区分每个用户的文件,进程,任务和工作环境,使得每个用户工作都不受干扰 1.保存用户信息的文件:/etc/ ...

  7. laravel 安装 Laravel 扩展包

    问题说明 我们经常要往现有的项目中添加扩展包,有时候因为文档的错误引导,如下图来自这个文档 的: composer update 这个命令在我们现在的逻辑中,可能会对项目造成巨大伤害. 因为 comp ...

  8. CodeForces 659F Polycarp and Hay

    并查集,$dfs$. 从大的数字往里加,每加一个数字合并一下连通块,判断连通块内数字个数是否够,以及k能不能被当前加入的数字整除.然后$dfs$一下构造答案. #pragma comment(link ...

  9. ecshop 后台添加新的设置

    1.ecs_shop_config 表添加新的值. 2.language/zh_cn/admin/shop_config.php 设置字段后台字段名和提示信息($_LANG['cfg_name'][' ...

  10. mx51的三个framebuffer,mxc_ipuv3_fb.c分析

    转载:http://blog.csdn.net/jack_a8/article/details/43309169 mx51支持三个framebuffer:fb0, fb1, fb2 /dev/grap ...