首页 > 代码库 > UVALive 6163

UVALive 6163

#include <algorithm>#include <iostream>#include <string.h>#include <stdio.h>#include <math.h>#include <vector>#include <queue>#include <stack>#include <map>#define inf 0x7f7f7f7fusing namespace std;int cal(int a, int b, int c){    if (c==0) return a*b;    if (c==1){        if (b==0) return inf/2;        return a/b;    }    if (c==2) return a+b;    if (c==3) return a-b;}bool Can(int k){    int a[4]={k/1000,k%1000/100,k%100/10,k%10};    int num,num1,num2;    for (int i=0;i<3;i++)        for (int j=i+1;j<=3;j++)            if(a[i]>a[j]){                int kk=a[i];                a[i]=a[j];                a[j]=kk;        }    do{    for (int r1=0;r1<=3;r1++)        for (int r2=0;r2<=3;r2++)            for (int r3=0;r3<=3;r3++){                if (cal(cal(cal(a[0],a[1],r1),a[2],r2),a[3],r3)==10) return true;                if (cal(cal(a[0],a[1],r1),cal(a[2],a[3],r3),r2)==10) return true;                if (cal(cal(a[0],cal(a[1],a[2],r2),r1),a[3],r3)==10) return true;                if (cal(a[0],cal(cal(a[1],a[2],r2),a[3],r3),r1)==10) return true;                if (cal(a[0],cal(a[1],cal(a[2],a[3],r3),r2),r1)==10) return true;            }    }while (next_permutation(a, a+4));    return false;}int main(){    int n,k;    bool flag;    while (scanf("%d",&n)!=EOF){        if (n==0)            break;        flag=false;        for (int i=1;i<=n;i++){            scanf("%d",&k);            if (!Can(k))                flag=true;        }        if (!flag)            printf("TRUE\n");        else            printf("BUSTED\n");    }    return 0;}
View Code

总结下:第一个是那个全排列的函数,,, 得先需要排下顺序;

           第二个在做的时候要把所有的运算顺序搞出来,

        浪费时间太多了