题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5143

题目意思:给出 1, 2, 3, 4 的数量,分别为a1, a2, a3, a4,问是否在每个数只使用一次的前提下,分成若干部分,每部分数的长度 >= 3且满足是等差数列。可以的话输出 Yes ,否则 No 。

  比赛的时候过了pretest,那个开心啊~~然后跟 XX 兽讨论了之后,才发现自己理解错了题目= =

  要用到深搜,问组合嘛~~组合就是有可能是(1, 2, 3, 4)、(1, 2, 3)、(2, 3, 4) 与 cnt[1] >= 3 || cnt[1] == 0 { (1, 1, 1), (0)}  ,cnt[2] >= 3 || cnt[2] == 0,cnt[3] >= 3 || cnt[3] == 0, cnt[4] >= 3 || cnt[4] == 0 的组合。

  cnt[i] 表示数字 i 的数量有cnt[i]个。其实总共有16种情况。

  0 0 0 0,  0 0 0 3,  0 0 3 0,  0 0 3 3

  0 3 0 0,  0 3 0 3,  0 3 3 0,  0 3 3 3

  3 0 0 0,  3 0 0 3,  3 0 3 0,  3 0 3 3

  3 3 0 0,  3 3 0 3,  3 3 3 0,  3 3 3 3

  注意:填 3 的那些位置实际上 >= 3 都符合条件的。然后跟(1, 2, 3, 4)、(1, 2, 3)、(2, 3, 4) 组合

  

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; bool dfs(int a, int b, int c, int d)
{
if ((a >= || !a) && (b >= || !b) && (c >= || !c) && (d >= || !d))// (1,1,1),(2,2,2), (3,3,3), (4,4,4) 的组合
return true;
if (a >= && b >= && c >= && d >= ) // (1, 2, 3, 4)
{
if (dfs(a-, b-, c-, d-))
return true;
}
if (a >= && b >= && c >= ) // (1, 2, 3)
{
if (dfs(a-, b-, c-, d))
return true;
}
if (b >= && c >= && d >= ) // (2, 3, 4)
{
if (dfs(a, b-, c-, d-))
return true;
}
return false;
} int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
int T, ta, tb, tc, td;
while (scanf("%d", &T) != EOF)
{
while (T--)
{
scanf("%d%d%d%d", &ta, &tb, &tc, &td);
printf("%s\n", dfs(ta, tb, tc, td) ? "Yes" : "No");
}
return ;
}
}

BestCoder22 1002.NPY and arithmetic progression(hdu 5143) 解题报告的更多相关文章

  1. BestCoder6 1002 Goffi and Squary Partition(hdu 4982) 解题报告

    题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?pid=1002&cid=530 (格式有一点点问题,直接粘 ...

  2. BestCoder16 1002.Revenge of LIS II(hdu 5087) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5087 题目意思:找出第二个最长递增子序列,输出长度.就是说,假如序列为 1 1 2,第二长递增子序列是 ...

  3. HDU 5143 NPY and arithmetic progression(思维)

    http://acm.hdu.edu.cn/showproblem.php?pid=5143 题意: 给定数字1,2,3,4.的个数每个数字能且仅能使用一次,组成多个或一个等差数列(长度大于等于3), ...

  4. BestCoder20 1002.lines (hdu 5124) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5124 题目意思:给出 n 条线段,每条线段用两个整数描述,对于第 i 条线段:xi,yi 表示该条线段 ...

  5. BestCoder18 1002.Math Problem(hdu 5105) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5105 题目意思:给出一个6个实数:a, b, c, d, l, r.通过在[l, r]中取数 x,使得 ...

  6. BestCoder17 1002.Select(hdu 5101) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5101 题目意思:给出 n 个 classes 和 Dudu 的 IQ(为k),每个classes 都有 ...

  7. BestCoder15 1002.Instruction(hdu 5083) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5083 题目意思:如果给出 instruction 就需要输出对应的 16-bit binary cod ...

  8. BestCoder12 1002.Help him(hdu 5059) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5059 题目意思:就是输入一行不多于 100 的字符串(除了'\n' 和 '\r' 的任意字符),问是否 ...

  9. BestCoder10 1002 Revenge of GCD(hdu 5019) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5019 题目意思:给出 X 和 Y,求出 第 K 个 X 和 Y 的最大公约数. 例如8 16,它们的公 ...

随机推荐

  1. java读写excel文件

    近期处理的数据规模比较大,正好又是统计合并的事情,想着借助excel就可以完成了,然后就了解了下java读取excel的事情. 读取的文件主要分两类:xls文件.xlsx文件.xls文件的相关操作用的 ...

  2. Object&&String学习

    Object类 列表项 String类 常用方法 构造方法 public String() public String(byte[] bytes) public String(byte[]bytes, ...

  3. FireBug调试工具笔记

         Firebug是网页浏览器 Mozilla Firefox下的一款开发类插件, 现属于Firefox的五星级强力推荐插件之一.它集HTML查看和编辑.Javascript控制台.网络状况监视 ...

  4. Python XML解析(转载)

    Python XML解析 什么是XML? XML 指可扩展标记语言(eXtensible Markup Language). 你可以通过本站学习XML教程 XML 被设计用来传输和存储数据. XML是 ...

  5. hadoop2.7.1安装

    Hadoop2.7.1安装与配置 http://www.oschina.net/question/117352_247251 http://www.cnblogs.com/wayne1017/arch ...

  6. python 爬虫1

    简单访问有道词典的翻译界面,将页面翻译功能简单呈现 import urllib.request import urllib.parse import json content = input(&quo ...

  7. 外网主机访问虚拟机下的web服务器(NAT端口转发)

    主机:系统win7,ip地址172.18.186.210 虚拟机:VMware Workstation 7,虚拟机下安装了Centos操作系统,ip地址是192.168.202.128,部署了LAMP ...

  8. iOS开发——网络篇——NSURLSession,下载、上传代理方法,利用NSURLSession断点下载,AFN基本使用,网络检测,NSURLConnection补充

    一.NSURLConnection补充 前面提到的NSURLConnection有些知识点需要补充 NSURLConnectionDataDelegate的代理方法有一下几个 - (void)conn ...

  9. iOS开发——UI基础-按钮的创建和设置

    @interface ViewController () - (IBAction)customBtnClick; @end @implementation ViewController - (void ...

  10. 跟着百度学PHP[4]OOP面对对象编程-7-OOP的一些关键子讲解

    面对对象常用的一些关键子:http://www.cnblogs.com/xishaonian/p/6146794.html排版不是很好望见谅. THE END