求复杂度
  • 板块灌水区
  • 楼主lucy2012
  • 当前回复20
  • 已保存回复20
  • 发布时间2024/9/8 22:14
  • 上次更新2024/9/9 14:22:17
查看原帖
求复杂度
1252442
lucy2012楼主2024/9/8 22:14
#include <iostream>
#include <map>
#include <cmath>
using namespace std;

const int maxn = 25;

int main() {
    int n, m;
    cin >> n >> m;
    map<int, int> d[maxn];
    for (int i = 1, opt, x, y; i <= m; i++) {
        cin >> opt >> x >> y;
        if (opt == 1)
            d[y][x] = 1;
        else
            d[y][x] = -1;
    }
    int bas, sum = 0;
    for (int i = 0; i < n; i++) {
        bas = 0;
        for (int j = 1; j <= n; j++) {
            bas += d[j][i];
            if (i == 0 && bas == 0)
                sum++;
            else
                sum += pow(bas, i);
        }
    }
    cout << sum << endl;
    return 0;
}
2024/9/8 22:14
加载中...