int calculate(char* s) { int size = 10000, top = 0, num = 0; bool hasNum = false; int stack[size]; char op; while (*s != '\0') { if (!isdigit(*s) && *s != ' ') { if (hasNum) { // if we use num != 0 instand of hasNum, when the input is 0, it will be confused pushNum(stack, &top, num); num = 0; hasNum = false; } if (*s == ')') { int start = top-2; while (stack[start] != '(') start -= 2; int n = calcu(stack, start+1, top); top = start; pushNum(stack, &top, n); } else { stack[top++] = *s; } } else if (isdigit(*s)) { num = num * 10 + *s - '0'; hasNum = true; } s++; } if (hasNum) { pushNum(stack, &top, num); } return calcu(stack, 0, top); }
void san_fen() { double lc,rc,mid1,mid2,res1,res2,ty ; lc=0 ; rc=pi/2 ; do { mid1=(lc+rc)/2 ; mid2=(mid1+rc)/2 ; res1=calcu(mid1); res2=calcu(mid2); if(res1<res2)lc=mid1 ; else rc=mid2 ; } while(rc-lc>eps); if(res1<res2)res1=res2 ; if(res1<y) { printf("-1\n"); return ; } else { er_fen(0,rc); } }
void enumerate(int energy, int number, int flag, int count) { if(energy * flag == 0 ) { return; } if(energy != flag && energy-flag <= flag) { array[count++] = flag; enumerate(energy-flag, number-1, energy-flag, count); count--; enumerate(energy, number, flag-1, count); } if(energy != flag && energy-flag > flag) { array[count++] = flag; enumerate(energy-flag, number-1, flag, count); } if(energy == flag) { array[count++] = flag; calcu(count, array); count--; enumerate(energy, number, flag-1, count); } return; }
int main() { while (scanf("%d",&p)!=EOF) { int x,y; if (calcu(p,x,y)!=-1) } return 0; }
ld calcu(ld R, ld X){ if(X >= R + R) return 4 * (ld)(1.0) / 3 * (2 * acosl((ld)0)) * R * R * R; else if(X <= R){ return (2 * acosl((ld)0)) * X * X * (R - X / 3); } else{ return 4 * (ld)(1.0) / 3 * (2 * acosl((ld)0)) * R * R * R - calcu(R, R + R - X); } }
void er_fen(double lc,double rc) { double res,mid ; while(rc-lc>eps) { mid=(lc+rc)/2 ; res=calcu(mid); if(res>y)rc=mid ; else lc=mid ; } printf("%.6lf\n",mid); }
ld cal(ld x){ ld res = x * W * L; for(int i = 0; i < (n); ++i){ ld v = calcu(r[i], x); ld vball = 4 * (ld)(1.0) / 3 * (2 * acosl((ld)0)) * r[i] * r[i] * r[i]; if(v >= vball * w[i]) res -= vball * w[i]; else res -= v; } return res; }