hdu5308 I Wanna Become A 24-Point Master(构造)
题目: pid=5308" target="_blank">http://acm.hdu.edu.cn/showproblem.php? pid=5308
题意:给定N个N,求出将这N个N构造成24的方法。
分析:要是想到用尽量少的N构造出24点((N+N)/N * (N+N)/N * (N+N)/N
* (N*N+N)/N)。然后把多的N构造成0就好办了((N-N)*N*.....)。
代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std; void _15(int n)
{
printf("1 + 2\n");//n+1
printf("4 + 5\n");//n+2
printf("7 + 8\n");//n+3
printf("10 + 11\n");//n+4
printf("%d + 12\n",n+4);//n+5
printf("%d / 3\n",n+1); // n+6 2
printf("%d / 6\n",n+2);//n+7 2
printf("%d / 9\n",n+3);//n+8 2
printf("%d / 13\n",n+5);//n+9 3
printf("14 - 15\n");//n+10 0
int c=n+10;
for(int i=16;i<=n;i++)
{
printf("%d * %d\n",c,i);
c++;
}
printf("%d * %d\n",n+6,n+7); //c+1
printf("%d * %d\n",n+8,c+1); //c+1
printf("%d * %d\n",c+2,n+9);
printf("%d + %d\n",c+3,c);
}
void _14()
{
int s1[100]={1,15,16,17,18,7,9,11,20,21,22,25,26};
int s2[100]={2,3,4,5,6,8,10,12,13,14,19,23,24};
char op[100]="-****+++//+--";
for(int i=0;op[i];i++)
printf("%d %c %d\n",s1[i],op[i],s2[i]);
}
void _13()
{
int s1[100]={1,4,7,10,17,14,15,16,18,19,21,23};
int s2[100]={2,5,8,11,12,3,6,9,13,20,22,24};
char op[100]="+++++////***";
for(int i=0;op[i];i++)
printf("%d %c %d\n",s1[i],op[i],s2[i]);
} void _12()
{
int s1[100]={1,3,5,7,9,11,13,15,17,19,21};
int s2[100]={2,4,6,8,10,12,14,16,18,20,22};
char op[100]="-----++++++";
for(int i=0;op[i];i++)
printf("%d %c %d\n",s1[i],op[i],s2[i]);
}
void _11()
{
int s1[100]={1,12,13,14,15,7,17,9,18,19};
int s2[100]={2,3,4,5,6,8,16,10,11,20};
char op[100]="-****+++/+";
for(int i=0;op[i];i++)
printf("%d %c %d\n",s1[i],op[i],s2[i]);
} void _10()
{
int s1[100]={1,11,4,6,8,13,14,15,17};
int s2[100]={2,3,5,7,9,10,12,16,18};
char op[100]="-++++//++";
for(int i=0;op[i];i++)
printf("%d %c %d\n",s1[i],op[i],s2[i]);
}
void _9()
{
int s1[100]={1,3,4,11,6,8,15,13};
int s2[100]={2,10,5,12,7,14,9,16};
char op[100]="++-+++/-";
for(int i=0;op[i];i++)
printf("%d %c %d\n",s1[i],op[i],s2[i]);
}
void _8()
{
int s1[100]={1,9,10,11,12,13,14};
int s2[100]={2,3,4,5,6,7,8};
char op[100]="-***+++";
for(int i=0;op[i];i++)
printf("%d %c %d\n",s1[i],op[i],s2[i]);
}
void _7()
{
int s1[100]={1,3,4,6,11,12};
int s2[100]={2,8,5,10,7,9};
char op[100]="++++/+";
for(int i=0;op[i];i++)
printf("%d %c %d\n",s1[i],op[i],s2[i]);
}
void _6()
{
int s1[100]={1,3,7,5,9};
int s2[100]={2,4,8,6,10};
char op[100]="+++-+";
for(int i=0;op[i];i++)
printf("%d %c %d\n",s1[i],op[i],s2[i]);
}
void _5()
{
printf("1 * 2\n");
printf("6 * 3\n");
printf("7 - 4\n");
printf("8 / 5\n");
}
void _4()
{
printf("1 * 2\n");
printf("5 + 3\n");
printf("6 + 4\n");
} int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
if(n>=15)
_15(n);
else if(n==14)
_14();
else if(n==13)
_13();
else if(n==12)
_12();
else if(n==11)
_11();
else if(n==10)
_10();
else if(n==9)
_9();
else if(n==8)
_8();
else if(n==7)
_7();
else if(n==6)
_6();
else if(n==5)
_5();
else if(n==4)
_4();
else
printf("-1\n");
}
return 0;
}
hdu5308 I Wanna Become A 24-Point Master(构造)的更多相关文章
- Kubeadm搭建高可用(k8s)Kubernetes v1.24.0集群
文章转载自:https://i4t.com/5451.html 背景 Kubernetes 1.24新特性 从kubelet中移除dockershim,自1.20版本被弃用之后,dockershim组 ...
- Codeforces Round #268 (Div. 1) A. 24 Game 构造
A. 24 Game Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/468/problem/A D ...
- Puppet自动化部署-前期环境准备(2)
在安装Puppet环境之前需要配置好机器的基本配置,如规范网络地址IP.hostname,certname认证名称,ntp时间同步等配置完毕,完善的搭建自动化环境. 1.环境介绍 此处实现部署的环境是 ...
- MySQL MMM高可用方案
200 ? "200px" : this.width)!important;} --> 介绍 本篇文章主要介绍搭建MMM方案以及MMM架构的原理.这里不介绍主从.主主的搭建方 ...
- MySQL 第一篇
一.MySQL介绍 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司.MySQL是一种关联数据库管理系统,关联数据库将数据保存在不同的表中,而不是将所有数 ...
- NIS域配置详解
一.前期准备1.1 NIS 简介NIS,英文的全称是network information service,也叫yellow pages.在Linux中,NIS是一个基于RPC的client/serv ...
- salt-master 的配置文件详解
绑定的地址: interface: 0.0.0.0 master和minion通信端口: publish_port: 4505 可以使用的文件描述符:(每个minion连接master至少需要一个文件 ...
- dns 服务器配置
1.安装 named 2.配置如下文件: /etc/named.conf // 2 // named.conf 3 // 4 // Provided by Red Hat bind package t ...
- C#_MySql 主从复制
一.业务发展驱动数据发展 随着网站业务的不断发展,用户量的不断增加,数据量成倍地增长,数据库的访问量也呈线性地增长.特别是在用户访问高峰期间,并发访问量突然增大,数据库的负载压力也会增大,如果架构方案 ...
随机推荐
- CSU 1364 Interview RMQ
题意: 瑶瑶有一家有一家公司,最近他想招m个人.因为他的公司是如此的出名,所以有n个人来参加面试.然而,瑶瑶是如此忙,以至于没有时间来亲自面试他们.所以他准备选择m场面试来测试他们. 瑶瑶决定这样来安 ...
- Java基础学习总结(9)——this关键字
一.this关键字 this是一个引用,它指向自身的这个对象. 看内存分析图: 假设我们在堆内存new了一个对象,在这个对象里面你想象着他有一个引用this,this指向这个对象自己,所以这就是thi ...
- poj--1637--Sightseeing tour(网络流,最大流判断混合图是否存在欧拉图)
Sightseeing tour Time Limit: 1000MS Memory Limit: 10000KB 64bit IO Format: %I64d & %I64u Sub ...
- centos7 zabbix3.4.6显示中文乱码问题
工具 : winscp (Linux Windows 传输文件工具) 当部署完zabbix然后显示中文会出现如下图 然后此时先去windows的文字目录如 C:\Windows\Fonts 随便托个字 ...
- HDU 5370 Tree Maker
一个显然的结论是,一棵n个结点的二叉树的形态数,是Catalan数第n项.
- Linux企业应用--RHAS 2.1 下安装中文 Lotus Domino R 6.5 图解
原文请到ftp.jms165.com下载,是用上传用户 (RHAS3+ksnapshot+OperOff ...
- JWT 使用介绍
转载收藏于 http://www.cnblogs.com/zjutzz/p/5790180.html JWT是啥? JWT就是一个字符串,经过加密处理与校验处理的字符串,形式为: A.B.C A由JW ...
- python requests请求卡住问题
最近经常接到别人反馈某个爬虫工具程序没有正常运行,需要下载的资讯数据也没有及时进行收录. 刚开始以为可能是机器的问题,偶尔机器会出现程序运行中途卡住的情况. 但随着异常的情况越来越频繁,我便只好去排查 ...
- nodeType 节点的类型
元素结点 1 属性结点 2 attributes 文本结点 3 注释结点 8 document结点 9 documentFragment 11 文档碎片
- PHP和js判断访问终端是否是微信浏览器
http://www.sucaihuo.com/php/813.html http://www.thinkphp.cn/extend/767.html http://blog.csdn.net/gf7 ...