1. #include <cstdlib>
    2. #include <cstdio>
    3. #include <ctime>
    4. #include <iostream>
    5. using namespace std;
    6. int main() {
    7. //该程序生成的数据到data.in中
    8. freopen("data.txt", "w", stdout);
    9. srand(time(NULL));
    10. //生成1到1000之间的随机整数n和m
    11. int n = rand() % 1000 + 1;
    12. int m = rand() % 1000 + 1;
    13. printf("%d %d\n", n, m);
    14. //生成-1000到1000间的数字
    15. for (int i = 1; i <= n; i++)
    16. printf("%d ", rand() % 2000 - rand() % 1000);
    17. puts("");
    18. for (int i = 1; i <= m; i++) {
    19. int x = rand() % n + 1;
    20. int y = x + rand() % n + 1;
    21. //保证生成的数据是x<=y
    22. if (y > n)
    23. y = n;
    24. printf("%d %d\n", x, y);
    25. }
    26. return 0;
    27. }
    28. /*
    29. rand()只能生成0到32767之间的随机整数,如果要生成1到50000之间的整数,可以写成:
    30. 26 rand()%30000+rand()%20000+1
    31. */