一份随机生成数据的代码(要多试几遍),帮助调试
查看原帖
一份随机生成数据的代码(要多试几遍),帮助调试
341864
sgxsz楼主2024/9/23 16:43
#include <bits/stdc++.h>
using namespace std;

int main() {
	freopen("P9118.in","w",stdout);
    srand(time(0));
    int n = rand() % 50000 + 1;
    int m = rand() % 100 + 1;
    int c = rand() % 10 + 1;

    cout << n << " " << m << " " << c << endl;

    for(int i=0; i<m; i++) {
        int op = rand()%3 + 1;
        if(op == 1 || op == 2) {
            int x = rand() % n + 1;
            int p = rand() % c + 1;
            cout << op << " " << x << " " << p << endl;
        } else {
            int x = rand() % (n-1) + 2; // x in the range [2, n]
            int y = (x == n) ? x-1 : x+1; // y = x-1 if x=n, else y = x+1
            cout << op << " " << x << " " << y << endl;
        }
    }
	
    return 0;
}
2024/9/23 16:43
加载中...