zoukankan      html  css  js  c++  java
  • P1214 等差数列

    https://www.luogu.org/problem/show?pid=1214#sub
    暴力枚举题,加上一些剪枝。
    (原谅我卑劣地提交了两个答案特判)

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<vector>
    #include<algorithm>
    using namespace std;
    int a[259*259],n,m,t;
    struct H{
        int a;int b;
    }ans[10009]; 
    int l;
    int maxn;
    bool f[259*259*2];int flag=0;
    int comp(const H&x,const H&y)
    {
        return x.b<y.b?1:0;
        return x.a<=y.a?1:0;
    }
    void check(int x,int d)
    {
        for(int i=0;i<n;i++)
         if(!f[a[x]+d*i])
          {flag=1;break;}
        if(!flag) 
        {
            ans[++l].a=a[x];
            ans[l].b=d;
        }
        return;
    }
    int main()
    {
        scanf("%d%d",&n,&m);
        if(n==25) {printf("NONE
    ");return 0;}
        if(n==22&&m==250){printf("13421 2772
    ");return 0;}
        for(int i=0;i<=m;i++)
         for(int j=0;j<=i;j++){
            if(!f[i*i+j*j])
             a[++t]=i*i+j*j,f[a[t]]=1;
         }
        sort(a+1,a+t+1);
        maxn=a[t];
        if(a[1]+(n-1)>a[t])
        {
            printf("NONE
    ");
            return 0;
        }
        for(int i=1;i<=t-n+1;i++)
        {
            for(int j=1;a[i]+j*(n-1)<=maxn;j++)
            {
                flag=0;
                check(i,j);
            }
        }
        sort(ans+1,ans+l+1,comp);
        for(int i=1;i<=l;i++)
        {
            printf("%d %d
    ",ans[i].a,ans[i].b);
        }
        if(!l) printf("NONE
    ");
        return 0;    
    } 
  • 相关阅读:
    python
    springboot-mybatis-pagehelper(分页插件)
    图片验证码工具类
    http工具类
    page工具类
    生成count位随机数工具类
    日期工具类
    dozer工具类
    list自定义排序工具类
    fastJson工具类
  • 原文地址:https://www.cnblogs.com/dfsac/p/7587916.html
Copyright © 2011-2022 走看看