第23次CCF计算机软件能力认证

思路后面再补

第一题

#include <bits/stdc++.h>
using namespace std;

const int maxn = 105;

int n, b[maxn];

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  cin >> n;
  for (int i = 0; i < n; i++) cin >> b[i];

  long long min_ = b[0];
  for (int i = 1; i < n; i++) {
    if (b[i] != b[i-1]) {
      min_ += b[i];
    }
  }
  cout << accumulate(b, b+n, 0LL) << endl;
  cout << min_ << endl;
  return 0;
}

第二题

#include <bits/stdc++.h>
using namespace std;

const int maxn = 5e5 + 5;

int n, a[maxn];
vector<int> pos[10005];

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];

  vector<int> b;
  for (int i = 0; i < n; i++) {
    if (i == 0 || a[i] != a[i-1]) {
      b.push_back(a[i]);
      pos[a[i]].push_back(b.size()-1);
    }
  }

  int maxp = *max_element(b.begin(), b.end());

  int cur = 0;
  for (int i = 0; i < b.size(); i++) {
    if (b[i] != 0 && (i == 0 || b[i-1] == 0)) {
      cur++;
    }
  }

  int ans = cur;

  for (int p = 1; p <= maxp; p++) { // remove p
    vector<int> &cpos = pos[p];
    for (int idx : cpos) {
      b[idx] = 0;
      if (idx - 1 >= 0 && idx + 1 < b.size() && b[idx-1] != 0 && b[idx+1] != 0) {
        cur++;
      } else if ((idx == 0 || b[idx - 1] == 0) && (idx == b.size() - 1 || b[idx + 1] == 0)) {
        cur--;
      }
    }
    ans = max(ans, cur);
  }
  cout << ans << endl;
  return 0;
}

第三题

#include <bits/stdc++.h>
using namespace std;

static unsigned long _next = 1;

/* RAND_MAX assumed to be 32767 */
int myrand(void) {
    _next = _next * 1103515245 + 12345;
    return((unsigned)(_next/65536) % 32768);
}

const int maxt = 1e5 + 5;
const int maxn = 1e3 + 5;

int N, S, P, T;
double dt;

struct Cell {
  double v, u, a, b, c, d;
  int send_time;
};

Cell cells[maxn];
int r[maxn];

struct Edge {
  int s, t;
  double w;
  int D;
};
Edge edges[maxn];

vector<int> G[maxn * 2];

int maxD;

void solve() {
  vector<vector<double>> I(maxD+1, vector<double>(N));

  int mod = maxD + 1;
  for (int k = 0; k < T; k++) {
    // 清空
    for (int i = 0; i < N ; i++) {
      I[(k+maxD) % mod][i] = 0;
    }

    // 脉冲
    for (int i = 0; i < P; i++) {
      int myr = myrand();
      if (r[i] > myr) {
        for (int j = 0; j < G[N+i].size(); j++) {
          Edge& e = edges[G[N+i][j]];
          I[(k+e.D) % mod][e.t] += e.w;
        }
      }
    }

    // 神经元
    for (int i = 0; i < N; i++) {
      // 更新 v 和 u
      double old_v = cells[i].v, old_u = cells[i].u;

      const double a = cells[i].a, b = cells[i].b;
      cells[i].v = old_v + dt * (0.04*old_v*old_v + 5*old_v + 140 - old_u) + I[k % mod][i];
      cells[i].u = old_u + dt * a * (b * old_v - old_u);

      if (cells[i].v >= 30) {
        cells[i].send_time++;
        for (int j = 0; j < G[i].size(); j++) {
          Edge &e = edges[G[i][j]];
          I[(k+e.D) % mod][e.t] += e.w;
        }
        cells[i].v = cells[i].c;
        cells[i].u += cells[i].d;
      }
    }

  }

  double t_max_v = cells[0].v, t_min_v = cells[0].v;
  int t_min_times = cells[0].send_time, t_max_times = cells[0].send_time;
  for (int i = 0; i < N; i++) {
    t_max_v = max(t_max_v, cells[i].v);
    t_min_v = min(t_min_v, cells[i].v);
    t_min_times = min(t_min_times, cells[i].send_time);
    t_max_times = max(t_max_times, cells[i].send_time);
  }
  cout << fixed << setprecision(3) << t_min_v << " " << t_max_v << endl;
  cout << t_min_times << " " << t_max_times << endl;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  cin >> N >> S >> P >> T;
  cin >> dt;
  int sum_rn = 0;
  while (sum_rn < N) {
    int rn;
    double v, u, a, b, c, d;
    cin >> rn >> v >> u >> a >> b >> c >> d;
    for (int i = sum_rn; i < sum_rn + rn; i++) {
      cells[i].v = v;
      cells[i].u = u;
      cells[i].a = a;
      cells[i].b = b;
      cells[i].c = c;
      cells[i].d = d;
      cells[i].send_time = 0;
    }
    sum_rn += rn;
  }
  for (int i = 0; i < P; i++) {
    cin >> r[i];
  }
  for (int i = 0; i < S; i++) {
    cin >> edges[i].s >> edges[i].t >> edges[i].w >> edges[i].D;
    maxD = max(maxD, edges[i].D);
    G[edges[i].s].push_back(i);
  }
  solve();
  return 0;
}

第四题

#include <bits/stdc++.h>
using namespace std;

const int maxstate = 65536 + 5;
const int maxnk = 80 + 5;

int n, k;
double p[20];

int calcCard(int mask) {
  int ret = 0;
  for (int i = 0; i < n; i++) {
    if (mask & (1<<i)) {
      ret++;
    }
  }
  return ret;
}

double dp[maxstate][maxnk];

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> p[i];

  int mask = (1<<n)-1;
  dp[0][0] = 1;
  double ans = 0;
  for (int s = 0; s <= mask; s++) {
    for (int j = 0; j <= n*k; j++) {
      int cards = calcCard(s);
      if (cards + j/k >= n) {
          ans += dp[s][j] * (cards + j);
          continue;
      }
      for (int i = 0; i < n; i++) {
        if (s & (1<<i)) {
          dp[s][j+1] += dp[s][j] * p[i];
        } else {
          dp[s|(1<<i)][j] += dp[s][j] * p[i];
        }
      }
    }
  }
  cout << fixed << ans << endl;
  return 0;
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值