zoukankan      html  css  js  c++  java
  • 如何对拍

    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的配置文件就要写好久诶。

    如果有时间还是学学吧。

    真·放假来袭。

    再见~

  • 相关阅读:
    Java RunTime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. ......
    UVA 1597 Searching the Web
    UVA 1596 Bug Hunt
    UVA 230 Borrowers
    UVA 221 Urban Elevations
    UVA 814 The Letter Carrier's Rounds
    UVA 207 PGA Tour Prize Money
    UVA 1592 Database
    UVA 540 Team Queue
    UVA 12096 The SetStack Computer
  • 原文地址:https://www.cnblogs.com/LoLiK/p/9531022.html
Copyright © 2011-2022 走看看