codeforces 24 Game(数学构造)
2016-07-22 14:55
447 查看
题意:给你一个数字n,1,2,3,4......,n-1,n在一个集合里,每次拿出两个数进行加或者减或者乘三种操作,每次操作结果再放入集合中,问能不能使集合最后剩下的那个数是24!不能输出“NO”,能输出“YES”,并且输出步骤!
分析:题目做着做着越觉得神奇了!!看到这题一头雾水(我还是太年轻了),看了大神的提点,才恍然大悟!!感叹现在人的脑洞真的好大啊!!关键在于凑1!!凑1!!【具体看代码!】
Examples
input
output
input
output
分析:题目做着做着越觉得神奇了!!看到这题一头雾水(我还是太年轻了),看了大神的提点,才恍然大悟!!感叹现在人的脑洞真的好大啊!!关键在于凑1!!凑1!!【具体看代码!】
Examples
input
1
output
NO
input
8
output
YES
8 * 7 = 56
6 * 5 = 30
3 - 4 = -11 - 2 = -130 - -1 = 3156 - 31 = 25
25 + -1 = 24
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; int main() { int n; while(~scanf("%d",&n)) { int i; if(n<4) { printf("NO\n");continue; } printf("YES\n"); if(n%2) { printf("5 * 3 = 15\n"); printf("2 * 4 = 8\n"); printf("15 + 8 = 23\n"); printf("23 + 1 = 24\n"); int cnt=0; for(i=n;i>=7;i-=2) { printf("%d - %d = 1\n",i,i-1);cnt++; } while(cnt--) { printf("24 * 1 = 24\n"); } } else { printf("2 * 3 = 6\n"); printf("6 * 4 = 24\n"); printf("24 * 1 = 24\n"); int cnt=0; for(i=n;i>=6;i-=2) { printf("%d - %d = 1\n",i,i-1);cnt++; } while(cnt--) { printf("24 * 1 = 24\n"); } } } return 0; }
相关文章推荐
- 2016 Multi-University Training Contest 2 1009 It's All In The Mind (贪心)
- 1005. 继续(3n+1)猜想 (25) PAT乙级真题
- mysql 导出表结构和表数据 mysqldump用法
- div 自适应高度 自动填充剩余高度
- linux 操作系统中cp复制命令的使用
- Angualr__directive
- 震惊小伙伴的单行代码(Python篇)
- 《Android 开发工程师面试指南》
- git基础入门
- Multi-thread下对int进行原子操作
- Prototype.js的使用手册
- thread_threadLocal(多线程共享数据)
- Oracle 行迁移 、行链接及优化
- 容器
- Android面试题收集
- HDU 2601 An easy problem (数学)
- SASS
- 树莓派使用DHT11温湿度传感器
- Sublime运行Matlab
- 1025. 反转链表 (25)-浙大PAT乙级真题