DFS.....

多余3个的数可以自己成等比数列

和其他数组合成等比数列的有1,2,3,  2,3,4  1,2,3,4 三种情况

NPY and arithmetic progression

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 189    Accepted Submission(s): 61

Problem Description
NPY is learning arithmetic progression in his math class. In mathematics, an arithmetic progression (AP) is a sequence of numbers such that the difference between the consecutive terms is constant.(from wikipedia)
He thinks it's easy to understand,and he found a challenging problem from his talented math teacher:
You're given four integers, a1,a2,a3,a4, which are the numbers of 1,2,3,4 you have.Can you divide these numbers into some Arithmetic Progressions,whose lengths are equal to or greater than 3?(i.e.The number of AP can be one)
Attention: You must use every number exactly once.
Can you solve this problem?
Input
The first line contains a integer T — the number of test cases (1≤T≤100000).
The next T lines,each contains 4 integers a1,a2,a3,a4(0≤a1,a2,a3,a4≤109).
Output
For each test case,print "Yes"(without quotes) if the numbers can be divided properly,otherwise print "No"(without quotes).
Sample Input
3 1 2 2 1 1 0 0 0 3 0 0 0
Sample Output
Yes No Yes

Hint

In the first case,the numbers can be divided into {1,2,3} and {2,3,4}. In the second case,the numbers can't be divided properly. In the third case,the numbers can be divided into {1,1,1}.

Source
BestCoder Round #22
/* ***********************************************
Author        :CKboss
Created Time  :2014年12月13日 星期六 23时09分55秒
File Name     :B_2.cpp
************************************************ */#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>using namespace std;bool flag;bool ck(int a,int b,int c,int d)
{/// checkif(a==0&&b==0&&c==0&&d==0) return true;if( ((a!=0&&a>=3)||(a==0)) && ((b!=0&&b>=3)||(b==0)) && ((c!=0&&c>=3)||(c==0)) && ((d!=0&&d>=3)||(d==0)) ) return true;if(a-1>=0&&b-1>=0&&c-1>=0&&d-1>=0)if(ck(a-1,b-1,c-1,d-1)) return true;if(a-1>=0&&b-1>=0&&c-1>=0)if(ck(a-1,b-1,c-1,d)) return true;if(b-1>=0&&c-1>=0&&d-1>=0)if(ck(a,b-1,c-1,d-1)) return true;return false;
}int main()
{//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);int T_T;scanf("%d",&T_T);while(T_T--){int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);if(ck(a,b,c,d)==true) puts("Yes");else puts("No");}return 0;
}

HDOJ 5143 NPY and arithmetic progression DFS相关推荐

  1. HDU5142 NPY and arithmetic progression BestCoder Round #23 1002

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5143 解题思路:BestCoder官方题解: 可以发现等差数列只有(123,234,1234和长度&g ...

  2. Almost Arithmetic Progression

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  3. Almost Arithmetic Progression(CF-978D)

    Problem Description Polycarp likes arithmetic progressions. A sequence [a1,a2,-,an] is called an ari ...

  4. 奇思妙想构造题 ARC145 D - Non Arithmetic Progression Set

    Non Arithmetic Progression Set 大意: 给定m,n 要求构造一个序列: 长度=n,元素和=m,任意三个元素无法构成等差数列,|a[i]|<=1e7 思路: 一开始这 ...

  5. cf----2019-10-20(Consecutive Subsequence,Almost Arithmetic Progression,Mentors)

    一场游戏一场空,最终 最初都由我掌控,好像一身从容,不曾有狼狈伤痛,可深夜一个人该如何相拥? You are given an integer array of length nn. You have ...

  6. hdoj - 1258 Sum It Up hdoj - 1016 Prime Ring Problem (简单dfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=1258 关键点就是一次递归里面一样的数字只能选一次. 1 #include <cstdio> 2 #i ...

  7. HDOJ 5144 NPY and shot 简单物理

    三分角度.... NPY and shot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  8. PAT(甲级)2021年春季考试 7-1 Arithmetic Progression of Primes

    思路:用筛除法打素数表(与之相对的是枚举加逐个判断)是降低时间复杂度的第一个点,第二个点是运用上数学技巧,给定了等差数列的范围(2-MAX),给定了个数,那么最大的等差是可以求出的.循环的第一层从最大 ...

  9. Codeforces Round #224 (Div. 2): C. Arithmetic Progression(模拟)

    题意: 给你n个数字,你需要再添加一个数字,使得最后所有数字排序之后任意相邻两个数之差全部相等,问可以添加多少种不同的数字 思路: 一看就是水题但是情况不少,没了 例如所有数字全部相等,只有两个数字, ...

  10. Arithmetic Progression 题解(随机数使用)

    思路: 本题的意思:求首项与公差. 第一部分:观察一下,题目的第二类操作(比某数大,有单调性)明显是要我们用二分(或者我觉得其实随机数也行,根据随机数来不断缩小范围,但是这题练二分)求最大值,大概要操 ...

最新文章

  1. SQL提示介绍-强制并行
  2. AndroidTv Home界面实现原理(二)——Leanback 库的主页卡位缩放动画源码解析
  3. 网络虚拟化技术为双11提供灵动网络
  4. Qt:Qt实现网页自动刷新工具
  5. 图论 —— 图的连通性 —— 并查集判断连通性
  6. Java 面试 1 小时,我看出了和月薪 3w 的差距
  7. 微信小程序——极点日历使用方法
  8. cnBlog的windows live writer 客户端配置
  9. jquery检测input变化_检测jQuery中的输入变化?
  10. 【转载】.NET系统学习----Assembly
  11. SPSS统计术语与思维【SPSS 002期】
  12. 一些简单的java编程题(3) ————小球落地问题
  13. pikachu逻辑漏洞实验
  14. 多重检验_LSD方法不准确性
  15. 计算机经常断开网络,当笔记本电脑经常自动断开网络连接时如何解决问题
  16. 鼠标拖拽mousemove和移动端touchmove问题
  17. echarts柱状图的样式调整及应用
  18. 软件开发README文档书写模板
  19. 揭秘PLC(四)RTS之服务篇
  20. 无需打开软件排版设计海报的在线工具!

热门文章

  1. C++验证奇偶性时求余运算%和位运算的速度比较
  2. 计算机专业文献阅读报告,文献阅读报告范本.doc
  3. 如何自动生成目录,并设置目录格式(一看就懂)
  4. 什么是自动化与自主化?
  5. 用纯CSS实现优惠券剪卡风格
  6. 本源量子计算机云平台,本源量子计算云平台
  7. 星光不问赶路人,时光不负奇舞团
  8. 阿里云ACA、ACP、ACE认证考试区别,报名入口及模拟试题分享
  9. 人脸识别权威评测和人脸识别技术现状
  10. 【CSS】学习iview的icon样式+font字体