Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 还以为是1A,原来只要过样例就能AC``

Posted by angeldust at 2012-08-12 15:07:36 on Problem 3983 and last updated at 2012-08-13 11:40:17
```样例根本无法弄明白括号该如何打嘛，（除法也在打括号）。假设是每个等式必须都打2对括号（最后一次运算不打括号），这样的话就很简单了，不用考虑运算符优先级。

#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <string>
#include <string.h>
#include <queue>
#include <set>
using namespace std;
char operators[4]={'+','-','*','/'};
int a[4],oper[3];
double calc(double a,int op,double b)
{
switch (op)
{
case 0:return a+b;
case 1:return a-b;
case 2:return a*b;
default:return a/(b!=0?b:0.00001);
}
}
int main()
{
for(int i=0;i<4;i++) scanf("%d",a+i);
for(int i=0;i<64;i++)
{
int tmp=i;
for(int j=0;j<3;j++,tmp>>=2) oper[j]=tmp&3;
if (calc(calc(a[0],oper[0],a[1]),oper[1],calc(a[2],oper[2],a[3]))==24)
{
printf("(%d%c%d)%c(%d%c%d)\n",a[0],operators[oper[0]],a[1],operators[oper[1]],a[2],operators[oper[2]],a[3]);
return 1;
}
if (calc(calc(calc(a[0],oper[0],a[1]),oper[1],a[2]),oper[2],a[3])==24)
{
printf("((%d%c%d)%c%d)%c%d\n",a[0],operators[oper[0]],a[1],operators[oper[1]],a[2],operators[oper[2]],a[3]);
return 1;
}
if (calc(calc(a[0],oper[0],calc(a[1],oper[1],a[2])),oper[2],a[3])==24)
{
printf("(%d%c(%d%c%d))%c%d\n",a[0],operators[oper[0]],a[1],operators[oper[1]],a[2],operators[oper[2]],a[3]);
return 1;
}
if (calc(a[0],oper[0],calc(calc(a[1],oper[1],a[2]),oper[2],a[3]))==24)
{
printf("%d%c((%d%c%d)%c%d)\n",a[0],operators[oper[0]],a[1],operators[oper[1]],a[2],operators[oper[2]],a[3]);
return 1;
}
if (calc(a[0],oper[0],calc(a[1],oper[1],calc(a[2],oper[2],a[3])))==24)
{
printf("%d%c(%d%c(%d%c%d))\n",a[0],operators[oper[0]],a[1],operators[oper[1]],a[2],operators[oper[2]],a[3]);
return 1;
}
}
}```

Followed by: