csu1569: Wet Tiles

csu1569: Wet Tiles

Time Limit: 6 Sec Memory Limit: 512 MB

Description

Alice owns a construction company in the town of Norainia, famous for its unusually dry weather. In fact, it only rains a few days per year there. Because of this phenomenon, many residents of Norainia neglect to do roof repairs until leaks occur and ruin their floors. Every year, Alice receives a deluge of calls from residents who need the leaks fixed and floor tiles replaced. While exquisite in appearance, Norainia floor tiles are not very water resistant; once a tile becomes wet, it is ruined and must be replaced. This year, Alice plans to handle the rainy days more efficiently than in past years. She will hire extra contractors to dispatch as soon as the calls come in, so hopefully all leaks can be repaired as soon as possible. For each house call, Alice needs a program to help her determine how many replacement tiles a contractor team will need to bring to complete the job.

For a given house, square floor tiles are arranged in a rectangular grid. Leaks originate from one or more known source locations above specific floor tiles. After the first minute, the tiles immediately below the leaks are ruined. After the second minute, water will have spread to any tile that shares an edge with a previously wet tile. This pattern of spreading water continues for each additional minute. However, the walls of a house restrict the water; if a damaged area hits a wall, the water does not penetrate the wall. We assume there are always four outer walls surrounding the entire house. A house may also have a number of additional “inner” walls; each inner wall is comprised of a connected linear sequence of locations (which may or may not be connected to the outer walls or to each other).

As an example, Figure 1 shows water damage (in gray) that would result from three initial leaks (each marked with a white letter ‘L’) after each of the first five minutes of time. Tiles labeled ‘2’ become wet during the second minute, tiles labeled ‘3’ become wet during the third minute, and so forth. The black areas designate inner walls that restrict the flow of water. Note that after 5 minutes, a total of 75 tiles have been damaged and will need to be replaced. Figures 2 through 4 show other houses that correspond to the example inputs for this problem.

75 wet tiles

这里写图片描述

17 wet tiles
这里写图片描述

4 wet tiles
这里写图片描述

94 wet tiles
这里写图片描述

Input

Each house is described beginning with a line having five integral parameters: X Y T L W. Parameters X and Y designate the dimensions of the rectangular grid, with 1 ≤ X ≤ 1000 and 1 ≤ Y ≤ 1000. The coordinate system is one-indexed, as shown in the earlier figures. Parameter T designates the number of minutes that pass before a team of contractors arrives at a house and stops the leaks, with 1 ≤ T ≤ 200000. The parameter L designates the number of leaks, with 1 ≤ L ≤ 100. Parameter W designates the number of inner walls in the house, 0 ≤ W ≤ 100.

The following 2L integers in the data set, on one or more lines, are distinct (x y) pairs that designate the locations of the L distinct leaks, such that 1 ≤ x ≤ X and 1 ≤ y ≤ Y.

If W > 0, there will be 4W additional integers, on one or more lines, that describe the locations of the walls. For each such wall the four parameters (x1,y1), (x2,y2) describe the locations of two ends of the wall. Each wall replaces a linear sequence of adjoining tiles and is either axis-aligned or intersects both axes at a 45 degree angle. Diagonal walls are modeled as a sequence of cells that would just be touching corner to corner. If the two endpoints of a wall are the same, the wall just occupies the single cell at that location. Walls may intersect with each other, but no leak is over a wall.

There will be one or more houses in the data file and a line with a single integer -1 designates the end of the data set.

Output

For each house, display the total number of tiles that are wet after T minutes.

Sample Input
12 12 5 3 5
2 11 3 3 9 5
1 9 6 9 1 7 4 4 7 1 7 4
10 9 10 12 11 4 12 4

9 7 8 1 3
4 3
2 2 6 6 6 2 2 6 8 2 8 2

6 7 50 1 3
3 4
2 2 2 6 3 6 5 4 5 4 3 2

12 12 5 3 0
2 11 3 3 9 5
-1

Sample Output
75
17
4
94

题虽然长,但是不难,bfs搜索即可。这是我会的第一个bfs,纪念一下。

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <queue>
#define pi acos(-1)
#define MIN 0.0000000001
using namespace std;

int tile[1001][1001];
int X,Y;

void makw (int x1,int y1,int x2,int y2)
{
    int i,j;
    if (x1==x2)
    {
        if (y1>y2) swap(y1,y2);
        for(i=y1;i<=y2;i++)
            tile[x1][i]=2;
        return;
    }
    else if (y1==y2)
    {
        if (x1>x2) swap(x1,x2);
        for(i=x1;i<=x2;i++)
            tile[i][y1]=2;
        return;
    }
    else
    {
        if (x1<x2)
        {
            if (y1<y2)
            {
                for(i=x1,j=y1;i<=x2;i++,j++)
                    tile[i][j]=2;
            }
            else
            {
                for(i=x1,j=y1;i<=x2;i++,j--)
                    tile[i][j]=2;
            }
        }
        else
        {
            if (y1<y2)
            {
                for(i=x1,j=y1;i>=x2;i--,j++)
                    tile[i][j]=2;
            }
            else
            {
                for(i=x1,j=y1;i>=x2;i--,j--)
                    tile[i][j]=2;
            }
        }
    }
}

bool jon(int x,int y)
{
    if (x-1==0) return false;
    if (tile[x-1][y]!=0) return false;
    return true;
}

bool jdown(int x,int y)
{
    if (x+1>X) return false;
    if (tile[x+1][y]!=0) return false;
    return true;
}

bool jleft (int x,int y)
{
    if (y-1==0) return false;
    if (tile[x][y-1]!=0) return false;
    return true;
}

