zoukankan      html  css  js  c++  java
  • 对拍程序

    对拍程序就是比较两个程序的输出是否一致

    P1144 最短路计数当例子

    先写个构造数据的程序 

    #include <stdio.h>
    #include<cstring>
    #include<ctime>
    #include<cstdlib>
    #include<algorithm>
    #include<iostream>
    #define mx ((int)1e9)
    using namespace std;
    
    char name[30],cmd[30];
    int a[66666];
    void pp(int n)
    {
        printf("%d
    ",rand()%(n/3)+n/3*2);
    }
    int main()
    {
        srand(time(0));
        for(int i=1;i<=1;i++)
        {
            //sprintf(name,"data%d.in",i);
            //freopen(name,"w",stdout);
            cout << "100 1000" <<endl;
            for(int j=1;j<=1000;j++)
            {
                int x,y;
                if(j<100)
                {
                    x=j+1;
                    y=rand()%(j)+1;
                }
                else
                {
                    x=rand()%100+1;
                    y=rand()%100+1;
                }
                printf("%d %d
    ",x,y);
            }
     
            //fclose(stdout);
            //sprintf(cmd,"./number <data%d.in >data%d.out",i,i);
            //system(cmd);
        }
    }

    再写两个解问题的代码

    一个暴力一个正解

    正解

    #include<iostream>
    #include<algorithm>
    #include<cstdlib>
    #include<cstdio>
    #include<cstring>
    #include<vector>
    #include<queue>
    #include<cmath>
    #include<set>
    #include<map>
    #include<complex>
    #define T 111111
    #define M 100003
    using namespace std;
    int sc()
    {
        int i=0; char c=getchar();
        while( c>'9' || c<'0' ) c=getchar();
        while( c>='0'&& c<='9') i=i*10+c-'0',c=getchar();
        return i;
    }
    int f[T],dis[T],mark[T],q[T];
    vector<int>e[T];
    int n,m,l,r;
    int main()
    {
        //freopen("map.in","r",stdin);
        //freopen("map.out","w",stdout);
        n=sc(); m=sc();
        for(int i=1; i<=m; i++)
        {
            int x=sc(),y=sc();
            e[x].push_back(y);
            e[y].push_back(x);
        }
        q[1]=1; l=1; r=2;
        memset(dis,11,sizeof(dis));
        mark[1]=dis[1]=f[1]=1;
        while( l<r )
        {
            int k=q[l++];
            for(int i=0; i<e[k].size(); i++)
                if( dis[e[k][i]]>dis[k] )
                {
                    dis[e[k][i]]=dis[k]+1;
                    f[e[k][i]]+=f[k];
                    f[e[k][i]]%=M;
                    if(!mark[e[k][i]])
                    {
                        mark[e[k][i]]=1;
                        q[r++]=e[k][i];
                    }
                }
        }
        for(int i=1; i<=n; i++) printf("%d
    ",f[i]%M);
        return 0;
    }

    暴力

    /** @file map.cpp
     *  This is an implementation file for a precompiled header.
     */
    
    /* LANG can be C++11 or C++14 for those more recent releases */
    
    // 17.4.1.2 Headers
    
    // C
    
    #ifndef _GLIBCXX_NO_ASSERT
    #include <cassert>
    #endif
    
    #include <cctype>
    #include <cerrno>
    #include <cfloat>
    #include <ciso646>
    #include <climits>
    #include <clocale>
    #include <cmath>
    #include <csetjmp>
    #include <csignal>
    #include <cstdarg>
    #include <cstddef>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <ctime>
    
    #if __cplusplus >= 201103L
    #include <ccomplex>
    #include <cfenv>
    #include <cinttypes>
    #include <cstdalign>
    #include <cstdbool>
    #include <cstdint>
    #include <ctgmath>
    #include <cwchar>
    #include <cwctype>
    #endif
    
    // C++
    
    #include <algorithm>
    #include <bitset>
    #include <complex>
    #include <deque>
    #include <exception>
    #include <fstream>
    #include <functional>
    #include <iomanip>
    #include <ios>
    #include <iosfwd>
    #include <iostream>
    #include <istream>
    #include <iterator>
    #include <limits>
    #include <list>
    #include <locale>
    #include <map>
    #include <memory>
    #include <new>
    #include <numeric>
    #include <ostream>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <stdexcept>
    #include <streambuf>
    #include <string>
    #include <typeinfo>
    #include <utility>
    #include <valarray>
    #include <vector>
    
    #if __cplusplus >= 201103L
    #include <array>
    #include <atomic>
    #include <chrono>
    #include <condition_variable>
    #include <forward_list>
    #include <future>
    #include <initializer_list>
    #include <mutex>
    #include <random>
    #include <ratio>
    #include <regex>
    #include <scoped_allocator>
    #include <system_error>
    #include <thread>
    #include <tuple>
    #include <typeindex>
    #include <type_traits>
    #include <unordered_map>
    #include <unordered_set>
    #endif
    using namespace std;
    const int maxn=1e5+50,maxm=2e5+50,modp=100003;
    int n,m,head[maxn],cnt,vis[maxn],dis[maxn];
    struct edge{
    	int fr,ne,to;
    }e[maxm*2];
    void add(int u,int v)
    {
    	e[++cnt].fr=u;
    	e[cnt].ne=head[u];
    	e[cnt].to=v;
    	head[u]=cnt;
    }
    queue<int>q;
    void bfs()
    {
    	q.push(1);
    	vis[1]=1;
    	dis[1]=0;
    	int u,fr,to;
    	while(!q.empty())
    	{
    		u=q.front();q.pop();
    		for(int i=head[u];i;i=e[i].ne)
    		{
    			fr=e[i].fr;to=e[i].to;
    			if((to!=1&&!dis[to]))
    			{
    				dis[to]=dis[fr]+1;
    				q.push(to);
    			}
    			if(dis[fr]+1==dis[to])
    			{
    				vis[to]+=vis[fr];
    				vis[to]%=modp;
    			}
    		}
    	}
    }
    int main()
    {
    	//freopen("map.in","r",stdin);
    	//freopen("map.out","w",stdout);
    	scanf("%d%d",&n,&m);
    	for(int i=1,u,v;i<=m;i++)
    	{
    		scanf("%d%d",&u,&v);
    		add(u,v);add(v,u);
    	}
    	bfs();
    	for(int i=1;i<=n;i++)
    	{
    		printf("%d
    ",vis[i]);
    	}
    }

    对拍程序

    #include<windows.h>
    #include<iostream>
    #include<cstdio>
    using namespace std;
    int main()
    {
    	int t=100;
    	while(t--)
    	{
    		system("a > a.in");//a是生成数据的程序//a.in读入文件
    		system("map < a.in > 1.out");map是正解//out两个输出文件
    		system("1   < a.in > 2.out");1是暴力
    		if(system("fc 1.out 2.out")) break;
    	}
    	system("pause");
    	return 0;
    }
    最后生成4个exe放到同个文件夹运行对拍的exe


  • 相关阅读:
    python之路_初始mysql数据库
    python之路_并发编程之IO模型
    python之路_并发编程之协程
    python之路_并发编程之多线程2
    python之路_并发编程之多线程1
    python之路_并发编程之多进程3
    python之路_并发编程之多进程2
    python之路_并发编程之多进程1
    python之路_基于udp协议编程
    python之路_基于tcp协议的粘包现象
  • 原文地址:https://www.cnblogs.com/1436177712qqcom/p/9278236.html
Copyright © 2011-2022 走看看