#include<bits/stdc++.h> #define int long long usingnamespace std; constint inf = 0x3f3f3f3f; typedeflonglong ll; signedmain() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while(t--) { int n, m, a, b; cin >> n >> m >> a >> b;
int num = abs(b - a) - 1; int catchTime = a - 1;//不能放炸弹的时间 if(b < a) catchTime = n - a; priority_queue<int> pq; int x; for(int i = 0; i < m; ++i){ cin >> x; pq.push(x); } //计算guard与hooligan的距离为num. int ans = 0; int time = catchTime + num; while(!pq.empty()) { if(time >= pq.top()) { ans++; time--; } pq.pop(); } cout << min(ans, num) << endl; } return0; }
E. Four Segments(签到)
题意
给四个线段,把他们摆在平面上,要求围出矩形,问矩形最大面积是多少。
分析
四个线段长度排序,按长和宽的短板效应取第一条和第三条长度相乘即可。
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include<bits/stdc++.h> usingnamespace std; constint inf = 0x3f3f3f3f; typedeflonglong ll; intmain() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while(t--) { int a[4]; for(int i = 0; i < 4; ++i) cin >> a[i]; sort(a, a + 4); cout << a[0] * a[2] << endl; } return0; }