CF 1244 C - The Football Season
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的更多相关文章
- [Codeforces 1244C] The Football Season
思维加枚举 题意 :足球赛,赢平所得到的分数分别为w和d,w>d,分别求赢平输的场数,输出一组即可,即x+y+z=n 且 xw+yd=p的一组解. 可以扩展公约数做,但由于注意到d和w<1 ...
- 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 ...
- [CF1244C] The Football Season【数学,思维题,枚举】
Online Judge:Luogu,Codeforces Round #592 (Div. 2) C Label:数学,思维题, 枚举 题目描述 某球队一共打了\(n\)场比赛,总得分为\(p\), ...
- American Football Vocabulary!
American Football Vocabulary! Share Tweet Share You’ll learn all about the vocabulary of American fo ...
- CodeForces-1244C-The Football Season-思维
The football season has just ended in Berland. According to the rules of Berland football, each matc ...
- 【Codeforces】CF Round #592 (Div. 2) - 题解
Problem - A Tomorrow is a difficult day for Polycarp: he has to attend \(a\) lectures and \(b\) prac ...
- Codeforces Round #592 (Div. 2)
A. Pens and Pencils 题目链接:https://codeforces.com/contest/1244/problem/A 题意: 给定五个数 a , b , c , d , k 求 ...
- codeforces #592(Div.2)
codeforces #592(Div.2) A Pens and Pencils Tomorrow is a difficult day for Polycarp: he has to attend ...
- 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使用html+css+js制作网站教程 准备
#1使用html+css+js制作网站教程 准备 本系列链接 0 准备 0.1 IDE编辑软件 0.2 浏览器 0.3 基础概念 0.3.1 html 0.3.2 css 0.3.3 js 0.4 文 ...
- Linux SSH , SCP 建立信任关系(免密传输)
最近有个需求,Jenkins需要将war传输到各个项目节点中,所以需要远程执行各个节点的shell脚本.但是中间有个输入密码的过程,在自动化部署中是行不通的,故需要增加免密登录.具体如下: 如果想在 ...
- python模块详解 | selenium(持续更新中)
目录: 关于selenium Selenium 安装Selenium 安装浏览器驱动 配置环境变量 selenium方法详解 定位元素 元素操作 浏览器操作 鼠标事件 浏览器事件 设置元素等待 多表单 ...
- 【Linux】如何查看命令来源于哪个包
Debian:(Ubuntu等) 先安装apt-file sudo apt-get install -y apt-file apt-file update 查询命令:(已查询ifconfig为例) r ...
- 二进制部署kubernetes
Kubernetes二进制安装 环境准备: 主机环境:做好主机名hosts文件映射 硬件2cpu 2G内存 192.168.30.21 k8s-master 192.168.30.22 k8s-no ...
- [Usaco2002 Feb]Rebuilding Roads重建道路
题目描述 一场可怕的地震后,奶牛用N个牲口棚(1 <= N <= 150,编号1..N)重建了农民John的牧场.奶牛没有时间建设多余的道路,所以现在从一个牲口棚到另一个牲口棚的道路是唯一 ...
- Python入门之修改jupyter启动目录
[导读]在给大家分享知识的过程中,我们也会分享一些小技巧,能够帮助大家在学习过程中有更好的体验.之前我们给大家分享了anaconda安装教程以及jupyter notebook使用方法,今天我们为大家 ...
- Mybatis总结(一)
Mybatis总结(一) 一.Mybatis启动流程(代码层面) 关于config.xml <?xml version="1.0" encoding="UTF-8& ...
- Redis连接池的相关问题分析与总结
https://mp.weixin.qq.com/s/juvr89lAvM0uuDmyWyvqNA 阿里干货课堂丨Redis连接池的相关问题分析与总结 原创 技术僧 Java进阶与云计算开发 2018 ...
- SVN 常见问题及解决方法
1.已跳过 'XXX' -- 节点处于冲突状态 解决方法:cd 进入到出错文件夹或文件所在目录,执行: svn resolved ./文件名(文件夹名)