zoukankan      html  css  js  c++  java
  • hdu 5143 NPY and arithmetic progression(暴力枚举)

    http://acm.hdu.edu.cn/showproblem.php?pid=5143

    题意 : 有一定数量的 1 2 3 4 

              要求每三个或以上数字组成等差数列 每个数字用一次

              问是否能把数字都用完

    思路: 等差数列的可能有 1 2 3  ,  2 3 4 ,1 2 3 4, 或者三个或以上的常数列

             如果前三种数列有三个以上就能组成常数列

             所以我们从0到2 枚举 只要剩下的数字全都 等于0 或者大于等于3 就能满足条件

             (想到就能轻松解决 可惜每次都要看题解才知道怎么搞= =)

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    
    bool ok(int a[])
    {
        if((a[0]==0||a[0]>=3)&&(a[1]==0||a[1]>=3)&&(a[2]==0||a[2]>=3)&&(a[3]==0||a[3]>=3))
            return true;
        return false;
    }
    int main()
    {
        int a[10],b[10];
        int n;
        int i,j,k;
        scanf("%d",&n);
        while(n--)
        {
            scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3]);
            if(ok(a)) printf("Yes
    ");
            else
            {
                int ok1=0;
                for(i=0;i<=2;i++)
                {
                    for(j=0;j<=2;j++)
                    {
                        for(k=0;k<=2;k++)
                        {
                            b[0]=a[0]-i-j;
                            b[1]=a[1]-i-j-k;
                            b[2]=a[2]-i-j-k;
                            b[3]=a[3]-i-k;
                            if(ok(b)) ok1=1;
                        }
                    }
                }
                if(ok1) printf("Yes
    ");
                else printf("No
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    迪杰斯特拉 优先队列 模板
    UVa 12186 树形dp
    树形dp总结
    codeforces 746C 模拟
    2017西安网络赛 F
    北京师范大学校赛C
    UVA 1584 字符串
    状压dp入门第一题 poj3254
    2017ICPC/广西邀请赛1005(水)HDU6186
    2017ICPC/广西邀请赛1001(水)HDU6181
  • 原文地址:https://www.cnblogs.com/sola1994/p/4249521.html
Copyright © 2011-2022 走看看