#include <cstdlib>#include <cstdio>#include <ctime>#include <iostream>using namespace std;int main() { //该程序生成的数据到data.in中 freopen("data.txt", "w", stdout); srand(time(NULL)); //生成1到1000之间的随机整数n和m int n = rand() % 1000 + 1; int m = rand() % 1000 + 1; printf("%d %d\n", n, m); //生成-1000到1000间的数字 for (int i = 1; i <= n; i++) printf("%d ", rand() % 2000 - rand() % 1000); puts(""); for (int i = 1; i <= m; i++) { int x = rand() % n + 1; int y = x + rand() % n + 1; //保证生成的数据是x<=y if (y > n) y = n; printf("%d %d\n", x, y); } return 0;} /*rand()只能生成0到32767之间的随机整数,如果要生成1到50000之间的整数,可以写成:26 rand()%30000+rand()%20000+1*/