Mail.Ru Cup 2018 Round 2C(__gcd)
#include<bits/stdc++.h>
using namespace std;
long long mx(long long l1,long long r1,long long l2,long long r2){
return max(0LL,min(r1,r2)-max(l1,l2)+1);
}
int main(){
long long l1,r1,t1,l2,r2,t2;
while(~scanf("%lld%lld%lld%lld%lld%lld",&l1,&r1,&t1,&l2,&r2,&t2)){
l1++;//从0开始加一变为从1开始
r1++;
l2++;
r2++;
long long mnsuojin=__gcd(t1,t2);//有最大公约数又对不齐会导致一直对不齐(某些情况),mnsuojin是可移动的最小距离
long long daierta=abs(r1-r2)/mnsuojin*mnsuojin;//避免超时所以一步到位
long long ans=0;
if(r1==r2)
ans=mx(l1,r1,l2,r2);
else if(r1<r2){
r1+=daierta;
l1+=daierta;
ans=max(mx(l1,r1,l2,r2),mx(l1+mnsuojin,r1+mnsuojin,l2,r2));//前者和后者必定存在一个最优解
}
else if(r1>r2){
r2+=daierta;
l2+=daierta;
ans=max(mx(l1,r1,l2,r2),mx(l1,r1,l2+mnsuojin,r2+mnsuojin));
}
printf("%lld\n",ans);
}
return 0;
}
Mail.Ru Cup 2018 Round 2C(__gcd)的更多相关文章
- Mail.Ru Cup 2018 Round 2 C. Lucky Days(拓展欧几里得)
传送门 待参考资料: [1]:https://www.cnblogs.com/Patt/p/9941200.html •题意 a君,b君存在幸运周期: a君在第[ L1+k·t1,R1+k·t1]天为 ...
- Mail.Ru Cup 2018 Round 2 B. Alice and Hairdresser (bitset<> or 其他)
传送门 题意: 给出你序列 a,在序列 a 上执行两种操作: ① 0 :查询有多少连续的片段[L,...,R],满足 a[L,...,R] > l: ② 1 p d :将第 p 个数增加 d: ...
- Mail.Ru Cup 2018 Round 3
A:签到 #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> # ...
- Mail.Ru Cup 2018 Round 2
A:阅读理解. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> ...
- Mail.Ru Cup 2018 Round 2 Solution
A. Metro Solved. 题意: 有两条铁轨,都是单向的,一条是从左往右,一条是从右往左,Bob要从第一条轨道的第一个位置出发,Alice的位置处于第s个位置,有火车会行驶在铁轨上,一共有n个 ...
- Mail.Ru Cup 2018 Round 2 Problem C Lucky Days
设在第 $x$ 天二人都 lucky,则有 $\DeclareMathOperator{\lcm}{lcm}$ $ x = y_a t_a + R_a $ $ x= y_b t_ b + R_b$ 约 ...
- 【Mail.Ru Cup 2018 Round 2 C】 Lucky Days
[链接] 我是链接,点我呀:) [题意] [题解] 题解的作者: manish_joshi 对于任意一个k 因为那条直线(关于x,y的方程可以看出一条直线)的斜率>= 所以肯定会经过第一象限. ...
- [题解]Mail.Ru Cup 2018 Round 1 - D. Changing Array
[题目] D. Changing Array [描述] 给n个整数a[1],...,a[n],满足0<=a[i]<=2^k-1.Vanya可以对这n个数中任一多个数进行操作,即将x变为x' ...
- [题解]Mail.Ru Cup 2018 Round 1 - C. Candies Distribution
[题目] C. Candies Distribution [描述] n个小朋友排排坐吃糖糖,小朋友从左到右编号1到n.每个小朋友手上有一定数量的糖.对于第i个小朋友来说,编号比他小的小朋友中有li个小 ...
随机推荐
- django 使用内建过滤器实现文章摘要效果
django 使用内建过滤器实现文章摘要效果 前端html代码 <div class="list-group"> {% if articles %} {% for ar ...
- poj-2420 A Star not a Tree?(模拟退火算法)
题目链接: A Star not a Tree? Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5219 Accepte ...
- 利用perlin noise 生成 wood texture
%%% Perlin Noise %%% Wood_texture clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image P ...
- BurpSuite工具应用及重放攻击实验
一.BurpSuite工具介绍 BurpSuite是用于攻击web 应用程序的集成平台.它包含了许多工具,并为这些工具设计了许多接口,以促进加快攻击应用程序的过程.所有的工具都共享一个能处理并显示HT ...
- bzoj 2044 三维导弹拦截——DAG最小路径覆盖(二分图)
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2044 还以为是CDQ.发现自己不会三维以上的…… 第一问可以n^2.然后是求最长不下降子序列 ...
- 洛谷 P4220 & UOJ #347 通道 —— 随机化
题目:https://www.luogu.org/problemnew/show/P4220 http://uoj.ac/problem/347 先写了一下 n^2 和三棵树一样的情况,n^2 还写了 ...
- DOM基础知识整理
--<JavaScript高级程序设计>Chapter10学习笔记 一.节点层次 1.Node类型 1)(Node).nodeType属性 节点nodeType属性有12种. 检测node ...
- poj 1519 Digital Roots (计算根数字)
一.Description The digital root of a positive integer is found by summing the digits of the integer. ...
- Poj 1936,3302 Subsequence(LCS)
一.Description(3302) Given a string s of length n, a subsequence of it, is defined as another string ...
- Python:内置函数zip()
zip函数接受任意多个可迭代对象作为参数,将对象中对应的元素打包成一个tuple,然后返回一个可迭代的zip对象. 这个可迭代对象可以使用循环的方式列出其元素 若多个可迭代对象的长度不一致,则所返回的 ...