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 ...
随机推荐
- 使用ionic来build安卓apk时,报CordovaError: Requirements check failed for JDK 1.8 or greater
本地配置了JDK和jre的本地环境变量之后,在命令行中运行Java.javac等都能正常输出,但是在使用ionic cordova build android 来打包ionic的程序时,会提示 Cor ...
- 4、APP FPS测试
什么是FPS FPS是图像领域中的定义,是指画面每秒传输帧数,通俗来讲就是指动画或视频的画面数.FPS是测量用于保存.显示动态视频的信息数量.每秒钟帧数愈多,所显示的动作就会愈流畅.通常,要避免动作不 ...
- Linux文件映射的反思
1. 思考 多个进程可以加载相同的共享链接库,比如C语言的运行库,加载运行库采用内存映射文件的方式,可以延迟对于文件内容的读入操作. 共享链接库文件,是一个elf格式的库文件,里面会包含多个不同的se ...
- leetcode-1053. 交换一次的先前排列
题目描述: 给你一个正整数的数组 A(其中的元素不一定完全不同),请你返回可在 一次交换(交换两数字 A[i]和 A[j] 的位置)后得到的.按字典序排列小于 A 的最大可能排列. 如果无法这么操 ...
- Python 操作excel常见异常
一.使用xlrd模块读取excel: 1.报错:IndexError: list index out of range,如下图 解决方法:reading_sheet.cell(1,0).value中c ...
- JUC源码分析-集合篇:并发类容器介绍
JUC源码分析-集合篇:并发类容器介绍 同步类容器是 线程安全 的,如 Vector.HashTable 等容器的同步功能都是由 Collections.synchronizedMap 等工厂方法去创 ...
- 第十七章 程序管理与SELinux初探--进程、进程管理(ps、top)
一个程序被加载到内存当中运行,在内存内的那个数据就被称为进程(process).进程是操作系统上非常重要的概念,所有系统上面跑的数据都会以进程的类型存在.系统进程有哪些状态?不同状态会如何影响系统的运 ...
- SaaS,PaaS,IaaS都是什么鬼?
IaaS Infrastructure as a Service,基础设施即服务. 假如你现在要做一个网站,你肯定要有一台服务器或者虚拟机,要么自己搭建,要么买服务器运营商的.说白了,IaaS就是解决 ...
- mysql数据库中某字段一部分乱码
笔者问题:mysql表(表中数据就是乱码,可能是插入时编码问题,这个问题以后解决)导出excel时数据中有乱码(但是在页面上查看是正常的),我们希望能导出一份没有中文乱码的excel 根据热力站中一次 ...
- 项目中UX设计1到2的设计提升总结