标签:long scan 网上 turn ++ bit int names pre
被一道数论题卡了半天
网上的题解说只要匹配l或者r就行,想了下还真是。。
能让r1和r2对其就让他们对其,不能对其就讨论一下两种情况就可以了
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll cul(ll l1, ll r1, ll l2, ll r2, ll t) { l1 += t; r1 += t; return max(0ll, min(r1, r2) - max(l1, l2) + 1); } int main() { ll l1, r1, v1, l2, r2, v2; while(~scanf("%lld %lld %lld %lld %lld %lld", &l1, &r1, &v1, &l2, &r2, &v2)) { l1++, r1++, l2++, r2++; ll d = __gcd(v1, v2); ll l = abs(r1 - r2); ll ans = 0; ll t1 = l / d * d; ll t2 = t1 + d; ans = max(ans, cul(l1, r1, l2, r2, t1)); ans = max(ans, cul(l1, r1, l2, r2, t2)); ans = max(ans, cul(l2, r2, l1, r1, t1)); ans = max(ans, cul(l2, r2, l1, r1, t2)); cout << ans << endl; } return 0; }
标签:long scan 网上 turn ++ bit int names pre
原文地址:https://www.cnblogs.com/zsben991126/p/10825677.html