bool jright (int x,int y)
{
    if (y+1>Y) return false;
    if (tile[x][y+1]!=0) return false;
    return true;
}

void print()
{
    int i,j;
    for(i=1;i<=X;i++)
        {
            for(j=1;j<=Y;j++)
                cout<<tile[i][j]<<' ';
            cout<<endl;
        }
    cout<<endl;
}

int main()
{
    //freopen("i.txt","r",stdin);
    int a,b ,T ,L ,W;
    int cases=0;
    int num1,num2;
    int i,j,k,x,y;
    while(cin>>X)
    {
        if (X<0) return 0;
        cin>>Y>>T>>L>>W;
        //cout<<X<<" "<<Y<<' '<<T<<' '<<L<<' '<<W<<endl;
        queue<int> wet;
        wet.empty();
        int l[1000001][2];
        memset(tile,0,sizeof(tile));
        for(i=1;i<=L;i++)
        {
            cin>>x>>y;
            l[i][0]=x,l[i][1]=y;
            tile[x][y]=1;
            wet.push(i);
        }
        while(W--)
        {
            cin>>x>>y>>a>>b;
            makw(x,y,a,b);
            //print();
        }
        int sum=L;
        int num=L;
        T--;
        while(T--)
        {
            for(i=0;i<num;i++)
            {
                int x=wet.front();
                int x1=l[x][0],y1=l[x][1];
                //cout<<x1<<' '<<y1<<endl;
                if (jon(x1,y1))
                {
                    sum++;
                    l[sum][0]=l[x][0]-1;
                    l[sum][1]=l[x][1];
                    wet.push(sum);
                    int x2=l[sum][0],y2=l[sum][1];
                    tile[x2][y2]++;
                    //cout<<x<<'d'<<x2<<' '<<y2<<' '<<sum<<endl;
                }
                if (jdown(x1,y1))
                {
                    sum++;
                    l[sum][0]=l[x][0]+1;
                    l[sum][1]=l[x][1];
                    wet.push(sum);
                    int x2=l[sum][0],y2=l[sum][1];
                    tile[x2][y2]++;
                    //cout<<x<<'d'<<x2<<' '<<y2<<' '<<sum<<endl;
                }
                if (jleft(x1,y1))
                {
                    sum++;
                    l[sum][0]=l[x][0];
                    l[sum][1]=l[x][1]-1;
                    wet.push(sum);
                    int x2=l[sum][0],y2=l[sum][1];
                    tile[x2][y2]++;
                    //cout<<x<<'d'<<x2<<' '<<y2<<' '<<sum<<endl;
                }
                if (jright(x1,y1))
                {
                    sum++;
                    l[sum][0]=l[x][0];
                    l[sum][1]=l[x][1]+1;
                    wet.push(sum);
                    int x2=l[sum][0],y2=l[sum][1];
                    tile[x2][y2]++;
                    //cout<<x<<'d'<<x2<<' '<<y2<<' '<<sum<<endl;
                }
                wet.pop();
            }
            num=wet.size();
            //cout<<endl;
            //print();
        }
        cout<<sum<<endl;
    }
    return 0;
}
数据中心机房是现代信息技术的核心设施,它承载着企业的重要数据和服务,因此,其基础设计与规划至关重要。在制定这样的方案时,需要考虑的因素繁多,包括但不限于以下几点: 1. **容量规划**:必须根据业务需求预测未来几年的数据处理和存储需求,合理规划机房的规模和设备容量。这涉及到服务器的数量、存储设备的容量以及网络带宽的需求等。 2. **电力供应**:数据中心是能源消耗大户,因此电力供应设计是关键。要考虑不间断电源(UPS)、备用发电机的容量,以及高效节能的电力分配系统,确保电力的稳定供应并降低能耗。 3. **冷却系统**:由于设备密集运行,散热问题不容忽视。合理的空调布局和冷却系统设计可以有效控制机房温度,避免设备过热引发故障。 4. **物理安全**:包括防火、防盗、防震、防潮等措施。需要设计防火分区、安装烟雾探测和自动灭火系统,设置访问控制系统,确保只有授权人员能进入。 5. **网络架构**:规划高速、稳定、冗余的网络架构,考虑使用光纤、以太网等技术,构建层次化网络,保证数据传输的高效性和安全性。 6. **运维管理**:设计易于管理和维护的IT基础设施,例如模块化设计便于扩展,集中监控系统可以实时查看设备状态,及时发现并解决问题。 7. **绿色数据中心**:随着环保意识的提升,绿色数据中心成为趋势。采用节能设备,利用自然冷源,以及优化能源管理策略,实现低能耗和低碳排放。 8. **灾难恢复**:考虑备份和恢复策略,建立异地灾备中心,确保在主数据中心发生故障时,业务能够快速恢复。 9. **法规遵从**:需遵循国家和地区的相关法律法规,如信息安全、数据保护和环境保护等,确保数据中心的合法运营。 10. **扩展性**:设计时应考虑到未来的业务发展和技术进步,保证机房有充足的扩展空间和升级能力。 技术创新在数据中心机房基础设计及规划方案中扮演了重要角色。例如,采用虚拟化技术可以提高硬件资源利用率,软件定义网络(SDN)提供更灵活的网络管理,人工智能和机器学习则有助于优化能源管理和故障预测。 总结来说,一个完整且高效的数据中心机房设计及规划方案,不仅需要满足当前的技术需求和业务目标,还需要具备前瞻性和可持续性,以适应快速变化的IT环境和未来可能的技术革新。同时,也要注重经济效益,平衡投资成本与长期运营成本,实现数据中心的高效、安全和绿色运行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值