栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【CCF-CSP】 202109-3 脉冲神经网络

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【CCF-CSP】 202109-3 脉冲神经网络

题目

题目:脉冲神经网络

代码 一、33分版本
#include
using namespace std;
static unsigned long ne = 1;
const int M = 1000;
const int BM = 100000;


int myrand(void) {
    ne = ne * 1103515245 + 12345;
    return((unsigned)(ne/65536) % 32768);
}

typedef struct nerve{
    int cnt;
    double I,v,u,a,b,c,d;
}nerve;
nerve nerves[M];

typedef struct tran{
    int out;
    int arrive_time[BM];
    double w;
    int D;
}tran;
map trans;
map > relation;

typedef struct pulse{
    int id,r;
}pulse;
map pulses;

void update(nerve &ner, double t){
    double v = ner.v,u = ner.u;
    ner.v = v + t*(0.04*v*v+5*v+140-u) + ner.I;
    ner.u = u+t*ner.a*(ner.b*v-u);

}

int cid(int in,int out){
    return in*M+out;
}

void make_pulse(int in,int time){
    int temp_in = in;
    set outs = relation[temp_in];
    for(auto temp_out:outs){
        //cout<<"temp_out:"<
    int N,S,P,T;
    cin>>N>>S>>P>>T;
    double t;cin>>t;
    int temp_N = N;
    int i=0;
    while(temp_N){
        //cout<<"test0!"<>r>>v>>u>>a>>b>>c>>d;
        temp_N-=r;
        while(r--){
            nerves[i] = nerve{0,0,v,u,a,b,c,d};
            i++;
        }
    }
    //cout<<"test1!"<
        int r;cin>>r;
        pulses[i] = pulse{i,r};
        i++;
    }
    //cout<<"test2!"<
        int in,out;
        double w;
        int D;
        cin>>in>>out>>w>>D;
        int id = cid(in,out);
        trans[id] = tran{out,{},w,D};
        if(relation.count(in) == 0){
            relation[in] = set();
            relation[in].insert(out);
        }else{
            relation[in].insert(out);
        }
    }
    //cout<<"test3!"< vs;
    vector cnts;
    for(int i=1; i<=T; i++){
        //cout<
            int rand = myrand();
            //cout<<"r:"<rand){
                make_pulse(p.first,i);
                //cout<<"pulse makeing pulse:"<
            tran temp_tran = t.second;
            if(temp_tran.arrive_time[i] == 1){
                int id = temp_tran.out;
                nerves[id].I += temp_tran.w;
                //cout<<"ner"<
            //cout<<"test,i am in j loop"<30){
                ner.v = ner.c;
                ner.u = ner.u+ner.d;
                ner.cnt++;
                make_pulse(j,i);
                //cout<<"updated ner.v:"<
                vs.push_back(ner.v);
                cnts.push_back(ner.cnt);
            }

        }
        if(i==T){
            int min_cnt,max_cnt;
            double max_v,min_v;
            max_cnt = *max_element(cnts.begin(),cnts.end());
            min_cnt = *min_element(cnts.begin(),cnts.end());
            max_v = *max_element(vs.begin(),vs.end());
            min_v = *min_element(vs.begin(),vs.end());
            //cout<<"after giving number!"< 

认真审题!!!!!!!!!!!!!!!!
这一次漏掉了“在每个时间刻,按照编号顺序从小到大,每个脉冲源调用一次上述的伪随机函数”这句话,我以为是每个时刻只需要调用一次随机函数就可以了,实际是有多少个脉冲源就调用多少次!
做了三次模拟题,都遇到了这个问题,不认真审题漏了条件,导致少部分结果正确,其他都错误,提交就0分。以后读题,每个字都给我读清楚!
然后就是超时问题,代码超时的主要原因在于传递脉冲的过程,因为一个脉冲可能同时传给多个神经元,我用的方法是用map这样的方式来保存某脉冲或者神经元的后继节点,一旦产生脉冲就遍历后继节点,但我看很多题解都是用一个二维数组进行传递,用空间换取时间,以后改进。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/920961.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号