删除格子里的草地和树

public void CutGrassTree(Terrain t, FacilityGrid grid, float radius)
{
    if (t == null)
    {
        t = Terrain.activeTerrain;
    }

    int TerrainDetailMapSize = t.terrainData.detailResolution;
    if (t.terrainData.size.x != t.terrainData.size.z)
    {
        return;
    }

    Vector3 position = grid.GetCenterPos();
    
    float PrPxSize = TerrainDetailMapSize / t.terrainData.size.x;

    Vector3 TexturePoint3D = position - t.transform.position;
    TexturePoint3D = TexturePoint3D * PrPxSize;
    radius = radius * PrPxSize;

    float[] xymaxmin = new float[4];
    Vector3 angleDeg = new Vector3(0f, 35f, 0f);
    xymaxmin[0] = TexturePoint3D.z + radius;
    xymaxmin[1] = TexturePoint3D.z - radius;
    xymaxmin[2] = TexturePoint3D.x + radius;
    xymaxmin[3] = TexturePoint3D.x - radius;
    
    Vector3 rt = ToolKit.GetRotatePosition(new Vector3(xymaxmin[0], 0, xymaxmin[2]), position, angleDeg);
    Vector3 lt = ToolKit.GetRotatePosition(new Vector3(xymaxmin[1], 0, xymaxmin[2]), position, angleDeg);
    Vector3 rb = ToolKit.GetRotatePosition(new Vector3(xymaxmin[0], 0, xymaxmin[3]), position, angleDeg);
    Vector3 lb = ToolKit.GetRotatePosition(new Vector3(xymaxmin[1], 0, xymaxmin[3]), position, angleDeg);

    xymaxmin[0] = ToolKit.GetMinMaxValue(new[] {rt.x, lt.x, rb.x, lb.x}, true);
    xymaxmin[1] = ToolKit.GetMinMaxValue(new[] {rt.x, lt.x, rb.x, lb.x}, false);
    xymaxmin[2] = ToolKit.GetMinMaxValue(new[] {rt.z, lt.z, rb.z, lb.z}, true);
    xymaxmin[3] = ToolKit.GetMinMaxValue(new[] {rt.z, lt.z, rb.z, lb.z}, false);
    
    int[,] map = t.terrainData.GetDetailLayer(0, 0, t.terrainData.detailWidth, t.terrainData.detailHeight, 0);

    for (int y = 0; y < t.terrainData.detailHeight; y++)
    {
        for (int x = 0; x < t.terrainData.detailWidth; x++)
        {
            Vector3 p = new Vector3(x, 0, y);
            p = ToolKit.GetRotatePosition(p, position, new Vector3(0, 35f, 0));
            if (xymaxmin[0] > p.x && xymaxmin[1] < p.x && xymaxmin[2] > p.z && xymaxmin[3] < p.z)
            {
                map[x, y] = 0;
            }
                
        }
    }
    
    t.terrainData.SetDetailLayer(0, 0, 0, map);
    
    TreeInstance[] treeInstances = t.terrainData.treeInstances;

    List<int> removedIndex = new List<int>(5);
    List<TreeInstance> list = new List<TreeInstance>(5);
    for (int i = 0; i < treeInstances.Length; i++)
    {
        TreeInstance currentTree = treeInstances[i];
        Vector3 currentTreeWorldPosition = Vector3.Scale(currentTree.position, t.terrainData.size) + t.transform.position;

        if (!grid.IsInGrid(currentTreeWorldPosition))
        {
            list.Add(currentTree);
        }
    }
   
    t.terrainData.treeInstances = list.ToArray();

    
    t.Flush();
}

 

# U599016 咿——哈! ## 题目背景 $$ ## 题目描述 ~~猜猜我是怎么将题目背景弄成没有的~~ 植物大战僵尸面的蹦极僵尸会偷走植物,这使得小$O$很郁闷,他现在给你一张草地的图,僵王博士首先会让蹦极僵尸在$(a,b)$点开始偷植物,求能不能让蹦极僵尸偷走所有植物。已知蹦极僵尸的初始血量为$x$,每偷走一个植物,僵王博士便会奖励他这个植物的所有血量(血量就会加上它),偷的植物必须比蹦极僵尸的血量少。而且每一次偷走的植物都必须为上一次偷走的植物的旁边(上下左右),但是有一些格子理由火爆辣椒或者樱桃炸弹,偷走这两个植物分别会使一行或者三乘三的格子面的植物不能被偷。(这俩的血量视为$-∞$,而且不视为植物) ## 输入格式 第一行五个数:$n,m,a,b,x$其中$n$ $m$分别表示草地的行数列数 加下来$n$行,每一行$m$个数,第$i$行第$j$列的数表示第$i$行第$j$列的植物的血量。输入"$h$"表示这个植物时火爆辣椒,输入"$y$"则表示这个植物是樱桃炸弹。 ## 输出格式 仅一行莫若能偷走所有植物输出“$Y$”,否则输出“$N$” ## 输入输出样例 #1 ### 输入 #1 ``` 3 3 1 1 1 0 1 1 1 1 1 1 1 1 ``` ### 输出 #1 ``` N ``` ## 输入输出样例 #2 ### 输入 #2 ``` 5 5 1 1 8 1 y 0 0 0 h 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ``` ### 输出 #2 ``` N ``` ## 输入输出样例 #3 ### 输入 #3 ``` 3 4 1 1 2 1 2 3 7 h 14 11 -10 29 -40 -10 y ``` ### 输出 #3 ``` Y ``` ## 输入输出样例 #4 ### 输入 #4 ``` 1 1 1 1 -100000000 y ``` ### 输出 #4 ``` Y ``` ## 输入输出样例 #5 ### 输入 #5 ``` 10 10 5 5 10 y y y y y y y y y y y h h h h h h h h h y y y y y y y y y y y h h h h h h h h h y y y y y y y y y y y h h h h h h h h h y y y y y y y y y y y h h h h h h h h h y y y y y y y y y y y h h h h h h h h h ``` ### 输出 #5 ``` Y ``` ## 说明/提示 $n,m<=500$ $a<=n$ $b<=m$ $x,a[i][j]<=1e8$c++,,给几个c++代码,第一个是题解,第二个是目前还没有测试数据,用一个c++代码来计算并输出几个测试数据,再再在另外,输出这两个c++代码的时间复杂度
最新发布
10-19
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值