拿到这道题就直接进行模拟了,然后果不其然超时了,目前没有想到有效的优化思路,尝试了优化,但还是66分,先留个66分版的在这。
//2109-3脉冲神经网络----66分版
#include<bits/stdc++.h>
using namespace std;
static unsigned long ne = 1;
/* 伪随机函数 */
int myrand(void) {
ne = ne * 1103515245 + 12345;
return((unsigned)(ne/65536) % 32768);
}
double t;
int N, S, P, T;
vector<int> lo[2005]; // 编号---时间
// 定义神经元结构
struct sjy {
int id;
double v, u; // T时刻的最大最小值
double a, b, c, d;
double I=0;
int count=0; // 最终求这个的最大值最小值
void cal_vu() {
double v0 = v, u0 = u;
v = v0 + t*(0.04*v0*v0+5*v0+140-u0) + I; // 强度要先更新
u = u0 + t*a*(b*v0-u0);
}
void update(int nowt) {
if(v>=30) {
v = c;
u = u + d;
count++;
lo[id].push_back(nowt); // 发送脉冲给出突触
}
I = 0; // k时刻之后需要将强度清零---注意前后关系,后续检查
}
}ss[1005];
// 定义脉冲源
struct mcy {
int id;
double r;
void update(int nowt) {
if(r>myrand()) {
// cout << "脉冲时间:" << nowt <<endl;
lo[id].push_back(nowt);
}
}
}mm[1005];
// 定义突触
struct tc {
double w;
int D;
int s, t;
void update(int nowt) {
if(!lo[s].empty()) {
for(auto it=lo[s].begin(); it!=lo[s].end(); it++) {
if(nowt-*it==D){
ss[t].I += w; // 向出结点神经元发送强度脉冲
// it = lo[s].erase(it); // 不能在单个突触內部删除!!
}
}
}
}
}tt[1005];
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// 读取输入
cin >> N >> S >> P >> T >> t;
int sum=0;
while(sum<N) {
int rn;
double v, u, a, b, c, d;
cin >> rn >> v >> u >> a >> b >> c >> d;
for(int i=0; i<rn; i++) {
ss[sum+i].id = sum+i, ss[sum+i].v = v, ss[sum+i].u = u, ss[sum+i].a = a, ss[sum+i].b = b, ss[sum+i].c = c, ss[sum+i].d = d;
}
sum += rn;
}
for(int i=0; i<P; i++) {
cin >> mm[i].r;
mm[i].id = N+i;
}
// cout << "||||"<< endl;
for(int i=0; i<S; i++) {
cin >> tt[i].s >> tt[i].t >> tt[i].w >> tt[i].D;
}
// cout << "||||"<< endl;
for(int nowt=1; nowt<=T; nowt++) { // 程序主循环
// cout << nowt << "-----时刻:" <<endl;
// 更新脉冲源
for(int x=0; x<P; x++) {
mm[x].update(nowt);
}
// 更新突触
for(int x=0; x<S; x++) {
tt[x].update(nowt);
}
// 更新神经元
for(int x=0; x<N; x++) {
ss[x].cal_vu();
ss[x].update(nowt);
}
// cout << ss[0].v << endl;
}
// 记录结果
vector<double> vv;
vector<int> cc;
for(int i=0; i<N; i++) {
vv.push_back(ss[i].v);
cc.push_back(ss[i].count);
}
sort(vv.begin(), vv.end()); sort(cc.begin(), cc.end()); // 默认升序
printf("%.3f %.3f\n", vv[0], vv[N-1]);
printf("%d %d\n", cc[0], cc[N-1]);
// cout << std::fixed << std::setprecision(3) << vv[0] << " "<<vv[N-1] << endl;
// cout << cc[0] << " " << cc[N-1] << endl;
return 0;
}