版本比较
模拟赛代码
正文
增加 61 行删除 57 行
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596045678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364```cpp#include<bits/stdc++.h>using namespace std;int a[200005], sm[100005], st[100005];bool flag[200005];int main() { freopen("parrot.in", "r", stdin); freopen("parrot.out", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n, m; cin >> n >> m; for (int i = 1; i <= m; i++) st[i] = n; int ans = 0, cnt = 0; for (int i = 1; i <= n * m; i++) cin >> a[i]; memset(flag, 0, sizeof(flag)); memset(sm, 0, sizeof(flag)); for (int i = 1; i <= n * m; i++) { if (a[i] == a[i - 1] && !flag[i - 1]) { cnt++; sm[a[i]]++; flag[i] = 1; }else { st[a[i]]--; ans++; } } int jl = 0, lst = 0, r = 1;// for (int i = 1; i <= m; i++) cout << sm[i] << " "; cout << "\n";// for (int i = 1; i <= m; i++) cout << st[i] << " "; cout << "\n"; for (int i = 1; i <= m; i++) { if (sm[i] == 0) continue; while (r <= m && sm[i] != 0) { if (i == r) lst += st[i]; else { if (st[r] >= sm[i]) { st[r] -= sm[i]; sm[i] = 0; break; }else { sm[i] -= st[r]; st[r] = 0; } } r++; }// cout << "r = " << r << "\n"; if (jl > sm[i]) { jl -= sm[i]; sm[i] = 0; } else { sm[i] -= jl; jl = 0; }// cout << "lst = " << lst << "\n"; jl += lst; lst = 0;// cout << "jl = " << jl << "\nlst = " << lst << "\n";// for (int i = 1; i <= m; i++) cout << sm[i] << " "; cout << "\n";// for (int i = 1; i <= m; i++) cout << st[i] << " "; cout << "\n"; }// cout << ans << "\n"; if (jl != 0) ans -= jl; cout << ans << "\n"; }}const int N = 3010;const int inf = 0x3f3f3f3f;int n, m, f[N];struct Node{ int l, r;}no[N];bool vis[N];//初始状态int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); freopen("spring.in", "r", stdin); freopen("spring.out", "w", stdout); cin >> n >> m; for(int i = 1; i <= n; ++i){ cin >> no[i].l >> no[i].r; for(int j = no[i].l; j <= no[i].r; ++j){ vis[j] = true; } } memset(f, inf, sizeof(f)); n += 2; no[n - 1] = {0, 0}; no[n] = {m + 1, m + 1}; f[0] = 0; for(int i = 1; i <= m; ++i){//哪个点 if(vis[i]){ f[i] = f[i - 1]; continue; } for(int j = 1; j <= n; ++j){//使用哪个弹簧 if(no[j].r < i){//从左边扩展 int more = i - no[j].r; if(no[j].l - more - 1 < 1) f[i] = min(f[i], more); else f[i] = min(f[i], f[no[j].l - more - 1] + more); // cout << i << " " << j << " " << f[i] << " " << more << endl; } } } cout << f[m] << endl; return 0;}/*T1 spring 超级弹簧考虑f[i]表示覆盖i最少使用的次数到一个点时枚举所有弹簧覆盖n<=3000...按左端点排序后贪心 不对 一定用最近的吗 - 事实上不一定中英一定要互译-----------2026年NOICA联盟-NOIP模拟赛(十七)-DIV2----------8:05 不是下发文件炸了只能用Div1的了8:29 T2搞定了,但没有大样例,再说8:41 T3有点思路但不确定正确性,先开T48:45 不是现在大样例上去了...等一会测一下T2吧9:10 T1思路很巧妙,这是怎么想到的9:28 T2没取模气笑了9:29 T2没毛病li(喜)9:59 T3 OK了,兵贵神速啊 验证一下复杂度 时间没问题11:04 T4答案稍小,祭11:21 T4极限数据跑了10s,气死我了,不过至少得到72pts了,好耶11:43 T4优化到6.3s了,就差一点(bushi) 5.7s了
预计分数: 100 + 100 + 100 + 72 = 372*/