zoukankan      html  css  js  c++  java
  • usaco-ariprog1-pass

    这个搜索有趣,需要限定一些东西,不解释,代码就反映了思想:

    /*
    ID: qq104801
    LANG: C++
    TASK: ariprog
    */
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <assert.h>
    #define NMAX 125001
    
    int n,m;
    int k[NMAX],a[NMAX];
    
    void test()
    {    
        FILE *fin = fopen ("ariprog.in", "r");
        FILE *fout = fopen ("ariprog.out", "w"); 
        
        fscanf(fin,"%d",&n);
        fscanf(fin,"%d",&m);
        for (int i=0;i<=2*m*m;i++)
        {
            k[i]=0;
            a[i]=0;
        }
    
        for(int i=0;i<=m;i++)
            for(int j=0;j<=m;j++)
                k[i*i+j*j]=1;
        int index=0;
        for(int i=0;i<=(2*m*m);i++)
        {
            if(k[i]==1)
            {
                a[index++]=i;
                //printf("%d %d
    ",index-1,i);    
            }           
        }
        int b=1,bmax=2*m*m/(n-1);
        int count=0;
        for(;b<=bmax;++b)
        {
            //printf("b:%d
    ",b);
            for(int i=0;a[i]+(n-1)*b<=m*m*2 && i<index;++i)
            {
                bool f=1;
                for(int j=1;j<n && f;++j)
                    if(!k[a[i]+j*b])f=0;
                if(f)
                {
                    //printf("%d %d
    ",a[i],b);
                    fprintf(fout,"%d %d
    ",a[i],b);
                    ++count;
                }
            }
        }
        if(!count)
            fprintf(fout,"NONE
    ");
    
    
        fclose(fin);
        fclose(fout);
    }
    
    main () {    
        test();    
        exit (0);
    }

    测试用例:

    USER: ll tom [qq104801]
    TASK: ariprog
    LANG: C++
    
    Compiling...
    Compile: OK
    
    Executing...
       Test 1: TEST OK [0.003 secs, 4472 KB]
       Test 2: TEST OK [0.003 secs, 4472 KB]
       Test 3: TEST OK [0.008 secs, 4472 KB]
       Test 4: TEST OK [0.003 secs, 4472 KB]
       Test 5: TEST OK [0.022 secs, 4472 KB]
       Test 6: TEST OK [0.065 secs, 4472 KB]
       Test 7: TEST OK [0.556 secs, 4472 KB]
       Test 8: TEST OK [1.258 secs, 4472 KB]
       Test 9: TEST OK [1.104 secs, 4472 KB]
    
    All tests OK.
    
    Your program ('ariprog') produced all correct answers! This is your submission #2 for this problem. Congratulations!
    
    Here are the test data inputs:
    
    ------- test 1 ----
    3
    2
    ------- test 2 ----
    5
    7
    ------- test 3 ----
    14
    10
    ------- test 4 ----
    10
    13
    ------- test 5 ----
    12
    50
    ------- test 6 ----
    18
    100
    ------- test 7 ----
    21
    200
    ------- test 8 ----
    22
    250
    ------- test 9 ----
    25
    250
    
    Keep up the good work!
    Thanks for your submission!
    /***********************************************

    看书看原版,原汁原味。

    不会英文?没关系,硬着头皮看下去慢慢熟练,才会有真正收获。

    没有原书,也要网上找PDF来看。

    网上的原版资料多了去了,下载东西也到原始下载点去看看。

    你会知其所以然,呵呵。

    ***********************************************/

  • 相关阅读:
    安装设置Android Studio Win7安装
    执行对象cocos2dx 2.x action动作整理集合
    查询生成三大框架整合 提示 不能进行查询错误
    一些链接
    成员函数指针与高性能的C++委托
    举例说明Linux不同网段访问的设置办法
    ubuntu 服务管理
    Ubuntu之开机检测硬盘
    Ubuntu 10.04开启字符模式并设置静态IP
    Ubuntu终端ssh连接服务器慢的解决方法
  • 原文地址:https://www.cnblogs.com/dpblue/p/3949122.html
Copyright © 2011-2022 走看看