2015多校联合第二场5308I Wanna Become A 24-Point Master

Problem Description
Recently Rikka falls in love with an old but interesting game -- 24 points. She wants to become a master of this game, so she asks Yuta to give her some problems to practice.

Quickly, Rikka solved almost all of the problems but the remained one is really difficult:

In this problem, you need to write a program which can get 24 points with  n  numbers, which are all equal to  n .
 

Input
There are no more then 100 testcases and there are no more then 5 testcases with  n100 . Each testcase contains only one integer  n (1n105)
 

Output
For each testcase:

If there is not any way to get 24 points, print a single line with -1.

Otherwise, let  A  be an array with  2n1  numbers and at firsrt  Ai=n (1in) . You need to print  n1  lines and the  i th line contains one integer  a , one char  b and then one integer c, where  1a,c<n+i  and  b  is "+","-","*" or "/". This line means that you let  Aa  and  Ac  do the operation  b  and store the answer into  An+i .

If your answer satisfies the following rule, we think your answer is right:

1.  A2n1=24

2. Each position of the array  A  is used at most one tine.

3. The absolute value of the numerator and denominator of each element in array  A  is no more than  109
 

Sample Input
  
  
4
 

Sample Output
  
  
1 * 2 5 + 3 6 + 4
 

Author
XJZX
 

Source

好歹这个题看明白问啥了 ̄□ ̄|| 一丢丢思路都没有啊啊啊啊啊啊 度娘告诉我 要构造要手动拆 好吧你赢了 小数可以手动拆 大数呢 又说可以构造24 how?

(4*n/n)*(6*n/n)=24  当然了 凑2*12 或者3*8也没人拦着你   再找两个数减得0与剩下的数乘起来 所以 小数 3以下的凑不出来14一下的手动算 其实没多难 就是想不到T^T

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
	int n,tmp;
	while(~scanf("%d",&n))
	{
	//	printf("%d:\n",n);
		if(n<=3)
			printf("-1\n");
		else if(n==4)
			printf("1 * 2\n5 + 3\n6 + 4\n");
		else if(n==5)
			printf("1 * 2\n3 / 6\n4 - 7\n5 * 8\n");
		else if(n==6)
			printf("1 + 2\n3 + 4\n5 - 6\n7 + 8\n10 - 9\n");
		else if(n==7)
			printf("1 + 2\n3 + 8\n9 / 4\n10 + 5\n11 + 6\n12 + 7\n");
		else if(n==8)
			printf("1 + 2\n3 + 9\n4 - 5\n11 * 6\n12 * 7\n13 * 8\n10 + 14\n");
		else if(n==9)
			printf("1 + 2\n3 + 10\n4 / 5\n6 / 7\n8 / 9\n11 - 12\n15 - 13\n 16 - 14\n");
		else if(n==10)
			printf("1 + 2\n3 / 4\n5 / 6\n7 / 8\n9 / 10\n11 + 12\n16 + 13\n17 + 14\n18 + 15\n");
		else if(n==11)
			printf("1 + 2\n3 / 4\n5 / 6\n7 - 8\n15 * 9\n16 * 10\n17 * 11\n12 + 13\n19 + 14\n20 + 18\n");
		else if(n==12)
			printf("1 + 2\n3 - 4\n5 * 14\n6 * 15\n7 * 16\n8 * 17\n9 * 18\n10 * 19\n11 * 20\n12 * 21\n13 + 22\n");
		else if(n==13)
            printf("1 + 2\n3 / 4\n5 / 6\n7 - 8\n17 * 9\n18 * 10\n19 * 11\n20 * 12\n21 * 13\n22 + 14\n23 - 15\n24 - 16\n");
		else
		{
			printf("1 + 2\n3 + 4\n5 + 6\n7 + 8\n9 + 10\n");
			printf("%d + %d\n%d + %d\n%d + %d\n",n+1,n+2,n+3,n+4,n+5,n+6);
			printf("%d / 11\n%d / 12\n",n+7,n+8);
			printf("%d * %d\n",n+9,n+10);
			printf("13 - 14\n");
			tmp=n-14;
			int i;
			for(i=0;i<tmp;i++)
			{
				printf("%d * %d\n",n+12+i,15+i);
			}
			printf("%d + %d\n",n+11,n+12+tmp);
		}
	//	printf("\n");
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值