您的位置:首页 > 健康 > 养生 > 每日一题。。

每日一题。。

2024/10/5 3:47:49 来源:https://blog.csdn.net/2303_79552392/article/details/141235077  浏览:    关键词:每日一题。。

对于这种计算边界的东西,烦死人,不过画个图也就解决了

Problem - B - Codeforces

#include <bits/stdc++.h>using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> PII;
#define pb emplace_back
//#define int ll
#define all(a) a.begin(),a.end()
#define x first
#define y second
#define ps push_back
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define lc u << 1
#define rc u << 1 | 1void solve();const int N = 1e6 + 10;signed main() {IOS;ll t = 1;cin >> t;while (t--)solve();return 0;
}void solve() {vector<PII> a(2);for(int i = 0; i < 2; ++ i){cin >> a[i].x >> a[i].y;}sort(all(a));//____,,,____//相加于一个点,或者不想交if(a[0].y <= a[1].x){ll ans = 1;if(a[0].y == a[1].x) ans ++;cout << ans << endl;return;}//相交点>= 1if(a[0].x == a[1].x){if(a[0].y <= a[1].y)//sort之后a0y <= a1y{ll ans = 1; if(a[0].y == a[1].y) ans--;cout << a[0].y - a[0].x + ans << endl;return;}}else//a0x < a1x{if(a[0].y <= a[1].y){ll ans = 1; if(a[1].y == a[0].y) ans --;cout << a[0].y - a[1].x + 1 + ans << endl;return;}else{cout << a[1].y - a[1].x + 1 + 1 << endl;return;}}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com