HDOJ 5143 NPY and arithmetic progression DFS
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
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?
The next T lines,each contains 4 integers a1,a2,a3,a4(0≤a1,a2,a3,a4≤109).
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}.
/* ***********************************************
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相关推荐
- HDU5142 NPY and arithmetic progression BestCoder Round #23 1002
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5143 解题思路:BestCoder官方题解: 可以发现等差数列只有(123,234,1234和长度&g ...
- Almost Arithmetic Progression
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- Almost Arithmetic Progression(CF-978D)
Problem Description Polycarp likes arithmetic progressions. A sequence [a1,a2,-,an] is called an ari ...
- 奇思妙想构造题 ARC145 D - Non Arithmetic Progression Set
Non Arithmetic Progression Set 大意: 给定m,n 要求构造一个序列: 长度=n,元素和=m,任意三个元素无法构成等差数列,|a[i]|<=1e7 思路: 一开始这 ...
- cf----2019-10-20(Consecutive Subsequence,Almost Arithmetic Progression,Mentors)
一场游戏一场空,最终 最初都由我掌控,好像一身从容,不曾有狼狈伤痛,可深夜一个人该如何相拥? You are given an integer array of length nn. You have ...
- 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 ...
- HDOJ 5144 NPY and shot 简单物理
三分角度.... NPY and shot Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- PAT(甲级)2021年春季考试 7-1 Arithmetic Progression of Primes
思路:用筛除法打素数表(与之相对的是枚举加逐个判断)是降低时间复杂度的第一个点,第二个点是运用上数学技巧,给定了等差数列的范围(2-MAX),给定了个数,那么最大的等差是可以求出的.循环的第一层从最大 ...
- Codeforces Round #224 (Div. 2): C. Arithmetic Progression(模拟)
题意: 给你n个数字,你需要再添加一个数字,使得最后所有数字排序之后任意相邻两个数之差全部相等,问可以添加多少种不同的数字 思路: 一看就是水题但是情况不少,没了 例如所有数字全部相等,只有两个数字, ...
- Arithmetic Progression 题解(随机数使用)
思路: 本题的意思:求首项与公差. 第一部分:观察一下,题目的第二类操作(比某数大,有单调性)明显是要我们用二分(或者我觉得其实随机数也行,根据随机数来不断缩小范围,但是这题练二分)求最大值,大概要操 ...
最新文章
- SQL提示介绍-强制并行
- AndroidTv Home界面实现原理(二)——Leanback 库的主页卡位缩放动画源码解析
- 网络虚拟化技术为双11提供灵动网络
- Qt:Qt实现网页自动刷新工具
- 图论 —— 图的连通性 —— 并查集判断连通性
- Java 面试 1 小时,我看出了和月薪 3w 的差距
- 微信小程序——极点日历使用方法
- cnBlog的windows live writer 客户端配置
- jquery检测input变化_检测jQuery中的输入变化?
- 【转载】.NET系统学习----Assembly
- SPSS统计术语与思维【SPSS 002期】
- 一些简单的java编程题(3) ————小球落地问题
- pikachu逻辑漏洞实验
- 多重检验_LSD方法不准确性
- 计算机经常断开网络,当笔记本电脑经常自动断开网络连接时如何解决问题
- 鼠标拖拽mousemove和移动端touchmove问题
- echarts柱状图的样式调整及应用
- 软件开发README文档书写模板
- 揭秘PLC(四)RTS之服务篇
- 无需打开软件排版设计海报的在线工具!