2015 多校赛 第四场 1010 (hdu 5336)

本文深入探讨了游戏开发领域的核心技术,包括游戏引擎、Unity、Cocos2d等,以及AI音视频处理技术的应用,如视频分割、语义识别、语音识别等。通过实例解析,为开发者提供全面的技术指导。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem Description
XYZ is playing an interesting game called "drops". It is played on a rc grid. Each grid cell is either empty, or occupied by a waterdrop. Each waterdrop has a property "size". The waterdrop cracks when its size is larger than 4, and produces 4 small drops moving towards 4 different directions (up, down, left and right). 

In every second, every small drop moves to the next cell of its direction. It is possible that multiple small drops can be at same cell, and they won't collide. Then for each cell occupied by a waterdrop, the waterdrop's size increases by the number of the small drops in this cell, and these small drops disappears. 

You are given a game and a position (xy), before the first second there is a waterdrop cracking at position (xy). XYZ wants to know each waterdrop's status after T seconds, can you help him?

1r1001c1001n1001T10000
 

 

Input
The first line contains four integers rcn and Tn stands for the numbers of waterdrops at the beginning. 
Each line of the following n lines contains three integers xiyisizei, meaning that the i-th waterdrop is at position (xiyi) and its size is sizei. (1sizei4)
The next line contains two integers xy

It is guaranteed that all the positions in the input are distinct. 

Multiple test cases (about 100 cases), please read until EOF (End Of File).
 

 

Output
n lines. Each line contains two integers AiBi
If the i-th waterdrop cracks in T seconds, Ai=0Bi= the time when it cracked. 
If the i-th waterdrop doesn't crack in T seconds, Ai=1Bi= its size after T seconds.
 

 

Sample Input
4 4 5 10
2 1 4
2 3 3
2 4 4
3 1 2
4 3 4
4 4
 

 

Sample Output
0 5
0 3
0 2
1 3
0 1
 

题意:

在一个 r*c 的格子图上,有 n 个水滴静止。每当水滴体积超过 4 时,会分成 4 个体积为 1 的小水滴向上下左右四个方向运动,每秒移动一个格子。小水滴与静止的水滴碰撞后会合成,体积相加。开始时 n 个水滴都静止,给出一个在 (x,y) 位置炸开的水滴作为启动源。

注意:1.小水滴彼此间不影响,即使同时经过同一位置。

2.若多个小水滴同时到达同一格子,则都与位于该格子的水滴合体,体积相加。超过 4 后按上述规则分裂。(即使为6,7等等)

 

思路:

因为数据较小所以直接暴力模拟O(nT)也能过。。

笔者用优先队列维护最先受到影响的水滴,依次处理,直到时间超出 T 或者是优先队列为空,则终止。

刚开始没有注意到应该注意的两点各种跪。。

水滴的结构体中还有一个变量 dir 记录该影响移动的方向。因为存在到了该“影响”发生的时候原有位置的水滴已经分裂不存在的情况,此时应继续向该方向搜索离之最近的点。

感觉实现的时候还是比较多细节要注意的。

