2018 ICPC East-Central NA Regional Practice Contest----So You Like Your Food Hot?

So You Like Your Food Hot? Kattis - soyoulikeyourfoodhot

Time limit 1000 ms
Memory limit 1048576 kB

Peter is co-owner of the incredibly successful Pete and Pat’s Pitas and Pizzas and his sales are on fire! But unfortunately, so is his building, due to carelessly laid delivery boxes placed too close to Pete’s famous wood burning pizza oven. After sifting though the remnants, one of the few things Pete is able to salvage is a ledger book, but the only thing he can make out on the charred pages is the profit he made during the last month. The insurance company would like to know how many pitas and how many pizzas Pete actually delivered over that period. Pete does recall how much profit he makes on each of these products, so he’s pretty confident that he can determine how many of each were sold during the last month given the total profit. Well perhaps “confident” is not the exact word Peter is looking for – it’s more like clueless. Can you help Pete out? I’m sure there are some discount coupons in it for you, or at least a really cheap price on a used pizza oven.

Input

Input consists of a single line containing 3 values pt p1 p2, where 0≤pt≤10000.00 is the profit for the month and 0

Output

Display two integers: the number of pitas sold and the number of pizzas sold so that the total profit equals the value given. If there is more than one combination of pitas and pizzas that give the specified profit, list them all, one combination per line, listing the combination with the smallest number of pitas first, then the combination with the second smallest number of pitas, and so on. If there are no combinations of pizza and pita sales that realize the profit, output none.

Sample Input 1

725.85 1.71 2.38

Sample Output 1

199 162

Sample Input 2

100.00 20.00 10.00

Sample Output 2

0 10
1 8
2 6
3 4
4 2
5 0

题目来源:
Source:2018 ICPC East-Central NA Regional Practice Contest
Author:John Bonomo

题意
利用两个小的数字的倍数得到一个大的数字,并把它们按顺序全部输出出来

解题思路
由于只是小数点后面两位的数值,所以我将其放大10000倍变成整数来进行计算,我这里第一个代码是纯暴力的写法,第二个代码利用公倍数来写更加节省时间

这是我的代码:950ms 有点直接取巧暴力的意思

#include 
#define EPSILON 0.00001
using namespace std;
int main()
{
    double pt,p1,p2;
    int flag=0;
    scanf("%lf%lf%lf",&pt,&p1,&p2);
    long long x,y,z;
    x=ceil(pt*10000);
    y=ceil(p1*10000);
    z=ceil(p2*10000);
    for(long long i=x; i>=0; i--)
    {
        if((x-z*i)%y==0&&(x-z*i)>=0)
        {
            printf("%lld %lld\n",(x-z*i)/y,i);
            flag=1;
        }
    }
    if(flag==0)
        printf("none\n");
    return 0;
}

这是一位大佬的代码:0ms 还是要膜拜啊~

#include 
using namespace std;
long long exgcd(long long a,long long b,long long &x,long long &y)
{
    if(b==0)
    {
        x=1,y=0;
        return a;
    }
    else if(b>a)return exgcd(b,a,y,x);
    else
    {
        long long r=exgcd(b,a%b,x,y);
        long long temp=x;
        x=y;
        y=temp-(a/b)*y;
        return r;
    }
}
int main()
{
    double pt,p1,p2;
    int flag=0;
    long long m0,n0;
    scanf("%lf%lf%lf",&pt,&p1,&p2);
    long long x,y,z;
    x=ceil(pt*10000);
    y=ceil(p1*10000);
    z=ceil(p2*10000);
    long long gcd=exgcd(y,z,m0,n0);//预处理
    for(long long t=x*m0/z+2; t>=-1*x*n0/y-2; t--)
    {
        long long q=(x*m0-z*t)/gcd;
        long long p=(x*n0+y*t)/gcd;
        if(q>=0&&p>=0)
        {
            printf("%lld %lld\n",q,p);
            flag=1;
        }
    }
    if(flag==0)
        printf("none\n");
    return 0;
}

你可能感兴趣的:(C++,简单处理)