CodeForces-1244C-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 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
30 60 3 1
17 9 4
10 51 5 4
-1
20 0 15 5
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.
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
typedef long long ll; int main()
{
ll n,p,w,d;
scanf("%lld %lld %lld %lld",&n,&p,&w,&d);
if(n*w<p)
printf("-1\n");
else if(n*w>=p)
{
if(n*w==p)
{
printf("%lld 0 0\n",n);
}
else if(n*w>p)
{
ll x=p/w;
ll q=p%w;;
if(q%d==)
{
ll y=q/d;
if(x+y<=n)
printf("%lld %lld %lld",x,y,n-x-y);
else
printf("-1\n");
}
else if(q%d!=)//说明需要从赢的局数点里面分出一部分点进行补充然后给到平局d
{
//需要求(q+wi)%d==0
int flag=;
for(int i=; i<=min(x,d); i++)
{
if((q+w*i)%d==)
{
ll xx=x-i;
ll yy=(q+w*i)/d;
ll zz=n-xx-(q+w*i)/d;
if(xx+yy+zz<=n)
{
flag=;
printf("%lld %lld %lld\n",xx,yy,zz);
}
else
printf("-1\n");
break;
}
}
if(!flag)
printf("-1\n");
}
}
}
return ;
}
CodeForces-1244C-The Football Season-思维的更多相关文章
- [Codeforces 1244C] The Football Season
思维加枚举 题意 :足球赛,赢平所得到的分数分别为w和d,w>d,分别求赢平输的场数,输出一组即可,即x+y+z=n 且 xw+yd=p的一组解. 可以扩展公约数做,但由于注意到d和w<1 ...
- CF 1244 C - The Football Season
C - The Football Season 先考虑求解 \[ x\times w + y\times d=p \] 若存在一组解 \[ \begin{cases} x_0\\ y_0 = kw + ...
- [CF1244C] The Football Season【数学,思维题,枚举】
Online Judge:Luogu,Codeforces Round #592 (Div. 2) C Label:数学,思维题, 枚举 题目描述 某球队一共打了\(n\)场比赛,总得分为\(p\), ...
- codeforces 1244C (思维 or 扩展欧几里得)
(点击此处查看原题) 题意分析 已知 n , p , w, d ,求x , y, z的值 ,他们的关系为: x + y + z = n x * w + y * d = p 思维法 当 y < w ...
- A. Yellow Cards ( Codeforces Round #585 (Div. 2) 思维水题
---恢复内容开始--- output standard output The final match of the Berland Football Cup has been held recent ...
- CodeForces - 427A (警察和罪犯 思维题)
Police Recruits Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- codeforces 895B XK Segments 二分 思维
codeforces 895B XK Segments 题目大意: 寻找符合要求的\((i,j)\)对,有:\[a_i \le a_j \] 同时存在\(k\),且\(k\)能够被\(x\)整除,\( ...
- codeforces 893D Credit Card 贪心 思维
codeforces 893D Credit Card 题目大意: 有一张信用卡可以使用,每天白天都可以去给卡充钱.到了晚上,进入银行对卡的操作时间,操作有三种: 1.\(a_i>0\) 银行会 ...
- C. Nice Garland Codeforces Round #535 (Div. 3) 思维题
C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- C Alyona and Spreadsheet Codeforces Round #401(Div. 2)(思维)
Alyona and Spreadsheet 这就是一道思维的题,谈不上算法什么的,但我当时就是不会,直到别人告诉了我,我才懂了的.唉 为什么总是这么弱呢? [题目链接]Alyona and Spre ...
随机推荐
- Linux 软硬链接区别
一.“硬链接“和“软链接“ 链接的概念:链接简单说实际上是一种文件共享的方式,是 POSIX 中的概念,主流文件系统都支持链接文件. 链接的作用:可以将链接简单地理解为 Windows 中常见的快捷方 ...
- Delphi 实现最近打开文件记录菜单
unit UntOpenMenu; //download by http://wwww.NewXing.com interface uses Windows, Messages, SysUtils, ...
- (转)OpenFire源码学习之十八:IOS离线推送
转:http://blog.csdn.net/huwenfeng_2011/article/details/43458213 IOS离线推送 场景: 如果您有iOS端的APP,在会话聊天的时候,用户登 ...
- A. Srdce and Triangle--“今日头条杯”首届湖北省大学程序设计竞赛(网络同步赛)
如下图这是“今日头条杯”首届湖北省大学程序设计竞赛的第一题,作为赛后补题 题目描述:链接点此 这套题的github地址(里面包含了数据,题解,现场排名):点此 Let be a regualr tr ...
- 探索C++的秘密之详解extern
转载:http://developer.51cto.com/art/200704/46843.htm C和C++对函数的处理方式是不同的.extern "C"是使C++能够调用C写 ...
- HDU 6695 Welcome Party (贪心)
2019 杭电多校 10 1005 题目链接:HDU 6695 比赛链接:2019 Multi-University Training Contest 10 Problem Description T ...
- 剑指offer——45整数中1出现的次数
题目描述 求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1.10.11.12.13因此共出现6次,但是对于后面问题他就没辙了. ...
- java.lang.Double.byteValue() 方法
java.lang.Double.byteValue() 方法(通过转换成一个字节)返回此Double为一个字节的值. 声明 以下是java.lang.Double.byteValue()方法的声明 ...
- static变量、static函数与普通变量、普通函数的区别
转自:http://blog.163.com/sunshine_linting/blog/static/44893323201191294825184/ 全局变量(外部变量)的说明之前再冠以stati ...
- 解决 IE6 position:fixed 固定定位问题
#e_float{ _position:absolute; _bottom:auto; _right:50%; _margin-right:-536px; _top:expression(eval(d ...