| Time Limit: 1000MS | Memory Limit: 65536K | |||
| Total Submissions: 1564 | Accepted: 621 | Special Judge | ||
Description
A cashier in a grocery store seems to have difficulty in distinguishing the multiplication symbol and the addition symbol. To make things easier for him, you want to buy goods in such a way that the product of their prices is the same as the sum of their prices.
Of course, if you buy only one item, this is always true. With two items and three items, it still seems quite a boring task to you, so now you are interested in finding possible prices of four items such that the sum of the four prices is equal to the product of the four prices. You should consider the prices are in € with two digits after the decimal point. Obviously, each product costs at least one cent.
Input
This problem has no input.
Output
Print all solutions which have a sum of the four items of at most 20.00 €. For each solution, print one line with the prices of the four items in non-decreasing order, with one space character between them. You may print the solutions in any order, but make sure to print each solution only once.
Sample Input
Sample Output
0.50 1.00 2.50 16.00 1.25 1.60 1.75 1.84 1.25 1.40 1.86 2.00 ...
Source
题意:
找出4个2位数,Q,W,E,R使Q+W+E+R==Q*W*E*R且Q+W+E+R<=20。
poin:
暴力打表输出。 HDU里那题没有Special Judge所以我好像过不了,POJ里可以过。
#include <stdio.h>
#include <string.h>
int main()
{
freopen("filename.txt", "a+", stdout);
for(int a=1; a<=500; a++)
{
for(int b=a; b<=700; b++)
{
if(a+b>2000) break;
for(int c=b; c<=1000; c++)
{ //对于每个a,b,c都有唯一确定的d,可以直接把他算出来。
int x=a+b+c;
if(a*b*c<=1000000) continue; //这步是由 a+b+c+d==a*b*c*d得到,我们的值都扩大了100倍,so d=1000000*x%(a*b*c-1000000)
if(1000000*x%(a*c*b-1000000)!=0) continue;//整数
int d=1000000*x/(a*c*b-1000000);
if(d<c||a+b+c+d>2000) continue;
double q,w,e,r;
q=a/100.0;
w=b/100.0;
e=c/100.0;
r=d/100.0;
printf("%.2lf %.2lf %.2lf %.2lf\\n",q,w,e,r);
}
}
}
}
寻找特殊商品组合

本文探讨了一个有趣的问题:如何找出四种商品的价格,使得这些价格的总和等于它们的乘积,并且总价不超过20欧元。文章提供了一种通过遍历所有可能的价格组合来找到符合条件的价格的方法。
337

被折叠的 条评论
为什么被折叠?



