The Football Season

这篇博客讨论了在Berland的足球赛季中,如何根据球队的比赛场次和获得的积分,来确定胜利、平局和失败的次数。文章提供了一个解决方案,通过枚举平局次数并利用赢得比赛和平局的得分来检查是否存在合适的赢、平、输的次数组合。
摘要由CSDN通过智能技术生成

The Football Season

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 w points, and the opposing team gets 0 points. If the game results in a draw, both teams get d 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 p points for them.

You have to determine three integers x, y and z— 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), report about it.

Input
The first line contains four integers n, p, w and d (1≤n≤10 ^12,0≤p≤10 ^17,1≤d<w≤10 ^5)— 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>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.

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

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

Examples
input
30 60 3 1
output
17 9 4

input
10 51 5 4
output
-1

input
20 0 15 5
output
0 0 20

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

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

In the third example the team got 0 points, so all 20 games were lost.

思路
这里我们看到 xw+yd=p,首先这样分析,要加上y倍的d让其等于p,那么我们就要枚举y的个数。(一般来说复杂度要超),但是由于当y的值大于w之后,平局的分数为w*d+(y-w)d,其中的wd可以用d个w来代替,所以我们只需要枚举[0,w)个d判断p-yd能不能整除w即可,且w和d的范围都在1e5之内,所以是完全可以过的~

代码如下:

#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
const int mx=1e5+10;

ll n,p,w,d;

int main(){
    scanf("%lld%lld%lld%lld",&n,&p,&w,&d);
	ll x=0,y=0,z;
	while(y<w&&(p-d*y) % w !=0)y++; //枚举[0,w)个y啦~
	if(y<w){
	   x=(p-d*y)/w;
	   z=n-x-y;
	   if(x<0||z<0)//主要判断两个条件
	   printf("-1\n");
	   else
	   printf("%lld %lld %lld\n",x,y,z);
    }
    else
    printf("-1\n");
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值