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 ...
随机推荐
- TTTTTTTTTTTTTTTT #7 div1 A Breadth-First Search by Foxpower 在线LCA(倍增),模拟
A - Breadth-First Search by Foxpower Time Limit:2000MS Memory Limit:131072KB 64bit IO Format ...
- AcWing:175. 电路维修(bfs)
达达是来自异世界的魔女,她在漫无目的地四处漂流的时候,遇到了善良的少女翰翰,从而被收留在地球上. 翰翰的家里有一辆飞行车. 有一天飞行车的电路板突然出现了故障,导致无法启动. 电路板的整体结构是一个R ...
- fastjson =< 1.2.47 反序列化漏洞浅析
fastjson =< 1.2.47 反序列化漏洞浅析 iiusky 洛米唯熊 今天 文章出处: https://www.03sec.com/3240.shtmlhttps://www.secq ...
- Git与Repo 的使用
一.Linux常用命令 pwd 用于显示工作目录,执行pwd指令可立刻得知您目前所在的工作目录的绝对路径名称. chmod 用来变更文件或目录的权限. > ...
- Java内存缓存-通过Google Guava创建缓存
谷歌Guava缓存 Guava介绍 Guava是Google guava中的一个内存缓存模块,用于将数据缓存到JVM内存中.实际项目开发中经常将一些公共或者常用的数据缓存起来方便快速访问. Guava ...
- TCP输入 之 tcp_rcv_established
概述 tcp_rcv_established用于处理已连接状态下的输入,处理过程根据首部预测字段分为快速路径和慢速路径: 1. 在快路中,对是有有数据负荷进行不同处理: (1) 若无数据,则处理输入a ...
- Linux 解压小全
.gz 解压1:gunzip FileName.gz 解压2:gzip -d FileName.gz 压缩:gzip FileName .zip 解压:unzip FileName.zip 压缩:zi ...
- vue 添加一个二级目录
原先的: http://xxx.xx.xxx.xxx:xxx/#/ 现在的: http://xxx.xx.xxx.xxx:xxx/guangfu/#/
- C++学习 之 初识命名空间
声明: 本人自学C++, 没有计算机基础,在学习的过程难免会出现理解错误,出现风马牛不相及的现象,甚至有可能会贻笑大方. 如果有幸C++大牛能够扫到本人的博客,诚心希望大牛能给予 ...
- Struts数据回显和模型驱动
prams拦截器,可以把请求数据自动填充的action的属性中 举例1: JSP <input type=text name=userName /> <input type=text ...