zoukankan      html  css  js  c++  java
  • Codeforces Round #592 (Div. 2)C. The Football Season(暴力,循环节)

    C. The Football Season

    time limit per test

    1 second

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets ww points, and the opposing team gets 00 points. If the game results in a draw, both teams get dd points.

    The manager of the Berland capital team wants to summarize the results of the season, but, unfortunately, all information about the results of each match is lost. The manager only knows that the team has played nn games and got pp points for them.

    You have to determine three integers xx, yy and zz — the number of wins, draws and loses of the team. If there are multiple answers, print any of them. If there is no suitable triple (x,y,z)(x,y,z), report about it.

    Input

    The first line contains four integers nn, pp, ww and dd (1≤n≤1012,0≤p≤1017,1≤d<w≤105)(1≤n≤1012,0≤p≤1017,1≤d<w≤105) — the number of games, the number of points the team got, the number of points awarded for winning a match, and the number of points awarded for a draw, respectively. Note that w>dw>d, so the number of points awarded for winning is strictly greater than the number of points awarded for draw.

    Output

    If there is no answer, print −1−1.

    Otherwise print three non-negative integers xx, yy and zz — the number of wins, draws and losses of the team. If there are multiple possible triples (x,y,z)(x,y,z), print any of them. The numbers should meet the following conditions:

    • x⋅w+y⋅d=px⋅w+y⋅d=p,
    • x+y+z=nx+y+z=n.

    Examples

    input

    Copy

    30 60 3 1
    

    output

    Copy

    17 9 4
    

    input

    Copy

    10 51 5 4
    

    output

    Copy

    -1
    

    input

    Copy

    20 0 15 5
    

    output

    Copy

    0 0 20
    

    Note

    One of the possible answers in the first example — 1717 wins, 99 draws and 44 losses. Then the team got 17⋅3+9⋅1=6017⋅3+9⋅1=60 points in 17+9+4=3017+9+4=30 games.

    In the second example the maximum possible score is 10⋅5=5010⋅5=50. Since p=51p=51, there is no answer.

    In the third example the team got 00 points, so all 2020 games were lost.

    暴力,并没有必要把p范围内的方案全部枚举,只需要枚举一边=遍,然后记录余数即可

    #include<bits/stdc++.h>
    using namespace std;
    map<long long,int> mp;
    int main()
    {
        long long n,p,w,d;
        scanf("%lld%lld%lld%lld",&n,&p,&w,&d);
        long long x=-1,y=-1;
        for(long long i=0;i*d<=p;i++)//枚举i次平局
        {
            long long tmp=p-i*d;
            if(tmp%w==0)
            {
                y=i;
                x=tmp/w;
                break;
            }
            if(mp[tmp%w]==1)
            {
                break;
            }
            else
            {
                mp[tmp%w]=1;
            }
        }
        if(x!=-1&&x+y<=n)
        {
            printf("%lld %lld %lld
    ",x,y,n-x-y);
        }
        else
        {
            printf("%d
    ",-1);
        }
    }
  • 相关阅读:
    关于json解析和所需jar
    Solr初步使用
    Appium-desktop使用时的一些配置
    mac电脑安装和配置tomcat步骤
    maven-reportng插件依赖添加
    maven-surefire插件配置
    mac电脑的一些操作
    元素的多种延时等待(&页面的超时处理)
    Mac系统搭建java+selenium+testng环境
    爬虫简介与request模块
  • 原文地址:https://www.cnblogs.com/caowenbo/p/11852207.html
Copyright © 2011-2022 走看看