题目:

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(构造)的更多相关文章

  1. Kubeadm搭建高可用(k8s)Kubernetes v1.24.0集群

    文章转载自:https://i4t.com/5451.html 背景 Kubernetes 1.24新特性 从kubelet中移除dockershim,自1.20版本被弃用之后,dockershim组 ...

  2. 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 ...

  3. Puppet自动化部署-前期环境准备(2)

    在安装Puppet环境之前需要配置好机器的基本配置,如规范网络地址IP.hostname,certname认证名称,ntp时间同步等配置完毕,完善的搭建自动化环境. 1.环境介绍 此处实现部署的环境是 ...

  4. MySQL MMM高可用方案

    200 ? "200px" : this.width)!important;} --> 介绍 本篇文章主要介绍搭建MMM方案以及MMM架构的原理.这里不介绍主从.主主的搭建方 ...

  5. MySQL 第一篇

    一.MySQL介绍 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司.MySQL是一种关联数据库管理系统,关联数据库将数据保存在不同的表中,而不是将所有数 ...

  6. NIS域配置详解

    一.前期准备1.1 NIS 简介NIS,英文的全称是network information service,也叫yellow pages.在Linux中,NIS是一个基于RPC的client/serv ...

  7. salt-master 的配置文件详解

    绑定的地址: interface: 0.0.0.0 master和minion通信端口: publish_port: 4505 可以使用的文件描述符:(每个minion连接master至少需要一个文件 ...

  8. dns 服务器配置

    1.安装 named 2.配置如下文件: /etc/named.conf // 2 // named.conf 3 // 4 // Provided by Red Hat bind package t ...

  9. C#_MySql 主从复制

    一.业务发展驱动数据发展 随着网站业务的不断发展,用户量的不断增加,数据量成倍地增长,数据库的访问量也呈线性地增长.特别是在用户访问高峰期间,并发访问量突然增大,数据库的负载压力也会增大,如果架构方案 ...

随机推荐

  1. Git 如何把master的内容更新到分支

    Background: 当有人对master进行更新之后,你想让已经创建的分支内容更新到master的最新状态, bpan@5CG7022BM2 MINGW64 /d/GitRep/JIRA_Exte ...

  2. iOS-入门HelloWorld

    刚刚搞了几个图形界面的iOS应用程序,难的没搞定一个,HelloWorld程序倒是很简单. 新建Project,iOS->Application->Single View Applicat ...

  3. thymeleaf 教程

    html页面 添加  <html xmlns:th="http://www.thymeleaf.org" > html原有标签都可以用thymeleaf标签替换 1.t ...

  4. Spring Cloud学习笔记【七】服务网关 Zuul(路由)

    Spring Cloud Zuul 路由是微服务架构的不可或缺的一部分,提供动态路由.监控.弹性.安全等的边缘服务.Zuul 是 Netflix 出品的一个基于 JVM 路由和服务端的负载均衡器. 准 ...

  5. ArcGIS api for javascript——图形-增加图形到地图

    描述 本例展示了如何使用Draw工具栏在地图上描绘许多种类的几何体.ArcGIS JavaScript API包含工具栏. 工具栏不是一个在页面上自动地可见的用户界面组件.相反,工具栏是一个助手类,可 ...

  6. 概率dp HDU 3853

    H - LOOPS Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit ci ...

  7. 热门游戏&lt;开心消消乐&gt;的“加壳”诡计!!

    好久没搞游戏了,前几天看了又又一次看了看<开心消消乐>的1.29最新版..于是故事開始了: 1.反编译分析 首先使用Androidkiller进行反编译,得到两个Smali代码目录:mal ...

  8. 【LeetCode-面试算法经典-Java实现】【063-Unique Paths II(唯一路径问题II)】

    [063-Unique Paths II(唯一路径问题II)] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 Follow up for "Unique Pa ...

  9. Redis封装之Set

    RedisSetService: /// <summary> /// Set:用哈希表来保持字符串的唯一性,没有先后顺序,存储一些集合性的数据 /// 1.共同好友.二度好友 /// 2. ...

  10. HDU 4359 Easy Tree DP? 组合数学+动归

    题意:定义一种树,每个节点的权值都是20到2n-1,每个权值出现一次,每个节点的左子树的权值和小于右子树,除非只有一个子树.给你n和d,问有n个节点且恰好深度是d的这种树有多少种. 比赛的时候我没有做 ...