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 }
  • 相关阅读:
    设计模式-策略模式
    .NET操作RabbitMQ组件EasyNetQ使用中文简版文档。
    LayIM项目之基础数据获取代码优化,Dapper取代ADO.NET
    干货!手把手教你如何使用第三方通讯服务实现LayIM Socket组件开发。
    几句代码简单实现IoC容器
    .NET Core On Mac 第一步,配置环境
    Func<T,T>应用之Elasticsearch查询语句构造器的开发
    四个人17分钟过桥的问题
    ElasticSearch中的简单查询
    ASP.NET SignalR 与 LayIM2.0 配合轻松实现Web聊天室(十四)之漏掉的客服消息
  • 原文地址:https://www.cnblogs.com/Annetree/p/5677746.html
Copyright © 2011-2022 走看看