代码如下:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
#define mod 1005
const int U=1,D=2,L=3,R=4;
int r,c,n,t,x,y;
struct drop{
    int x,y,size,status,time,num,dir;
    bool operator < (const drop d) const{
        return time>d.time;
    }
}drops[105];
int update(int num,int dir){
    int closest=-1;
    for(int i=0;i<n;i++) if(drops[i].status&&i!=num){
        if(dir==U){
            if(drops[num].x==drops[i].x&&drops[num].y<drops[i].y)
                if(closest==-1||drops[i].y<drops[closest].y) closest=i;
        }
        else if(dir==D){
            if(drops[num].x==drops[i].x&&drops[num].y>drops[i].y)
                if(closest==-1||drops[i].y>drops[closest].y) closest=i;
        }
        else if(dir==L){
            if(drops[num].y==drops[i].y&&drops[num].x>drops[i].x)
                if(closest==-1||drops[i].x>drops[closest].x) closest=i;
        }
        else{
            if(drops[num].y==drops[i].y&&drops[num].x<drops[i].x)
                if(closest==-1||drops[i].x<drops[closest].x) closest=i;
        }
    }
    return closest;
}
priority_queue<drop>pq;
vector<drop> T;
int main(){
    for(int i=0;i<105;i++) drops[i].num=i;
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    while(~scanf("%d%d%d%d",&r,&c,&n,&t)){
        for(int i=0;i<n;i++){
            scanf("%d%d%d",&drops[i].x,&drops[i].y,&drops[i].size);
            drops[i].status=1,drops[i].time=10005;
        }
        scanf("%d%d",&x,&y);
        while(!pq.empty()) pq.pop();
        drops[100].x=x,drops[100].y=y,drops[100].status=1;
        drops[100].size=4,drops[100].time=0;
        pq.push(drops[100]);
        int t_now=0;
        while(!pq.empty()){
            drop tmp=pq.top();
            while(!drops[tmp.num].status){
                pq.pop();
                int num=update(tmp.num,tmp.dir);
                if(num!=-1){
                    drop temp=drops[num];
                    temp.dir=tmp.dir;
                    if(temp.dir==U) temp.time=temp.y-tmp.y;
                    else if(temp.dir==D) temp.time=tmp.y-temp.y;
                    else if(temp.dir==L) temp.time=tmp.x-temp.x;
                    else temp.time=temp.x-tmp.x;
                    temp.time+=tmp.time;
                    pq.push(temp);
                }
                if(pq.empty()) break;
                else tmp=pq.top();
            }
            if(pq.empty()) break;
            if(tmp.time>t) break;
            int up=-1,down=-1,left=-1,righ=-1;
            if(drops[tmp.num].size<4){
                drops[tmp.num].size++;
                pq.pop();
                continue;
            }
            pq.pop();//new
            T.clear();
            while(!pq.empty()){
                drop Tmp=pq.top();
                if(Tmp.time==tmp.time&&Tmp.x==tmp.x&&Tmp.y==tmp.y)
                    pq.pop();
                else if(Tmp.time==tmp.time){
                    T.push_back(Tmp);
                    pq.pop();
                }
                else break;
            }
            for(int i=0;i<T.size();i++) pq.push(T[i]);
            drops[tmp.num].status=0;
            drops[tmp.num].time=tmp.time;
            t_now=drops[tmp.num].time;
            for(int i=0;i<n;i++) if(drops[i].status){
                if(tmp.x==drops[i].x){
                    if(tmp.y<drops[i].y){
                        if(up==-1||drops[i].y<drops[up].y) up=i;
                    }
                    else{
                        if(down==-1||drops[i].y>drops[down].y) down=i;
                    }
                }
                else if(tmp.y==drops[i].y){
                    if(tmp.x>drops[i].x){
                        if(left==-1||drops[i].x>drops[left].x) left=i;
                    }
                    else{
                        if(righ==-1||drops[i].x<drops[righ].x) righ=i;
                    }
                }
            }
            if(up!=-1&&drops[up].time>drops[up].y-tmp.y+t_now){
                drop temp=drops[up];
                temp.time=drops[up].y-tmp.y+t_now,temp.dir=U;
                pq.push(temp);
            }
            if(down!=-1){
                drop temp=drops[down];
                temp.time=tmp.y-drops[down].y+t_now,temp.dir=D;
                pq.push(temp);
            }
            if(left!=-1){
                drop temp=drops[left];
                temp.time=tmp.x-drops[left].x+t_now,temp.dir=L;
                pq.push(temp);
            }
            if(righ!=-1){
                drop temp=drops[righ];
                temp.time=drops[righ].x-tmp.x+t_now,temp.dir=R;
                pq.push(temp);
            }
            //pq.pop();
        }
        for(int i=0;i<n;i++){
            if(drops[i].status) printf("1 %d\n",drops[i].size);
            else printf("0 %d\n",drops[i].time);
        }
    }
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/names-yc/p/4703137.html

内容概要:本文介绍了基于SMA-BP黏菌优化算法优化反向传播神经网络(BP)进行变量回归预测的项目实例。项目旨在通过SMA优化BP神经网络的权重和阈值,解决BP神经网络易陷入局部最优、收敛速度慢及参数调优困难等问题。SMA算法模拟黏菌寻找食物的行为,具备优秀的全局搜索能力,能有效提高模型的预测准确性和训练效率。项目涵盖了数据预处理、模型设计、算法实现、性能验证等环节,适用于变量非线性数据的建模和预测。; 适合人群:具备一定机器学习基础,特别是对神经网络和优化算法有一定了解的研发人员、数据科学家和研究人员。; 使用场景及目标:① 提升变量回归模型的预测准确性,特别是在工业过程控制、金融风险管理等领域;② 加速神经网络训练过程,减少迭代次数和训练时间;③ 提高模型的稳定性和泛化能力,确保模型在不同数据集上均能保持良好表现;④ 推动智能优化算法与深度学习的融合创新,促进领域复杂数据分析能力的提升。; 其他说明:项目采用Python实现,包含详细的代码示例和注释,便于理解和二次开发。模型架构由数据预处理模块、基于SMA优化的BP神经网络训练模块以及模型预测与评估模块组成,各模块接口清晰,便于扩展和维护。此外,项目还提供了种评价指标和可视化分析方法,确保实验结果科学可信。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值