https://www.cometoj.com/contest/68/problem/A
enmmmm burst ll see many of the old story
#include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t,a,b,c,d; cin >> t; while(t--) { cin >> a >> b >> c >> d; if((a < 0 && c > 0) && (b < 0 && d > 0)) cout << "8\n"; else if((a < 0 && c > 0) || (b < 0 && d > 0)) cout << "6\n"; else cout << "5\n"; } return 0; }
https://www.cometoj.com/contest/68/problem/B
A sequence from small to large a1 a2 a3 a4 a5, if the sum-a5 <= a5 nice ring are all then result sum-a5
Otherwise the result is sum / 2, corresponding to each greedy take maximum number minus 2 both available proof by mathematical induction and until less than 1
if sum == 2 || 3, result = sum/2
Suppose sum> 3 && sum is an even number, SUM -A (max)> A (max)
SUM-A (max) -1> A '(max) is still established, so the hypothesis
#include<bits/stdc++.h> using namespace std; int main(){ int a[6] = {}; long long ans = 0; for(int i = 0; i < 5; i++) cin >> a[i], ans += a[i]; sort(a, a+5); if(ans-a[4] > a[4]) cout<< ans/2; else cout<< ans-a[4]; return 0; } /* 1 1 1 1 1 2 */
https://www.cometoj.com/contest/68/problem/C
Direct enumeration left the house seeking the right number of each house door house with double pointer
Lower_bound and can also be used to reduce the code upper_bound
/* 3 3 1 3 3 4 5 6 2 4 4 5 5 7 5 */ #include<bits/stdc++.h> using namespace std; #define _for(i,a,b) for(int i = (a); i < (b); i++) #define _rep(i,a,b) for(int i = (a); i <= (b); i++) #define l first #define r second const int N = 2e5+100; int n,m; pair<int, int > t[N], s[N]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin>> n >> m; _rep(i,1,n) cin >> t[i].l >> t[i].r; _rep(i,1,m) cin >> s[i].l >> s[i].r; int L = 1, R = 1, res = 0; _rep(i,1,n){ while(L <= m && s[L].r < t[i].l) L++; while(R <= m && s[R].l <= t[i].r) R++; res += R-L; } cout << res << endl; return 0; } //
#include<bits/stdc++.h> using namespace std; #define _for(i,a,b) for(int i = (a); i < (b); i++) #define _rep(i,a,b) for(int i = (a); i <= (b); i++) const int N = 2e5+100; int xl[N],xr[N],yl[N],yr[N]; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m; cin >> n >> m; _rep(i,1,n) cin >> xl[i] >> xr[i]; _rep(i,1,m) cin >> yl[i] >> yr[i]; int res = 0; _rep(i,1,n) res += (upper_bound(yl+1, yl+m+1, xr[i])-yl) - (lower_bound(yr+1, yr+m+1, xl[i])-yr); cout << res << endl; return 0; }
https://www.cometoj.com/contest/68/problem/D1?problem_id=3936
n <= 1e5, it is possible to use direct analog and binary prefix answers
// 1 // 5 3 2 7 // 1 1 1 // output 11 #include<bits/stdc++.h> using namespace std; #define _for(i,a,b) for(int i = (a); i < (b); i++) #define _rep(i,a,b) for(int i = (a); i <= (b); i++) #define ll long long const int N = 2e5+100; int a[N],pre[N]; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while(t--){ ll n,m,k,d,res = 0, sum = 0; cin >> n >> m >> k >> d; _rep(i,1,m) cin >> a[i], sum += a[i]; if(d >= n*sum) { cout << n*(m+k) << endl; continue;} sort(a+1, a+1+m); pre[0] = 0; _rep(i,1,m) pre[i] = pre[i-1]+a[i];// init 若是 +=,须得初始化 //_for(i,0,m) cout << pre[i] << " " ; cout << "\n"; _rep(i,0 , n-) { // Enumeration 0 ~ n finish time remaining roll sheets do subject LL Time = D - I * SUM, Score = I * (m + K), ANS = 0 ; IF (Time < 0 ) BREAK ; LL L = 0 , R & lt = m; the while (L <= R & lt) { LL MID = (L + R & lt) >> . 1 ; IF (pre [MID] * (Ni) <= Time) = MID ANS , L = MID + . 1 ; the else R & lt mid- = . 1 ; } Score+= (n-i)*(ans) + (time-pre[ans]*(n-i))/a[ans+1]; res = max(res, score); } cout << res << endl; } return 0; }
https://www.cometoj.com/contest/68/problem/D2?problem_id=3937
Since Q 5e4 n 1e9 not so enumerated directly n, m 1e5 unchanged but it can try to enumerate m,
assuming an optimal time to achieve depletion of P questions, there are many ways to make the first roll track Title P , the roll has been made of the number of sheets of these methods to segment a
score in the interval of the horizontal axis is the vertical axis in a linear function (straight line), so that the maximum value at both ends, the subject is calculated by enumerating the corresponding It takes a maximum value to the extremum (enmmmmmm generally understand, still do not know the specific details of the code)
#include <bits/stdc++.h> using namespace std; const int Maxn = 500005; int m, k, res, T, a[Maxn]; long long n, ans, now, D; int main() { scanf("%d", &T); while (T--) { now = 0, ans = 0, res = 0; scanf("%lld%d%d%lld", &n, &m, &k, &D); for (int i = 1; i <= m; i++) scanf("%d", &a[i]), now += a[i]; sort(a + 1, a + 1 + m); for (int i = 1; i <= m; i++) { int all = min(n, D / now); ans = max(ans, all * (long long) (m + k - res) + min((n - all) * a[i], D - all * now) / a[i] + n * res); if (D - a[i] * n < 0) { ans = max(ans, D / a[i] + n * res); break; } if (i != m) { int tmp = ceil((D - a[i] * n) / (double) (now - a[i])); if (D - tmp * now >= 0) ans = max(ans, (long long) tmp * (m + k - res) + min(n * a[i], D - tmp * now) / a[i] + n * res); } now -= a[i]; D -= a[i] * n; res++; } printf("%lld\n", ans); } return 0; }
https://www.cometoj.com/contest/68/problem/E?problem_id=3938
Is first determined: when k is larger than n is not clearly established, secondly when k is an odd number, an odd number of edges have no points is odd not established in the figure (drawn on rough paper is found under the, not strictly specific proof)
When k is established, it is considered a maximum number of edges directly deleted without side edge to a minimum to FIG full if n is odd, each point of the edges are connected to n-1 (even number), by deleting only k / 2 pieces either side to produce an odd edge point k
Similarly, when n is even, while each point is connected to n-1 (odd number), to keep only the k-th edge point does not delete, deleting (nk) / nk two sides can produce an even edge point
slightly mouthful, but draw a picture on the toilet paper glance
#include <bits/stdc++.h> using namespace std; #define _for(i,a,b) for(int i = (a); i < (b); i++) #define _rep(i,a,b) for(int i = (a); i <= (b); i++)int main(){ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); longlong t,n,k; cin >> t; while(t--) { cin >> n >> k; //cout<< n <<k <<" \n";if(k>n || k&1) cout<< ""renrendoushijwj \ the n- ; else { if(n&1) cout<< n*(n-1)/2-k/2 << endl; else cout << n*(n-1)/2-(n-k)/2 << endl; } } return 0; } /* 4 7 8 7 4 3 1 5 4 样例输出 1 renrendoushijwj 19 renrendoushijwj 8 */