• <cf>Two Problems


    A. Two Problems
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    A boy Valera registered on site Codeforces as Valera, and wrote his first Codeforces Round #300. He boasted to a friend Arkady about winning as much as x points for his first contest. But Arkady did not believe his friend's words and decided to check whether Valera could have shown such a result.

    He knows that the contest number 300 was unusual because there were only two problems. The contest lasted for t minutes, the minutes are numbered starting from zero. The first problem had the initial cost of a points, and every minute its cost reduced by da points. The second problem had the initial cost of b points, and every minute this cost reduced by db points. Thus, as soon as the zero minute of the contest is over, the first problem will cost a - da points, and the second problem will costb - db points. It is guaranteed that at any moment of the contest each problem has a non-negative cost.

    Arkady asks you to find out whether Valera could have got exactly x points for this contest. You should assume that Valera could have solved any number of the offered problems. You should also assume that for each problem Valera made no more than one attempt, besides, he could have submitted both problems at the same minute of the contest, starting with minute 0 and ending with minute number t - 1. Please note that Valera can't submit a solution exactly t minutes after the start of the contest or later.

    Input

    The single line of the input contains six integers x, t, a, b, da, db (0 ≤ x ≤ 600; 1 ≤ t, a, b, da, db ≤ 300) — Valera's result, the contest's duration, the initial cost of the first problem, the initial cost of the second problem, the number of points that the first and the second problem lose per minute, correspondingly.

    It is guaranteed that at each minute of the contest each problem has a non-negative cost, that is, a - i·da ≥ 0 and b - i· db ≥ 0 for all 0 ≤ i ≤ t - 1.

    Output

    If Valera could have earned exactly x points at a contest, print "YES", otherwise print "NO" (without the quotes).

    Sample test(s)
    input
    30 5 20 20 3 5
    
    output
    YES
    
    input
    10 4 100 5 5 1
    
    output
    NO
    
    Note

    In the first sample Valera could have acted like this: he could have submitted the first problem at minute0 and the second problem — at minute 2. Then the first problem brings him 20 points and the second problem brings him 10 points, that in total gives the required 30 points.

    这不是一道难题,但是一次AC还是不易的,因为有些细节问题很容易忽略,首先可以两题答错(x=0),也可以只答对一题,也可以两题皆对。

    AC code

    #include <iostream>
    using namespace std;
    int main()
    {
        int x,t,a,b,da,db,i;
        double ta,tb;
        bool flag;
        while(cin>>x>>t>>a>>b>>da>>db)
        {
            flag=false;
            if(x==0) flag=true;
            for(i=0;i<t && !flag;i++)
            {
                int m=x-(a-i*da);
                if(m==0 || m==b)
                {
                    flag=true;
                }
                else if(m>0 && m<b)
                {
                    tb=1.0*(b-m)/db;
                    if((int)tb==tb && tb>=0 && tb<t)
                    {
                        flag=true;
                    }
                }
            }
            for(i=0;i<t && !flag;i++)
            {
                int m=x-(b-i*db);
                if(m==0 || m==a)
                {
                    flag=true;
                }
                else if(m>0 && m<a)
                {
                    ta=1.0*(a-m)/da;
                    if((int)ta==ta && ta>=0 && ta<t)
                    {
                        flag=true;
                    }
                }
            }
            if(flag) cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        return 0;
    }
    


  • 相关阅读:
    架构,改善程序复用性的设计(目录)
    如何让你的系统配置文件更合理
    MVC验证(自动在基类中验证实体的数据有效性),本人最满意的作品之一
    MVC验证(只验证指定字段)
    Redis学习笔记~实现消息队列比MSMQ更方便
    FRG图像文件格式(四):编码技术
    缓冲区
    Oracle体系结构及备份(十一)——bcakgroundprocess
    Excel编程(2)自动填充
    设计模式:策略模式
  • 原文地址:https://www.cnblogs.com/cszlg/p/2910594.html
Copyright © 2020-2023  润新知