• toj 2804 The Art Gallery Problem


       The Art Gallery Problem

    Time Limit: 1.0 Seconds   Memory Limit: 65536K



    In 1973, Klee posed a fascinating problem - the art gallery problem. Imagine an art gallery room whose floor plan can be modeled by a polygon of n vertices. Klee asked: How many stationary guards are needed to guard the room? Each guard is considered a fixed point that can see in every direction. Of course a guard cannot see through a wall of the room. An equivalent formulation is to ask how many point lights are needed to fully illuminate the room. To let you fully understand this problem, there are two points needed to explain in detail.

    Visibility

    To make the notion of visibility precise, we say that point x can see point y (or y is visible to x) if and only if the closed segment xy is nowhere exterior to the polygon. Note that this definition permits the line-of-sight to have grazing contact with a vertex, as shown in the following figure.

    A set of guards is said to cover a polygon if every point in the polygon is visible to some guard. Guards themselves do not block each other's visibility.

    Max over Min Formulation

    The phrase "how many" means that we need to find the maximum over all polygons of n vertices, of the minimum number of guards needed to cover the polygon.

    For example, the following are two polygons of 12 vertices.

    The first polygon needs at least three guards, but the second needs at least four guards. So the number of guards needed when n equals to 12 is at least 4.

    You may think how hard this problem is, just like nuanran. But what's surprising is that the conclusion is very simple, it is just n/3, the integer part of n divided by 3.

    Although it is such an easy job, nuanran still doesn’t want to do it himself. What a lazy guy! As an excellent student of Tianjin University, can you help him?

    Input

    The input will contain multiple test cases. Each test case contains a single line with a single integer n, the number of vertices of the polygon. (3 ≤ n ≤ 101000)

    The input will be terminated by the end of file.

    Output

    For each corresponding n, output a single line with the number of guards needed.

    Sample Input

    5
    100
    99999999999999999999

    Sample Output

    1
    33
    33333333333333333333

    Problem Setter: nuanran

    Source:  TJU Programming Contest 2007 Preliminary

    Problem ID in problemset: 2804



    Submit   Back   Runs   Statistics   Clarifications

    #include <iostream>
    #define MAX 1002
    using namespace std;
    typedef 
    struct node
    {
        
    char num[MAX];
        
    int len;
    }Num;
    void Change(Num &ob,int n)
    {
        
    int i;
        
    for(i=0;i<ob.len;i++)
            ob.num[i]
    -=n;
    }
    void Rev(Num &ob)
    {
        
    int s,e;
        
    char temp;
        s
    =0;
        e
    =ob.len-1;
        
    while(s<e)
        {
            temp
    =ob.num[s];
            ob.num[s]
    =ob.num[e];
            ob.num[e]
    =temp;
            s
    ++;
            
    --e;
        }
    }
    void Mult_ten(Num &ob)
    {
        
    int i;
        
    if(ob.len==1&&ob.num[0]==0)
            
    return ;
        
    for(i=ob.len;i>0;--i)
        {
            ob.num[i]
    =ob.num[i-1];
        }
        ob.num[
    0]=0;
        ob.len
    ++;
    }
    int Cmp(Num &a,Num &b)
    {
        
    if(a.len>b.len)
            
    return 1;
        
    else if(a.len<b.len)
            
    return -1;
        
    else
        {
            
    int i;
            
    for(i=a.len-1;i>=0;--i)
            {
                
    if(a.num[i]>b.num[i])
                    
    return 1;
                
    else if(a.num[i]<b.num[i])
                    
    return -1;
            }
        }
        
    return 0;
    }
    Num Sub(Num 
    &a,Num &b)
    {
        Num c;
        memset(
    &c,0,sizeof(c));
        
    int tw=0,i,l=a.len;
        c.len
    =a.len;
        
    for(i=0;i<=l;i++)
        {
            c.num[i]
    =a.num[i]-b.num[i]-tw;
            
    if(c.num[i]<0)
            {
                tw
    =1;
                c.num[i]
    +=10;
            }
            
    else
                tw
    =0;
        }
        
    while(c.len>1&&!c.num[c.len-1])
            
    --c.len;
        
    return c;
    }
    Num Div(Num 
    &a,Num &b)
    {
        Num temp,c;
        
    int cnt;
        memset(
    &c,0,sizeof(c));
        memset(
    &temp,0,sizeof(temp));
        
    for(int i=a.len-1;i>=0;--i)
        {
            cnt
    =0;
            Mult_ten(c);
            Mult_ten(temp);
            temp.num[
    0]=a.num[i];
            
    while(Cmp(temp,b)>=0)
            {
                temp
    =Sub(temp,b);
                cnt
    ++;
            }
            c.num[
    0]=cnt;
        }
        
    while(c.len>1&&!c.num[c.len-1])
            
    --c.len;
        
    return c;
    }
    int main()
    {
        Num a,b,c;
        memset(
    &a,0,sizeof(a));
        memset(
    &b,0,sizeof(b));
        
    while(scanf("%s",a.num)!=EOF)
        {
            a.len
    =strlen(a.num);
            strcpy(b.num,
    "3");
            b.len
    =1;
            Change(a,
    '0');
            Change(b,
    '0');
            Rev(a);
            Rev(b);

            c
    =Div(a,b);
            Rev(c);
            Change(c,(
    int)(-'0'));

            printf(
    "%s\n",c.num);
            memset(
    &a,0,sizeof(a));
            memset(
    &b,0,sizeof(b));
        }
        
    return 0;
    }
  • 相关阅读:
    Treat wchar_t as built-in type不一致导致的链接错误
    C++ const关键字总结
    安全学习资料网站(持续更新欢迎补充)
    移动端https抓包那些事--进阶篇
    移动端https抓包那些事--初级篇
    drozer工具的安装与使用:之二使用篇
    drozer工具的安装与使用:之一安装篇
    信息安全学习笔记--CSRF
    信息安全学习笔记--XSS
    // 日期操作 封装一些日期常用操作
  • 原文地址:https://www.cnblogs.com/forever4444/p/1456971.html
Copyright © 2020-2023  润新知