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 ...
随机推荐
- 树————N叉树的层序遍历
思想: 使用队的思想,将每一层的节点放入队列中,依次弹出,同时将其children放入队列. c++ /* // Definition for a Node. class Node { public: ...
- Python_day01——变量
变量 1.声明变量 name="钱成龙" 变量定义的规则: 变量名只能是 字母.数字或下划线的任意组合 变量名的第一个字符不能是数字 关键字不能声明为变量名 2.变量类型 整 ...
- 攻防世界 MISC篇
Excaliflag 一张图片,winhex打开没什么发现,分值不高,应该属于常见的图片隐写题目.如果对于图片的格式有详细的了解,应该很容易就能够知道了属于最低有效位(LSB)隐写,下面是通过phot ...
- Html加水印和禁用复制和右键(jquery.watermark.js)
近期遇到一个需求,需要在页面背景加上自己的水印和禁止用户在页面复制粘贴 解决: 水印使用的是jquery.watermark.js插件,这个插件可以在html背景上加水印,同时可以设置相关属性值. 相 ...
- websocke和http的区别
同:建立在TCP之上,同http一样通过TCP来传输数据 不同: HTTP协议为单向协议,即浏览器只能向服务器请求资源,服务器才能将数据传送给浏览器,而服务器不能主动向浏览器传递数据.分为长连接和短连 ...
- nodejs moment 修改时间格式 日期格式与时间戳格式互相转化
node js moment 修改时间格式 日期格式与int格式互相转化 nvm use 8.3 > moment = require('moment') > days = '2019-0 ...
- CSS:CSS 分组 和 嵌套 选择器
ylbtech-CSS:CSS 分组 和 嵌套 选择器 1.返回顶部 1. CSS 分组 和 嵌套 选择器 Grouping Selectors 在样式表中有很多具有相同样式的元素. h1 { col ...
- 17、javaWebService,的使用
2. 实质上分三步操作: 创建一个服务器端(电力系统),和一个客户端(人员系统) 第一步:使用服务器端提供的接口,生成.wsdl文件 第二步:使用.wsdl文件,在电力系统中生成服务器端的代码 第三步 ...
- jmter 5.1 中文
一.jmeter5.0下载解压后,默认的界面是英文版的,许多人觉得不方便,想要汉化,jmeter是不需要安装汉化包的,通过修改配置文件即可:1.找到jmeter解压后的文件夹,例如我是安装在D:\De ...
- 剑指offer第二版面试题4:替换空格(JAVA版)
题目:请实现一个函数,把字符串中的每个空格替换成“%20”.例如输入“We are happy”,则输出”We%20are%20happy”. 原因:在网络编程中,如果URL参数中含有特殊字符,如:空 ...