传送门

1600: Twenty-four point

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 490  Solved: 78
[Submit][Status][Web Board]

Description

Given four numbers, can you get twenty-four through the addition, subtraction, multiplication, and division? Each number can be used only once.

Input

The input consists of multiple test cases. Each test case contains 4 integers A, B, C, D in a single line (1 <= A, B, C, D <= 13).

Output

For each case, print the “Yes” or “No”. If twenty-four point can be get, print “Yes”, otherwise, print “No”.

Sample Input

2 2 3 9
1 1 1 1
5 5 5 1

Sample Output

Yes
No
Yes

HINT

For the first sample, (2/3+2)*9=24.

Source

 
思路:
dfs,把数组当参数,4个数先选2个算一下,然后变成三个数,传入当下一层,避免了麻烦的选数
 
 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <stack>
#include <cctype>
#include <vector>
#include <cmath>
#include <map>
#include <queue> #define ll long long
#define eps 1e-8 using namespace std; double a[]; int dfs(double p[],int len)
{
if(len==){
if(fabs(p[]-)<eps){
return ;
}
else{
return ;
}
}
double f[];
int cou;
int i,j,k;
for(i = ;i <len-;i++){
for(j=i+;j<len;j++){
cou=;
for(k=;k<len;k++){
if(k!=i && k!=j){
f[cou]=p[k];cou++;
}
}
f[cou]=p[i]+p[j];
if(dfs(f,cou+)) return ;
f[cou]=p[i]-p[j];
if(dfs(f,cou+)) return ;
f[cou]=p[j]-p[i];
if(dfs(f,cou+)) return ;
f[cou]=p[i]*p[j];
if(dfs(f,cou+)) return ;
if(p[j]!=){
f[cou]=p[i]/p[j];
if(dfs(f,cou+)) return ;
}
if(p[i]!=){
f[cou]=p[j]/p[i];
if(dfs(f,cou+)) return ;
}
}
}
return ;
} int main()
{
//freopen("in.txt","r",stdin);
//scanf("%d",&T);
//for(int ccnt=1;ccnt<=T;ccnt++){
while(scanf("%lf%lf%lf%lf",&a[],&a[],&a[],&a[])!=EOF){
if(dfs(a,) == ){
printf("Yes\n");
}
else{
printf("No\n");
}
}
return ;
}

csu 1600: Twenty-four point的更多相关文章

  1. 我叫Twenty,我是要成为博客王的博客框架

    标题套用了路飞的格式,其实我想说的是大多数都不相信你的梦想,直到你快走到了. 不废话了,介绍一下twenty: 这是基于CMS框架 zerojs打造一个博客.zerojs 的架构介绍在这里http:/ ...

  2. SQL 2008升级SQL 2008 R2完全教程或者10.00.1600升级10.50.1600

    http://blog.csdn.net/feng19821209/article/details/8571571 SQL 2008升级SQL 2008 R2完全教程或者10.00.1600升级10. ...

  3. SQL 2008 R2下载 升级R2 SP1或者SQL 2008从10.50.1600升级10.5.2500

    SQL Server 2008 R2 中英文 开发版/企业版/标准版 链接地址 一. 简体中文 1. SQL Server 2008 R2 Developer (x86, x64, ia64) - D ...

  4. Droidicon – 1600+ 漂亮的 Android 图标

    Droidicon 提供超过1600款定制图标,让你可以超级容易的把图标和徽章添加到您的应用程序中.你可以自定义你想要的各种形式的图标,给图标添加描边,透明度和颜色过滤器.包括这些 Google Ma ...

  5. csu 1812: 三角形和矩形 凸包

    传送门:csu 1812: 三角形和矩形 思路:首先,求出三角形的在矩形区域的顶点,矩形在三角形区域的顶点.然后求出所有的交点.这些点构成一个凸包,求凸包面积就OK了. /************** ...

  6. CSU 1503 点到圆弧的距离(2014湖南省程序设计竞赛A题)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1503 解题报告:分两种情况就可以了,第一种是那个点跟圆心的连线在那段扇形的圆弧范围内,这 ...

  7. CSU 1120 病毒(DP)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1120 解题报告:dp,用一个串去更新另一个串,递推方程是: if(b[i] > a ...

  8. CSU 1116 Kingdoms(枚举最小生成树)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1116 解题报告:一个国家有n个城市,有m条路可以修,修每条路要一定的金币,现在这个国家只 ...

  9. CSU 1113 Updating a Dictionary(map容器应用)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1113 解题报告:输入两个字符串,第一个是原来的字典,第二个是新字典,字典中的元素的格式为 ...

随机推荐

  1. map,reduce高阶函数

    iterator:迭代器 python的iterator是一个惰性序列(即你不主动去遍历它,他不会去计算其中元素的值) m是一个iterator,所以通过tuple()函数让整个序列计算出来,并返回一 ...

  2. Failed to obtain lock on file /usr/local/nagios/var/ndo2db.lock: Permission denied : Permission denied

    Failed to obtain lock on file /usr/local/nagios/var/ndo2db.lock: Permission denied  : Permission den ...

  3. Qt中为QPushButton添加背景图片

    有2种方式,一种是在代码中设置,另外一种是直接在Qt Creator中直接设置,下面是第二种 参考: http://doc.qt.io/qt-4.8/stylesheet-examples.html ...

  4. SQLite_安装

    SQLite -安装 zero-configuration SQLite闻名的特性,这意味着不需要复杂的设置或管理.本章将带你通过设置SQLite的过程在Windows.Linux和Mac OS X. ...

  5. Python3简明教程(六)—— 数据结构

    简单的来说,数据结构(data structure)是计算机中存储.组织数据的方式.比如我们之前使用过的列表就是一种数据结构,在这里我们还会深入学习它.之前也有简单的介绍. 列表 >>&g ...

  6. vue 数据没有驱动视图?

    Part.1  问题 数据改变,视图却没有根据数据而改变. 原因在于,数据并不在 vue 监听范围之内,vue 只对事先在 data 中声明的变量丶对象等类型数据进行监听 Part.2  例子 < ...

  7. table、tr、td表格的行、单元格等属性说明

    table.tr.td表格的行.单元格等属性说明 <table>标签定义HTML表格.简单的HTML表格由table元素以及一个或多个tr.th或td元素组成. tr元素定义表格行,th元 ...

  8. log4j.xml 精选的log4j.xml文档,比较详细,网上的版本很多,这个版本相对而言比较完整

    <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE log4j:configuration PUB ...

  9. 全局/局部变量、宏、const、static、extern

    #pragma mark--全局变量和局部变量 根据变量的作用域,变量可以分为: 一.全局变量 1> 定义:在函数外面定义的变量2> 作用域:从定义变量的那一行开始,一直到文件结尾(能被后 ...

  10. 内存区--Java

    一.概述 对于 Java 程序员来说,在虚拟机自动内存管理机制下,不再需要像C/C++程序开发程序员这样为内一个 new 操作去写对应的 delete/free 操作,不容易出现内存泄漏和内存溢出问题 ...