zoukankan      html  css  js  c++  java
  • poj2977

    题意:给定一个长方体,和长方体表面上的一个点。求该点在长方体表面上移动到长方体一个(确定的)顶点的最短距离。

    分析:陷阱就在于可能需要经过三个面,而不是两个面,如果一个点在顶面,那么可能需要经过顶面、后面和左面,也可能经过顶面、右面和前面。

    View Code
    #include <iostream>
    #include
    <cstdio>
    #include
    <cstdlib>
    #include
    <cstring>
    using namespace std;

    int main()
    {
    //freopen("t.txt", "r", stdin);
    int lx, ly, lz, x, y, z;
    while (scanf("%d%d%d%d%d%d", &lx, &ly, &lz, &x, &y, &z), lx | ly | lz | x
    | y | z)
    {
    int ans;
    if (x == 0 || y == 0 || z == 0)
    {
    printf(
    "%d\n", x * x + y * y + z * z);
    continue;
    }
    if (z == lz && y == ly && x == lx)
    {
    printf(
    "%d\n", min((y + z) * (y + z) + x * x, min((x + z) * (x + z)
    + y * y, (y + x) * (y + x) + z * z)));
    continue;
    }
    if (z == lz)
    {
    ans
    = min((y + lz) * (y + lz) + x * x, (x + lz) * (x + lz) + y * y);
    ans
    = min(ans, (ly + x) * (ly + x) + (ly - y + lz) * (ly - y + lz));
    ans
    = min(ans, (y + lx) * (y + lx) + (lx - x + lz) * (lx - x + lz));
    printf(
    "%d\n", ans);
    continue;
    }
    if (y == ly)
    {
    ans
    = min((z + ly) * (z + ly) + x * x, (x + ly) * (x + ly) + z * z);
    ans
    = min(ans, (lz + x) * (lz + x) + (lz - z + y) * (lz - z + y));
    ans
    = min(ans, (lx + z) * (lx + z) + (lx - x + y) * (lx - x + y));
    printf(
    "%d\n", ans);
    continue;
    }
    if (x == lx)
    {
    ans
    = min((y + lx) * (y + lx) + z * z, (z + lx) * (z + lx) + y * y);
    ans
    = min(ans, (ly + z) * (ly + z) + (ly - y + x) * (ly - y + x));
    ans
    = min(ans, (lz + y) * (lz + y) + (lz - z + x) * (lz - z + x));
    printf(
    "%d\n", ans);
    continue;
    }
    }
    return 0;
    }
  • 相关阅读:
    Git for Android Studio 学习笔记
    ACM-线段树区间更新+离散化
    hdu 1394 逆序数(线段树)
    Android瀑布流照片
    Android照片墙-多图加载
    Android-加载图片避免OOM
    Android-自定义View实现ImageView播放gif
    maven---工程建立及目录添加--
    oracle--视图(2)---
    Hibernate---Hql查询2---
  • 原文地址:https://www.cnblogs.com/rainydays/p/2114130.html
Copyright © 2011-2022 走看看