首页 > 编程知识 正文

脉冲神经网络,脉冲神经网络代码

时间:2023-05-06 12:33:16 阅读:242186 作者:1395

文章目录 C++总结


本题链接:202109-3 脉冲神经网络

本博客给出本题截图

C++ #include <iostream>#include <cstring>#include <algorithm>using namespace std;const int N = 2010;const double INF = 1e8;int n, s, p, T;double dt;int h[N], e[N], D[N], ne[N], idx;double W[N], v[N], u[N], a[N], b[N], c[N], d[N];int r[N], cnt[N];double I[1024][N / 2];static unsigned long _next = 1;/* RAND_MAX assumed to be 32767 */int myrand(void) { _next = _next * 1103515245 + 12345; return((unsigned)(_next/65536) % 32768);}void add(int a, int b, double c, int d){ e[idx] = b, W[idx] = c, D[idx] = d, ne[idx] = h[a], h[a] = idx ++ ;}int main(){ memset(h, -1, sizeof h); scanf("%d%d%d%d", &n, &s, &p, &T); scanf("%lf", &dt); for (int i = 0; i < n;) { int rn; scanf("%d", &rn); double vv, wjdyet, aa, bb, cc, dd; scanf("%lf%lf%lf%lf%lf%lf", &vv, &wjdyet, &aa, &bb, &cc, &dd); for (int j = 0; j < rn; j ++, i ++ ) { v[i] = vv, u[i] = wjdyet, a[i] = aa, b[i] = bb, c[i] = cc, d[i] = dd; } } for (int i = n; i < n + p; i ++ ) scanf("%d", &r[i]); int mod = 0; while (s -- ) { int a, b, d; double c; scanf("%d%d%lf%d", &a, &b, &c, &d); add(a, b, c, d); mod = max(mod, d + 1); } for (int i = 0; i < T; i ++ ) { int t = i % mod; for (int j = n; j < n + p; j ++ ) if (r[j] > myrand()) { for (int k = h[j]; ~k; k = ne[k]) { int x = e[k]; I[(t + D[k]) % mod][x] += W[k]; } } for (int j = 0; j < n; j ++ ) { double vv = v[j], wjdyet = u[j]; v[j] = vv + dt * (0.04 * vv * vv + 5 * vv + 140 - wjdyet) + I[t][j]; u[j] = wjdyet + dt * a[j] * (b[j] * vv - wjdyet); if (v[j] >= 30) { for (int k = h[j]; ~k; k = ne[k]) { int x = e[k]; I[(t + D[k]) % mod][x] += W[k]; } cnt[j] ++ ; v[j] = c[j], u[j] += d[j]; } } memset(I[t], 0, sizeof I[t]); } double minv = INF, maxv = -INF; int minc = INF, maxc = -INF; for (int i = 0; i < n; i ++ ) { minv = min(minv, v[i]); maxv = max(maxv, v[i]); minc = min(minc, cnt[i]); maxc = max(maxc, cnt[i]); } printf("%.3lf %.3lfn", minv, maxv); printf("%d %dn", minc, maxc); return 0;}
总结

第三题日常的大模拟,比较难的一道模拟题
练习这种题能提高自己的码代码能力,不过考场这种题提交WA后是真的上头
按照要求一点一点实现题目要求,大模拟题值得反复去练习
读者可以尝试一个 稍微 简单一些的大模拟:202104-3 DHCP服务器

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。