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 ...
随机推荐
- 【基础】1001_Hello,World!
题目相关 [题目描述] 编写一个能够输出"Hello,World!"的程序,这个程序常常作为一个初学者接触一门新的编程语言所写的第一个程序,也经常用来测试开发.编译环境是否能够正常 ...
- 使用SharePoint App-Only获得访问权限
目前在开发SharePoint Online的过程中,主要使用通过Azure AD的方式获得应用的访问权限,但是SharePoint App-Only的方式依旧被保留了.使用这种方式进行CSOM开发比 ...
- 【Azure Redis 缓存】Azure Redis功能性讨论
关于使用Azure Redis服务在以下九大方面的功能性的解说: 高可用 备份可靠性 配置自动化 部署多样性 快速回档功能 数据扩容 SLA稳定性 数据安全性 监控系统 一:高可用 Azure Cac ...
- 剑指offer 面试题10:斐波那契数列
题目描述 大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0).n<=39 编程思想 知道斐波拉契数列的规律即可. 编程实现 class Solu ...
- servlet+jsp完成简单登录
将用户在注册界面中的数据填充到数据库相对应的表格中.当用户再次登录时,从数据库中拿到相应的数据查询并与页面的数据做对比,判断是否登陆成功. 需要在HTML文件中将form表单上的action属性值设置 ...
- 聊聊 g0
很多时候,当我们跟着源码去理解某种事物时,基本上可以认为是以时间顺序展开,这是编年体的逻辑.还有另一种逻辑,纪传体,它以人物为中心编排史事,使得读者更聚焦于某个人物.以一种新的视角,把所有的事情串连起 ...
- playwright自动化项目搭建
这是关于playwright系列介绍的最后一篇.搭建基于 playwright 的自动化项目. GitHub地址: https://github.com/defnngj/playwright-pro ...
- CMU数据库(15-445)Lab1-BufferPoolManager
0. 关于环境搭建请看 https://www.cnblogs.com/JayL-zxl/p/14307260.html 1. Task1 LRU REPLACEMENT POLICY 0. 任务描述 ...
- 5V充12.6V三节锂电池,5V升压12.6V的电路图
三串锂电池的充电电压是三串锂电池的最高电压值,就是12.6V了.5V充12.6V是5V给三串锂电池充电.如笔记本的USB口5V给三串锂电池充电,如5V的适配器或者手机充电器插上数据线给三串锂电池充电电 ...
- Redis 实战 —— 05. Redis 其他命令简介
发布与订阅 P52 Redis 实现了发布与订阅(publish/subscribe)模式,又称 pub/sub 模式(与设计模式中的观察者模式类似).订阅者负责订阅频道,发送者负责向频道发送二进制字 ...