zoukankan      html  css  js  c++  java
  • poj3347 Kadj Squares【计算几何】

    Kadj Squares
    Time Limit: 2000MS   Memory Limit: 65536K
    Total Submissions: 3594   Accepted: 1456

    Description

    In this problem, you are given a sequence S1S2, ..., Sn of squares of different sizes. The sides of the squares are integer numbers. We locate the squares on the positive x-y quarter of the plane, such that their sides make 45 degrees with x and y axes, and one of their vertices are on y=0 line. Let bi be the x coordinates of the bottom vertex of Si. First, put S1 such that its left vertex lies on x=0. Then, put S1, (i > 1) at minimum bi such that

    • bi > bi-1 and
    • the interior of Si does not have intersection with the interior of S1...Si-1.

    The goal is to find which squares are visible, either entirely or partially, when viewed from above. In the example above, the squares S1S2, and S4 have this property. More formally, Si is visible from above if it contains a point p, such that no square other than Si intersect the vertical half-line drawn from p upwards.

    Input

    The input consists of multiple test cases. The first line of each test case is n (1 ≤ n ≤ 50), the number of squares. The second line contains n integers between 1 to 30, where the ith number is the length of the sides of Si. The input is terminated by a line containing a zero number.

    Output

    For each test case, output a single line containing the index of the visible squares in the input sequence, in ascending order, separated by blank characters.

    Sample Input

    4
    3 5 1 4
    3
    2 1 2
    0
    

    Sample Output

    1 2 4
    1 3
    

    Source

    题意:

    n个正方形45度角的放,边靠着边,放完了之后从顶部往下看。有哪些正方形没有被挡住。

    思路:

    我们从这张图来看,正方形之间的三角形是等腰三角形,边长是两个正方形边长的较小值。

    我们现在记下每个正方形的最左的横坐标,和最右的横坐标,和边长。并且我们假设输入的边长是实际边长投影在横坐标上的长度。

    因为大家都同时放大,是不影响结果的。

    当我们摆好了前面i-1个正方形之后,摆第i个正方形。那么可以知道第i个正方形的左端点应该是前面所有正方形的最右端点减去两个正方形边长之差。

    摆好第i个正方形之后我们再看,前i-1个正方形中有哪几个被遮掉了一部分。

    有两种情况,一种是左边的遮掉右边的,一种是右边的遮掉左边的。

     1 #include <iostream>
     2 #include <set>
     3 #include <cmath>
     4 #include <stdio.h>
     5 #include <cstring>
     6 #include <algorithm>
     7 #include <vector>
     8 #include <queue>
     9 #include <map>
    10 //#include <bits/stdc++.h>
    11 using namespace std;
    12 typedef long long LL;
    13 #define inf 0x7f7f7f7f
    14 
    15 const int maxn = 55;
    16 int n;
    17 struct node{
    18     int len, l, r;
    19 }squ[maxn];
    20 
    21 
    22 int main()
    23 {
    24     while(scanf("%d", &n) != EOF && n){
    25         for(int i = 1; i <= n; i++){
    26             scanf("%d", &squ[i].len);
    27             squ[i].l = 0;
    28             for(int j = 1; j < i; j++){
    29                 squ[i].l = max(squ[i].l, squ[j].r - abs(squ[i].len - squ[j].len));
    30             }
    31             squ[i].r = squ[i].l + 2 * squ[i].len;
    32             for(int j = 1; j < i; j++){
    33                 if(squ[j].r > squ[i].l){
    34                     if(squ[i].len > squ[j].len){
    35                         squ[j].r = squ[i].l;
    36                     }
    37                     else{
    38                         squ[i].l = squ[j].r;
    39                     }
    40                 }
    41             }
    42         }
    43 
    44         bool flag = true;
    45         for(int i = 1; i <= n; i++){
    46             if(squ[i].l < squ[i].r){
    47                 if(flag){
    48                     printf("%d", i);
    49                     flag = false;
    50                 }
    51                 else{
    52                     printf(" %d", i);
    53                 }
    54             }
    55         }
    56         printf("
    ");
    57 
    58     }
    59     return 0;
    60 }
  • 相关阅读:
    python3.6.4源码安装
    centos 6 中恢复删除的文件
    mysql5.6.8源码安装
    zookeeper集群搭建
    vmware 12中安装苹果系统
    docker被入侵后.............
    关于docker
    关于redis
    人生的价值 幸福感
    c# 泛型
  • 原文地址:https://www.cnblogs.com/wyboooo/p/9889755.html
Copyright © 2011-2022 走看看