HDU 5143 DFS
分别给出1,2,3,4 a, b, c,d个
问能否组成数个长度不小于3的等差数列。
首先数量存在大于3的可以直接拿掉,那么可以先判是否都是0或大于3的
然后直接DFS就行了,但是还是要注意先判合法能否进入下层递归来减少内存消耗。
/** @Date : 2017-09-27 15:08:23
* @FileName: HDU 5143 DFS.cpp
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8; int ans = 0;
bool dfs(int a, int b, int c, int d)
{
if(ans)
return 1;
if(!a && !b && !c && !d)
return 1;
else if((a==0 || a > 2) && (b==0 || b > 2) && (c==0 || c > 2) && (d==0 || d > 2))
return 1;
else if(a < 0 || b < 0 || c < 0 || d < 0)
return 0;
if(!ans)
ans |= dfs(a - 1, b - 1, c - 1, d - 1);
if(!ans)
ans |= dfs(a - 1, b - 1, c - 1, d);
if(!ans)
ans |= dfs(a, b - 1, c - 1, d - 1);
return ans;
} int main()
{
/*int size = 256 << 20; // 256MB
char *p = (char*)malloc(size) + size;
__asm__("movl %0, %%esp\n" :: "r"(p));*/
int T;
cin >> T;
while(T--)
{
int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d);
ans = 0;
printf("%s\n", dfs(a, b, c, d)?"Yes":"No");
}
return 0;
}
HDU 5143 DFS的更多相关文章
- Snacks HDU 5692 dfs序列+线段树
Snacks HDU 5692 dfs序列+线段树 题意 百度科技园内有n个零食机,零食机之间通过n−1条路相互连通.每个零食机都有一个值v,表示为小度熊提供零食的价值. 由于零食被频繁的消耗和补充, ...
- BestCoder22 1002.NPY and arithmetic progression(hdu 5143) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5143 题目意思:给出 1, 2, 3, 4 的数量,分别为a1, a2, a3, a4,问是否在每个数 ...
- HDU 5877 dfs+ 线段树(或+树状树组)
1.HDU 5877 Weak Pair 2.总结:有多种做法,这里写了dfs+线段树(或+树状树组),还可用主席树或平衡树,但还不会这两个 3.思路:利用dfs遍历子节点,同时对于每个子节点au, ...
- hdu 4751(dfs染色)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4751 思路:构建新图,对于那些两点连双向边的,忽略,然后其余的都连双向边,于是在新图中,连边的点是能不 ...
- HDU 1045 (DFS搜索)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1045 题目大意:在不是X的地方放O,所有O在没有隔板情况下不能对视(横行和数列),问最多可以放多少个 ...
- HDU 1241 (DFS搜索+染色)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1241 题目大意:求一张地图里的连通块.注意可以斜着连通. 解题思路: 八个方向dfs一遍,一边df ...
- HDU 1010 (DFS搜索+奇偶剪枝)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意:给定起点和终点,问刚好在t步时能否到达终点. 解题思路: 4个剪枝. ①dep&g ...
- hdu 1716(dfs)
题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=1716 排列2 Problem Description Ray又对数字的列产生了兴趣:现 ...
- hdu 4705 dfs统计更新节点信息
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4705 #pragma comment(linker, "/STACK:16777216&qu ...
随机推荐
- BeanCreationException报错启动不起来(jar包冲突)
一月 23, 2015 3:46:13 下午 org.apache.catalina.core.AprLifecycleListener init 信息: The APR based Apache T ...
- 结对项目-四则运算出题程序(GUI版)
目录: 一.致搭档(含项目地址) 二.PSP(planning) 三.结对编程中对接口的设计 四.计算模块接口的设计与实现过程 五.计算模块接口部分的性能改进 六.计算模块部分单元测试展示 七.计算模 ...
- angularJS1笔记-(1)-多控制器
前端写好: <div ng-app="myApp"> <div ng-controller="firstController"> < ...
- BUAA软工个人作业Week2-代码复审
一. 代码复审Check List 1.概要部分 代码能符合需求和规格说明么? 对-c的测试: 可以看到程序不支持1000000的数独终局输出,读源码发现常量MaxCounts定义为了100000,导 ...
- Delphi中使用OLE方法操作Excel
首先创建 Excel 对象,使用ComObj: var ExcelApp: Variant; ExcelApp := CreateOleObject( ′Excel.Application′ ); 注 ...
- requests爬取豆瓣热门电视剧
# *_*coding:utf-8 *_* import requests payload = {'key1': 'value1', 'key2': 'value2'} headers = {'use ...
- scrapy-下载器中间件
from faker import Faker class MySpiderMiddleware(object): def __init__(self): self.fake = Faker() de ...
- 检测web服务器指定位置大文件是否存在
在bugscan群里看到有人问有一个大文件,想探测其是否存在.如果使用curl的话,会将整个文件下载到节点,对于扫描没有任何用处,反而浪费了扫描时间. 于是我想到的解决办法是不使用curl,直接用底层 ...
- check the manual that corresponds to your MySQL server version for the right syntax to use near 'type=InnoDB' at line 7
第一种是:解决MySQL的版本问题(我用的是mysql 5.5版本),mysql 5.0版本以后的数据库方言是:org.hibernate.dialect.MySQ5LInnoDBDialect.第二 ...
- CSS3 Selectors All In One
CSS3 Selectors All In One https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors https://www ...