zoukankan      html  css  js  c++  java
  • 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 (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的话
    可以看下面我画的这张图

    唉我画图真的画的太好了哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈(无限得意中
    下面放代码
     1 #include<stdio.h>
     2 #include<iostream>
     3 #include<math.h>
     4 #include<algorithm>
     5 #include<string.h>
     6 #include<limits.h>
     7 using namespace std;
     8 int a(int x)
     9 {
    10     return x*x;
    11 }
    12 int main()
    13 {
    14     int lx,ly,lz,x,y,z;
    15     int res;
    16     while(cin>>lx>>ly>>lz>>x>>y>>z)
    17     {
    18         if(lx==0&&ly==0&&lz==0&&x==0&&y==0&&z==0)
    19             break;
    20         res=INT_MAX;
    21         if(x==0||y==0||z==0)//相邻面上 
    22             res=x*x+y*y+z*z;
    23         else if(z==lz)//上面
    24         {
    25             res=min(min(a(x)+a(lz+y),a(y)+a(lz+x)),res);
    26             res=min(res,min(a(y+lx)+a(lx+lz-x),a(x+ly)+a(ly+lz-y)));
    27         }
    28         else if(y==ly)//后面
    29         {
    30             res=min(min(a(x)+a(z+ly),a(z)+a(ly+x)),res);
    31             res=min(res,min(a(x+lz)+a(ly+lz-z),a(z+lx)+a(ly+lx-x)));
    32         }
    33         else if(x==lx)//右面
    34         {
    35             res=min(min(a(z)+a(lx+y),a(y)+a(z+lx)),res);
    36             res=min(res,min(a(lz+y)+a(lx+lz-z),a(z+ly)+a(ly+lx-y)));
    37         }
    38         cout<<res<<endl;
    39     }
    40     return 0;
    41 }
  • 相关阅读:
    (二)juc线程高级特性——CountDownLatch / Callable / Lock
    (一)juc线程高级特性——volatile / CAS算法 / ConcurrentHashMap
    配置tomcat的session共享
    elastic不错的官方文档(中文)
    elasticsearch java客户端api使用(一)
    Tomcat 没有自动解压webapp下的war项目文件问题
    Spring+Quartz实现定时任务
    注意的问题
    JMS之——ActiveMQ 高可用与负载均衡集群安装、配置(ZooKeeper + LevelDB + Static discovery)
    activemq持久化配置,设置为主从模式(带复制的主从模式,应用mysql数据库)
  • 原文地址:https://www.cnblogs.com/Annetree/p/5677746.html
Copyright © 2011-2022 走看看