codeforces 上的找两人的幸运天
Bob and Alice are often participating in various programming competitions. Like many competitive programmers, Alice and Bob have good and bad days. They noticed, that their lucky and unlucky days are repeating with some period. For example, for Alice days [la;ra] are lucky, then there are some unlucky days: [ra+1;la+ta−1], and then there are lucky days again: [la+ta;ra+ta] and so on. In other words, the day is lucky for Alice if it lies in the segment [la+kta;ra+kta] for some non-negative integer k
.
The Bob's lucky day have similar structure, however the parameters of his sequence are different: lb
, rb, tb. So a day is a lucky for Bob if it lies in a segment [lb+ktb;rb+ktb], for some non-negative integer k
.
Alice and Bob want to participate in team competitions together and so they want to find out what is the largest possible number of consecutive days, which are lucky for both Alice and Bob.
The first line contains three integers la
, ra, ta (0≤la≤ra≤ta−1,2≤ta≤109
) and describes Alice's lucky days.
The second line contains three integers lb
, rb, tb (0≤lb≤rb≤tb−1,2≤tb≤109
) and describes Bob's lucky days.
It is guaranteed that both Alice and Bob have some unlucky days.
Print one integer: the maximum number of days in the row that are lucky for both Alice and Bob.
0 2 5
1 3 5
2
0 1 3
2 3 6
1
The graphs below correspond to the two sample tests and show the lucky and unlucky days of Alice and Bob as well as the possible solutions for these tests.


题意 : 两个人轮流会有幸运天,给你两个人的幸运天的分布情况,是按周期的,问最终重复的幸运天最多是多少?
思路分析 :

代码示例 :
#define ll long long
ll l1, r1, t1;
ll l2, r2, t2; ll gcd(ll a, ll b){
return b==0?a:gcd(b, a%b);
} void solve() {
if (l1 > l2) {swap(l1, l2); swap(r1, r2); swap(t1, t2);}
ll len1 = r1-l1+1, len2 = r2-l2+1;
ll g = gcd(t1, t2);
ll ans = 0;
ll d = (l2-l1)%g;
ans = max(ans, min(len1-d, len2));
ll yd = g-d;
ans = max(ans, min(len1, len2-yd));
printf("%lld\n", ans);
} int main() {
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout); cin >> l1 >> r1 >> t1;
cin >> l2 >> r2 >> t2; solve();
return 0;
}
codeforces 上的找两人的幸运天的更多相关文章
- 用python实现了一下:甲乙两人互猜数字(数理逻辑)
今天在园子里看到博客:超难面试题:甲乙两人互猜数字(数理逻辑).然后琢磨了半天,写了个Python程序实现算法,我得出来的结果是1,6或1,8或35,42的组合, 不知道是否正确,请高人指点? 下面列 ...
- linux下实现两人、三人无序对话功能
序:引子 对话功能实际上就是利用管道见得通信.最原始的是一方发另一方收,不能进项交互,发送方的代码如下: /*============================================ ...
- codeforces上某题
一道codeforces上的题目. 题目大意: 定义有k个不同的字符的字符串为好字符串.现在给出一个字符串,求解对该字符串的每个前缀Si至少是多少个好字符串的连接,若不能由好字符串连接而成则输出-1. ...
- 《移山之道》第十一章:两人合作 读书笔记 PB16110698 第六周(~4.15)
本周在考虑阅读材料时,我翻阅了<移山之道>,正好看到这一章:两人合作,心想:正好,我们正值结对作业的紧要关头,书中两人合作的宝贵经验和教诲应当对我们有很大帮助.于是,我开始一边在ddl苦 ...
- 这份github上被14万人点赞的Java教程太强了
前几天有个小伙伴加我之后问了下面的这个问题.我看到后是一脸懵逼的状态,jcombobox?实话说,我已经完全忘了在Java中还有这么个东西. 在网上一番搜索后,才发现原来它是 swing 中的下拉列表 ...
- kindeditor多图片上传找不到action原来是private File upload成员变量惹得祸
kindeditor多图片上传找不到action原来是private File upload成员变量惹得祸
- curl文件上传有两种方式,一种是post_fileds,一种是infile
curl文件上传有两种方式,一种是POSTFIELDS,一种是INFILE,POSTFIELDS传递@实际地址,INFILE传递文件流句柄! );curl_setopt($ch, CURLOPT_PO ...
- 在Activiti官方源码上提交的两个bugfix
前段时间在Activiti官方源码上提交了两个bugfix,截图为证. 第1个是BPMN model输出的bug:
- 17.从键盘上输入一个正整数n,请按照以下五行杨辉三角形的显示方式, 输出杨辉三角形的前n行。请采用循环控制语句来实现。 (三角形腰上的数为1,其他位置的数为其上一行相邻两个数之和。) 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1
17.从键盘上输入一个正整数n,请按照以下五行杨辉三角形的显示方式, 输出杨辉三角形的前n行.请采用循环控制语句来实现. (三角形腰上的数为1,其他位置的数为其上一行相邻两个数之和.) 1 1 1 1 ...
随机推荐
- Springboot-webscoket with sockjs
新建springboot maven工程,引入以下包 <dependency> <groupId>org.springframework.boot</groupId> ...
- 解决input number类型上下滚动 禁用滚轮事件
1.去掉input在type="number"时的上下箭头 <style> input::-webkit-outer-spin-button,input::-webki ...
- UPC 2019年第二阶段我要变强个人训练赛第十六场
传送门: [1]:UPC比赛场 [2]:UPC补题场 F.gu集合(数论) •题目描述 题目描述: Dew有一个长为n的集合S. 有一天,他想选k个不同的元素出来做游戏. 但是Dew只有两只手,所以他 ...
- P1052 国王放置问题
题目描述 在n*m的棋盘上放置k个国王,要求k个国王互相不攻击,有多少种不同的放置方法.假设国王放置在第(x,y)格,国王的攻击的区域是:(x-1,y-1), (x-1,y),(x-1,y+1),(x ...
- es6笔记 day2---函数默认参数、箭头函数、剩余参数
函数变化: 1.函数默认参数 2.函数参数默认是已经定义了,不能再使用let.const声明 3.扩展运算符.rest运算符 ...就是扩展运算符,它的作用就是把数组给展开 结合函数使用传参,也可以将 ...
- tensorflow中models的安装
tensorflow中models的安装参看网址: 1. Tensorflow Object Detection API Windows Install Guide http://www.insigh ...
- Date日期时间相关
最近在封装一个关于时间函数的功能时,竟发现这些最基本的函数都有些生疏,于是进来来总结复习下,巩固自己记忆的同时,希望能帮助到需要的人 首先了解下日期对象相关的方法 var date = new Dat ...
- windows系统锁屏及修改密码项目开发经验记录
改造windows开机.锁屏登录流程需要使用微软停供的Credential Providers工程,编译出来是dll,安装在C:\windows\system32目录下,然后注册注册表(运行工程生成的 ...
- Vsual Studio 2010可用的sqlite驱动程序(实体数据模型使用)
背景 昨天一个旧的项目(.net framework 4 + EF4 +sqlite + edmx db first),数据库结构有变更,要更新实体edmx模型 先是到官网下载最新的驱动,结果不能更新 ...
- 微信 HTML5 VIDEO 视频播放解决方案
原文链接:https://www.jianshu.com/p/e4573acf6564 webkit-playsinline && playsinline="true&quo ...