csu 1600: Twenty-four point
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
#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的更多相关文章
- 我叫Twenty,我是要成为博客王的博客框架
标题套用了路飞的格式,其实我想说的是大多数都不相信你的梦想,直到你快走到了. 不废话了,介绍一下twenty: 这是基于CMS框架 zerojs打造一个博客.zerojs 的架构介绍在这里http:/ ...
- 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. ...
- 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 ...
- Droidicon – 1600+ 漂亮的 Android 图标
Droidicon 提供超过1600款定制图标,让你可以超级容易的把图标和徽章添加到您的应用程序中.你可以自定义你想要的各种形式的图标,给图标添加描边,透明度和颜色过滤器.包括这些 Google Ma ...
- csu 1812: 三角形和矩形 凸包
传送门:csu 1812: 三角形和矩形 思路:首先,求出三角形的在矩形区域的顶点,矩形在三角形区域的顶点.然后求出所有的交点.这些点构成一个凸包,求凸包面积就OK了. /************** ...
- CSU 1503 点到圆弧的距离(2014湖南省程序设计竞赛A题)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1503 解题报告:分两种情况就可以了,第一种是那个点跟圆心的连线在那段扇形的圆弧范围内,这 ...
- CSU 1120 病毒(DP)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1120 解题报告:dp,用一个串去更新另一个串,递推方程是: if(b[i] > a ...
- CSU 1116 Kingdoms(枚举最小生成树)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1116 解题报告:一个国家有n个城市,有m条路可以修,修每条路要一定的金币,现在这个国家只 ...
- CSU 1113 Updating a Dictionary(map容器应用)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1113 解题报告:输入两个字符串,第一个是原来的字典,第二个是新字典,字典中的元素的格式为 ...
随机推荐
- IOS数组
/*******************************************************************************************NSArray ...
- MongoDB最简单的入门教程之二 使用nodejs访问MongoDB
在前一篇教程 MongoDB最简单的入门教程之一 环境搭建 里,我们已经完成了MongoDB的环境搭建. 在localhost:27017的服务器上,在数据库admin下面创建了一个名为person的 ...
- (转)Spring4.2.5+Hibernate4.3.11+Struts2.3.24整合开发
http://blog.csdn.net/yerenyuan_pku/article/details/52902851 前面我们已经学会了Spring4.2.5+Hibernate4.3.11+Str ...
- oracle的Hint
与优化器模式相关的Hint 1 ALl_ROWS 让优化器启用CBO /*+ all_rows */ 2 first_rows(n) 让优化器启用CBO 模式,而且得到目标sql的执行计 ...
- sysUpload.vue上传组件 的时候 看进度的时候 不要mock 注释掉 // if (process.env.NODE_ENV !== 'production') require('@/mock')
上传组件 的时候 看进度的时候 不要mock 注释掉 // if (process.env.NODE_ENV !== 'production') require('@/mock') <!-- * ...
- HTML基础(二)列表标签
无序列表ul ul标签的格式为 <ul> <li>内容1</li> <li>内容2</li> <li>内容3</li> ...
- http协议基本认证Authorization
http协议是无状态的, 浏览器和web服务器之间可以通过cookie来身份识别. 桌面应用程序(比如新浪桌面客户端, skydrive客户端)跟Web服务器之间是如何身份识别呢? 什么是HTTP基本 ...
- java基本框架
public class 文件名 { public static void mian(string[] args) { 自己的代码: } }
- 复制webp图片到word || 微信webp图片不能复制 || 如何复制webp到word
用IE浏览器打开Alt+A 复制直接去word粘贴, 用IE浏览器打开Alt+A 复制直接去word粘贴 用IE浏览器打开Alt+A 复制直接去word粘贴 用IE浏览器打开Alt+A 复制直接去wo ...
- POJ-1002-487-3279(字符串)
487-3279 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 309685 Accepted: 55292 Descripti ...