zoukankan      html  css  js  c++  java
  • hdu5308 I Wanna Become A 24-Point Master(构造)

    题目: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+1
    	printf("4 + 5
    ");//n+2
    	printf("7 + 8
    ");//n+3
    	printf("10 + 11
    ");//n+4
    	printf("%d + 12
    ",n+4);//n+5
    	printf("%d / 3
    ",n+1); // n+6 2
    	printf("%d / 6
    ",n+2);//n+7   2
    	printf("%d / 9
    ",n+3);//n+8   2
    	printf("%d / 13
    ",n+5);//n+9  3
    	printf("14 - 15
    ");//n+10     0
    	int c=n+10;
    	for(int i=16;i<=n;i++)
    	{
    		printf("%d * %d
    ",c,i);
    		c++;
    	}
    	printf("%d * %d
    ",n+6,n+7); //c+1
    	printf("%d * %d
    ",n+8,c+1); //c+1
    	printf("%d * %d
    ",c+2,n+9);
    	printf("%d + %d
    ",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
    ",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
    ",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
    ",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
    ",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
    ",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
    ",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
    ",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
    ",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
    ",s1[i],op[i],s2[i]);
    }
    void _5()
    {
    	printf("1 * 2
    ");
    	printf("6 * 3
    ");
    	printf("7 - 4
    ");
    	printf("8 / 5
    ");
    }
    void _4()
    {
    	printf("1 * 2
    ");
    	printf("5 + 3
    ");
    	printf("6 + 4
    ");
    }
    
    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
    ");
    	}
    	return 0;
    }


  • 相关阅读:
    共望明月
    游丽都公园有感
    创业天才尼尔曼迈向成功的十四个原则
    赵娜(帮别人名字作诗)
    小幽默也有大道理:哲理幽默15则
    夜游草堂
    成功就是简单的事情重复做、重复做
    千万别入错行 15条人生建议
    听一堂课值三十九万,把它看完,定会有收获!
    VIEW:X$KCCRSControlfile Record Section directory (8.0 8.1)
  • 原文地址:https://www.cnblogs.com/yjbjingcha/p/7122481.html
Copyright © 2011-2022 走看看