UVA-10483 the Sum Equals the Product violence

Source: Internet
Author: User

Give a scope, ask to find out within this range to meet
n = x + y + z = x * y * z all formulas

How to solve the problem: because the decimal place here is accurate to 0.01, so first of all, X, Y, Z are 100 times times larger.
From small to large enumerations, assuming x <= y <= Z, then the range of X is in the range of (0,n ^ (1/3)],y in [X, (N-x) ^ (1/2)] so the range can be determined.
and z can be obtained by X and Y
Because x + y + z = x * y * z, and z/y are magnified 100 times times after
So (x + y + z) * 10000 = x * y * z
Distorted by formula, Z = (x + y) * 10000/(x * y-10000)

#include <cstdio>#include <algorithm>#include <cmath>#define MAXN 10010#define PO 100.0#define MIN 1e-9using namespace STD;DoubleSum1, sum2;intCntstructans{DoubleSum, A, B, C;} ANS[MAXN];BOOLCMP (ans &a, ans &b) {if(fabs(a.sum-b.sum) >= MIN)returnA.sum < B.sum;if(fabs(A.A-B.A) >= MIN)returnA.A < B.A;if(fabs(a.b-b.b) >= MIN)returnA.B < b.b;returnA.C < B.C;}voidSolve () {cnt =0;intleft = Sum1 * -, right = sum2 * -; for(inti =1; I * i * I <= right *10000; i++) for(intj = i; J * J * I <= Right *10000; J + +) {if((i * j <=10000) || ((i + j) *10000% (i * j-10000)) )Continue;intx = (i + j) *10000/(I * j-10000);if(X < I | | x < j)Continue;intsum = i + j + x;intf = i * j * x;if(f%10000)Continue;if(Sum >= left && sum <= right && (sum = f/10000) {ans[cnt].sum = Sum/po;                ANS[CNT].A = I/po;                ans[cnt].b = J/po;                ANS[CNT].C = X/po;            cnt++; }} sort (ans, ans + cnt, CMP); for(inti =0; I < CNT; i++)printf("%.2LF =%.2lf +%.2lf +%.2lf =%.2lf *%.2LF *%.2lf\n", ANS[I].SUM,ANS[I].A, ans[i].b, ans[i].c,ans[i].a,ans[i].b, ans[i].c);}intMain () { while(scanf("%LF%LF", &AMP;SUM1, &sum2) = =2) {solve (); }return 0;}

UVA-10483 the Sum Equals the Product violence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.