Python input/output boilerplate for competitive programming
The following code is my submission for Codeforces 1244C The Football Season.
import io
import sys
import math
def inverse(a, m):
u = 0
v = 1
while a != 0:
t = m // a
m -= t * a
a, m = m, a
u -= t * v
u, v = v, u
assert m == 1
return u
def main():
# It helps to use a input file when testing or debugging your code locally.
# with open("main.in", "r", encoding='utf-8') as f:
with sys.stdin as f:
n, p, w, d = map(int, f.readline().split())
g = math.gcd(w, d)
if p % g:
print(-1)
return
W = w // g
D = d // g
x = inverse(W, D)
y = (1 - W * x) // D
assert W * x + D * y == 1
m = p // g
x *= m
y *= m
ub = min(x // D, (n - x - y) // (W - D))
lb = (-y + W - 1) // W
if lb > ub:
print(-1)
return
X = x - lb * D
Y = y + lb * W
assert X >= 0 and Y >= 0 and X * w + Y * d == p and X + Y <= n
print(X, Y, n - X - Y)
main()
Notes:
//does floor divison in Python.
References
Python input/output boilerplate for competitive programming的更多相关文章
- Docker 在转发端口时的这个错误Error starting userland proxy: mkdir /port/tcp:0.0.0.0:3306:tcp:172.17.0.2:3306: input/output error.
from:https://www.v2ex.com/amp/t/463719 系统环境是 Windows 10 Pro,Docker 版本 18.03.1-ce,电脑开机之后第一次运行 docker ...
- PHP-FPM-failed to ptrace(PEEKDATA) pid 123: Input/output error
If you're running PHP-FPM you can see these kind of errors in your PHP-FPM logs. $ tail -f php-fpm.l ...
- NFS挂载异常 mount.nfs: Input/output error
[root@localhost ~]# vi /etc/exports #增加/nfs 192.168.10.132(rw,no_root_squash,no_all_squash,async) [r ...
- BIOS(Basic Input/Output System)是基本输入输出系统的简称
BIOS(Basic Input/Output System)是基本输入输出系统的简称 介绍 操作系统老师说,平时面试学生或者毕业答辩的时候他都会问这个问题,可见这个问题对于计算机专业的学生来说是如此 ...
- read()、write()返回 Input/output error, Device or resource busy解决
遇到的问题,通过I2C总线读.写(read.write)fs8816加密芯片,报错如下: read str failed,error= Input/output error! write str fa ...
- Angular 个人深究(三)【由Input&Output引起的】
Angular 个人深究(三)[由Input&Output引起的] 注:最近项目在做别的事情,angular学习停滞了 1.Angular 中 @Input与@Output的使用 //test ...
- dpdk EAL: Error reading from file descriptor 23: Input/output error
执行test程序时输出: EAL: Error reading from file descriptor 23: Input/output error 原因: 在虚拟机添加的网卡,dpdk不支持导致的 ...
- python's output redirect
[python's output redirect] fin = open("xx.txt", 'r'); print >>fin, "hello world ...
- html5 填表 表单 input output 与表单验证
1.<output> Js计算结果 <form oninput="res.value = num1.valueAsNumber*num2.valueAsNumber ...
随机推荐
- CCPC-Wannafly & Comet OJ 夏季欢乐赛(2019)E
题面 这个题暴好啊,考了很多东西. 首先设f(x)为离终点还有x步要走的期望步数,我们可以发现 : 1.x>=k时,x可以转移到的点的下标都<x. 2.x<k时,则可能走回到x或者下 ...
- HNOI2004 树的计数 | HNOI2008 明明的烦恼
题目链接:戳我 prufer序列的问题. prufer序列和无根树是一一对应的.而且在树中度数为k的点,在prufer序列中的出现次数为\(k-1\)次. 根据有限制次数的可重复元素的排列计数公式,我 ...
- 9030PCI CAN驱动开发点滴
1.配置EEPROM. 使用PlxMon打开9030,基本修改Spacex(0,1,2,3), Chip selectx(0,1,2,3), 中断状态INTCSR(0x74), 其他(0x78),详细 ...
- Js模块化开发--seajs和gruntJs
1.Seajs库 解决开发中的冲突依赖等问题,提供代码可维护性. SeaJS 是由玉伯开发的一个遵循 CommonJS 规范的模块加载框架,可用来轻松愉悦地加载任意 JavaScript 模块和css ...
- Windows上redis下载与安装
一.redis是什么 非关系型内存数据库,以key-value的形式将数据储存在内存中.Mysql是关系型数据库,数据是保存在硬盘中 二.redis下载安装 1.要安装Redis,首先要获取安装包. ...
- SpringMVC——返回值类型
1.void作为返回值类型 如果你的方法写成了Void就跟原来Servlet含义是差不多的 @RequestMapping("/index*") public void first ...
- 软工第04组 Alpha冲刺(1/6)
队名:new game 组长博客:戳 作业博客:戳 组员情况 鲍子涵(队长) 过去一段时间对项目的精度和分工进行了更加细致的划分,并初步进行了GamePlay逻辑部分的框架设计 GitHub签入记录: ...
- jenkins安装以及自由风格的项目搭建(jenkins+tomcat+svn)
jenkins提供了直接通过war包启动以及通过tomcat容器启动的启动方法,这里使用tomcat来启动jenkins,这也是我觉得更稳定的方法. 提前搭建好tomcat环境,这里我使用的版本是:A ...
- yum源问题
配置本地yum源 1.使用工具将iso文件上传到操作系统,或者直接挂载iso文件 2.配置yum #cd /etc/yum.repos.d/ 删除多余的repo文件 # vi /etc/yum.rep ...
- HTML中meta=“viewport”的介绍
viewport就是浏览器上用来显示网页的那部分区域 layout viewport:整个网页所占据的区域(包括可视也包括不可视的区域) 默认的 visual viewport:网页在浏览器上的可视 ...