POJ 3369 Grocery store (枚举 打表)

来源:互联网 发布:app流程图制作软件 编辑:程序博客网 时间:2024/05/22 05:09
Grocery store
Time Limit: 1000MS Memory Limit: 65536KTotal 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.001.25 1.60 1.75 1.841.25 1.40 1.86 2.00...

Source

Ulm Local 2007


题意:

找出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);            }        }    }}



原创粉丝点击