C - The Football Season

先考虑求解

\[
x\times w + y\times d=p
\]

若存在一组解

\[
\begin{cases}
x_0\\
y_0 = kw + v & (0<v<w)\\
\end{cases}
\]

\[
x_0 \times w + y_0 \times d = p\\
\Rightarrow x_0 \times w + (kw+v)\times d = p\\
\Rightarrow x_0\times w + k\times w\times d + v\times d = p\\
\Rightarrow (x_0+k\times d)\times w + v\times d = p ~~~~~
\]

所以一定存在一组解

\[
\begin{cases}
x = x_0 + k\times d\\
y = v
\end{cases}
\]

并且由于$w> d$

\[
x + y = x_0 + k\times d + v < x_0 + k\times w + v
\]

前者比后者更有可能成为答案

所以直接枚举所有的v即可

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,p,w,d;
int main(){
cin >> n >> p >> w >> d;
for(ll v=0;v<w;v++){
if((p - v * d) % w == 0){
ll x = (p - v * d) / w;
if(x >= 0 && x + v <= n){
printf("%lld %lld %lld\n",x,v,n-x-v);
return 0;
}
}
}
puts("-1");
return 0;
}

CF 1244 C - The Football Season的更多相关文章

  1. [Codeforces 1244C] The Football Season

    思维加枚举 题意 :足球赛,赢平所得到的分数分别为w和d,w>d,分别求赢平输的场数,输出一组即可,即x+y+z=n 且 xw+yd=p的一组解. 可以扩展公约数做,但由于注意到d和w<1 ...

  2. CF1244C The Football Season

    题目链接 problem 给定\(n,p,w,d\),求解任意一对\((x,y)\)满足\[xw+yd=p\\ x + y \le n\] \(1\le n\le 10^{12},0\le p\le ...

  3. [CF1244C] The Football Season【数学,思维题,枚举】

    Online Judge:Luogu,Codeforces Round #592 (Div. 2) C Label:数学,思维题, 枚举 题目描述 某球队一共打了\(n\)场比赛,总得分为\(p\), ...

  4. American Football Vocabulary!

    American Football Vocabulary! Share Tweet Share You’ll learn all about the vocabulary of American fo ...

  5. CodeForces-1244C-The Football Season-思维

    The football season has just ended in Berland. According to the rules of Berland football, each matc ...

  6. 【Codeforces】CF Round #592 (Div. 2) - 题解

    Problem - A Tomorrow is a difficult day for Polycarp: he has to attend \(a\) lectures and \(b\) prac ...

  7. Codeforces Round #592 (Div. 2)

    A. Pens and Pencils 题目链接:https://codeforces.com/contest/1244/problem/A 题意: 给定五个数 a , b , c , d , k 求 ...

  8. codeforces #592(Div.2)

    codeforces #592(Div.2) A Pens and Pencils Tomorrow is a difficult day for Polycarp: he has to attend ...

  9. Python input/output boilerplate for competitive programming

    The following code is my submission for Codeforces 1244C The Football Season. import io import sys i ...

随机推荐

  1. WPF TreeView Indent 减少节点的缩进

    www.swack.cn - 原文链接:WPF TreeView Indent 减少节点的缩进 问题 最近一个需求,需要在界面中实现Windows资源管理器TreeView的界面.但是我发现,我做出的 ...

  2. 3D动漫人物代码

    <div id="page_end_html"> <script src="https://eqcn.ajz.miesnfu.com/wp-conten ...

  3. Openstack Nova 控制服务 和 计算服务 (六)

    Openstack Nova 控制服务 和 计算服务 (六) 引用: https://docs.openstack.org/ocata/zh_CN/install-guide-rdo/nova.htm ...

  4. 【RAC】11gRAC 搭建(VMware+裸设备)

    安装环境与网络规划 安装环境 主机操作系统:windows 7虚拟机VMware12:两台Oracle Linux R6 U5 x86_64 Oracle Database software: Ora ...

  5. 洛谷P1972 [SDOI2009]HH的项链(树状数组)

    题目链接: https://www.luogu.org/problemnew/show/P1972 题目描述: HH 有一串由各种漂亮的贝壳组成的项链.HH 相信不同的贝壳会带来好运,所以每次散步完后 ...

  6. let关键字:加强版的var关键字

    本文首发于个人网站:let关键字:加强版的var关键字 你好,今天大叔想和你唠扯唠扯 ES6 新增的关键字 -- let.再说 let 的具体用法之前,大叔想先和你说说大叔自己对 let 的感受 -- ...

  7. Java程序入门

    编写Java源程序 在d:\day01 目录下新建文本文件,完整的文件名修改为HelloWorld.java ,其中文件名为HelloWorld ,后缀名必须为.java . 用记事本打开 在文件中键 ...

  8. 如何将1rpx转为1rem

    最近我在开发的过程中,出现了一个需求,我需要把开发好的小程序倒模成H5页面,这里就涉及一个布局单位问题,我们小程序用的单位都rpx,是按照750rpx铺满整个页面来算的,可H5又不支持rpx单位,这里 ...

  9. U盘制作系统启动盘方法

    1.下载一个UltralSO用来把CentOS系统镜像写入U盘作为启动安装盘 U盘用一个空U盘,会格式化的. 下载下来,使用试用版就行 刻录完成.

  10. IDEA 2019 Unable to get current time from Google's servers 解决

    取消android support即可