尧图网站设计 尧图网站设计YAOTU DESIGN
ARTICLE DETAIL

资讯详情

深耕网站设计与一线实操的经验洞察。

2026牛客暑期多校训练营9题解

2026牛客暑期多校训练营9题解 B题思路n行n列要计算至少还需要点亮多少个格子才能使网格中存在至少一行或一列就对输入的每个xy累加计算然后对每行每列算最大的mmax然后n - mmax就可以了。复杂度是m n。代码#include bits/stdc.h using namespace std; typedef long long ll; void solve() { ll n,m; cin n m; vectorllx(n 1 ,0),y(n 1,0); for(ll i 1; i m; i){ ll xx,yy; cin xx yy; x[xx]; y[yy]; } ll mmax 0; for(ll i 1; i n; i){ mmax max({x[i],y[i],mmax}); } cout n - mmax; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll t 1; // cin t; while (t--) { solve(); } }H题思路就是偶数可以自消2变11奇数会分成偶数和奇数如果有偶个奇数那剩下偶数如果是奇个奇数则剩下奇数这个最多种看最大数值如果是奇数就是max(mmax_ou - 1,mmax_qi)要把偶数最大考虑进去偶数也是差不多的。代码#include bits/stdc.h using namespace std; typedef long long ll; void solve() { ll n; cin n; vectorllcc,dd; ll ma 0,mma 1; for(ll i 1; i n; i){ ll a; cin a; if(a 1){ cc.push_back(a); mma max(mma, a); } else{ dd.push_back(a); ma max(ma, a); } } ll cnt 0; if(cc.empty()){ cnt ma / 2; } else{ if(cc.size() 1){ mma max(ma - 1,mma); cnt mma / 2 1; } else{ ma max(mma -1,ma); cnt ma /2 ; } } cout cnt; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll t 1; // cin t; while (t--) { solve(); } }I题思路就是毒肯定越早越好所以就是分种类看最小回合就是用毒多少回合在用普攻多少回合可以死用二分减少复杂度就可以了。塔皮王朝了代码#includebits/stdc.h #define int long long using namespace std; const int N 50000; int poi[N], att[N]; int get(int x, int n) { if (n x) { return (((x 1) * x) 1LL); } else { return (((x x - n 1) * n) 1LL); } } void solve(){ int n, a, b; cin n a b; int tn n, mn 0x3f3f3f3f; for (int i 1; i N; i) { if (i 1) poi[i] a; else poi[i] poi[i - 1] - 1 a; att[i] att[i - 1] poi[i]; } for (int i 0; i N; i) { int cost 0; n tn; n - att[i]; if (n 0) { cost i; } if (n 0) { int ttn n; int l 0, r N, ans 0; while (l r) { n ttn; int mid ((r - l) 1) l; n - (mid * b) (get(poi[i] - 1, mid)); if (n 0) { l mid 1; } if (n 0) { r mid - 1; ans mid; } } cost i ans; } mn min(mn, cost); } cout mn endl; } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // mapint, vectorint, int mp; // mp[1].push_back(1); // cout mp[1][0] endl; int _ 1; // cin _; while (_--) solve(); return 0; }
返回列表