• 如何对拍


    idy002老师在放假为我们讲了讲c++的对拍。

    以求1~n的和(n<=1e9)为例:

    需要一个暴力程序(brute.cpp):

    #include <cstdio>
    
    int main() {
    	int n;
    	long long sum = 0;
    	scanf("%d", &n);
    	for(int i = 1; i <= n; i++)
    		sum += i;
    	printf("%I64d
    ", sum);
    }
    
    

    以及一个正确程序(A.cpp):

    #include <cstdio>
    
    int main() {
    	int n;
    	scanf("%d", &n);
    	long long sum = (1 + n) * (long long)n / 2;
    	printf("%I64d
    ", sum);
    }
    
    

    甚至可以是错误程序:

    #include <cstdio>
    #include <cstdlib>
    #include <ctime>
    
    int main() {
    	int n;
    	scanf("%d", &n);
    	srand(time(0));
    	if (rand() % 10 == 1)
    	 n++;
    	long long sum = (1 + n) * (long long)n / 2;
    	printf("%I64d
    ", sum);
    }
    
    

    不可或缺的数据生成器(gen.cpp):

    #include <cstdio>
    #include <cstdlib>
    #include <ctime>
    
    int main() {
    	srand(time(0));
    	printf("%d
    ", rand() % 100000);
    }
    
    

    以及一个对拍程序(dp.cpp):

    程序来自这里

    system就跟cmd差不多?
    大概意思如此吧。

    #include<cstdio>
    #include<cstdlib>
    #include<ctime>
    
    int main()
    {   
        long s,t;
        while(1){
            system("cls");
            do{
                system("gen > input"); //data是数据生成程序
                s=clock();
                system("brute < input > brute.out");  //a是要交的程序
                t=clock();
                system("A < input > A.out");  //b是正确的程序
                if(system("fc brute.out A.out > nul"))
                    break;
                else printf("AC time: %ldms
    ",t-s);
            }while(1);
            printf("WA time: %ldms
    ",t-s);  //运行时间 
            system("fc brute.out A.out");
            system("pause>nul");
        }
        return 0;
    }
    
    

    一切就绪,点击dp.exe即可开始AC(WA WA 机)的旅程。

    考试之前真的有时间写这个吗?

    我写Vim的配置文件就要写好久诶。

    如果有时间还是学学吧。

    真·放假来袭。

    再见~

  • 相关阅读:
    python+django+uwsgi 搭建环境
    python系列-3 pyenv的使用
    生产消费者队列(TaskCompletionSource)的应用
    socket
    Redis 参考
    webform调用windows服务
    文件编码格式获取
    webform版部分视图与请求拦截
    asp.net 自定义节配置 (configSections下的section)
    组合配置草稿
  • 原文地址:https://www.cnblogs.com/LoLiK/p/9531022.html
Copyright © 2020-2023  润新知