POJ 3369 Grocery store (枚举 打表)

49 篇文章 0 订阅
Grocery store
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

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);

            }
        }
    }
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值