NOIP模拟1
赛时rank3,95,30,40,5,5
赛后hack,rank7,40,30,40,5,5
T1 分糖果
简要题意:
将
将每个数
可以的方案有三种
考虑到
点此查看代码
#include<bits/stdc++.h> #include<bits/extc++.h> // using namespace __gnu_pbds; // using namespace __gnu_cxx; using namespace std; #define infile(x) freopen(x,"r",stdin) #define outfile(x) freopen(x,"w",stdout) #define errfile(x) freopen(x,"w",stderr) using ll=long long;using ull=unsigned long long; const int N = 1e5 + 10; int n,a[N]; queue<int> tot[3]; signed main(){ #ifndef ONLINE_JUDGE infile("in.in");outfile("out.out"); #else #endif cin.tie(0)->sync_with_stdio(false); cout.tie(0)->sync_with_stdio(false); cin>>n; for(int i = 1;i <= n; ++i) cin>>a[i]; for(int i = 1;i <= n; ++i) tot[a[i]%3].push(i); int emm = min({tot[0].size(),tot[1].size(),tot[2].size()}); ll ans = 0,res = 0; for(int i = 0;i <= min(emm,2); ++i){ if(ans < (tot[0].size()-i)/3+(tot[1].size()-i)/3+(tot[2].size()-i)/3+i){ ans = (tot[0].size()-i)/3+(tot[1].size()-i)/3+(tot[2].size()-i)/3+i; res = i; } } cout<<ans<<'\n'; if(!ans) return 0; while(res--){ cout<<tot[0].front()<<' '<<tot[1].front()<<' '<<tot[2].front()<<'\n'; tot[0].pop();tot[1].pop();tot[2].pop(); } while(tot[0].size()>=3){ cout<<tot[0].front()<<' ';tot[0].pop(); cout<<tot[0].front()<<' ';tot[0].pop(); cout<<tot[0].front()<<'\n';tot[0].pop(); } while(tot[1].size()>=3){ cout<<tot[1].front()<<' ';tot[1].pop(); cout<<tot[1].front()<<' ';tot[1].pop(); cout<<tot[1].front()<<'\n';tot[1].pop(); } while(tot[2].size()>=3){ cout<<tot[2].front()<<' ';tot[2].pop(); cout<<tot[2].front()<<' ';tot[2].pop(); cout<<tot[2].front()<<'\n';tot[2].pop(); } }
T2 乒乓球
找循环节,不会打,待填
T3 与或
简要题意:
给定一个长度为|
运算符,&
运算符,用以上
样例输入1
4 2 1 3 5 7
样例输出1
7 ||&
样例输入2
4 1 1 3 5 7
样例输出2
7 &&|
有一个结论:&
放在|
前一定不劣。
证明:假设有三个相邻的位置x,y,z
,左边是∣
,右边是&
,那么结果最大是z
,假设左边是&
,右边是∣
,那么结果最小是z
。
考虑按位贪心,对于当前位置,若放了|
后后续最大答案仍是理论最大值,则放|
,反之,则放&
。
点此查看代码
#include<bits/stdc++.h> #include<bits/extc++.h> // using namespace __gnu_pbds; // using namespace __gnu_cxx; using namespace std; #define infile(x) freopen(x,"r",stdin) #define outfile(x) freopen(x,"w",stdout) #define errfile(x) freopen(x,"w",stderr) using ll=long long;using ull=unsigned long long; const int N = 2e5 + 10; int n,k,sum[N][61]; ll a[N]; inline ll check(int pos,ll val,int k){ if(pos <= n - k){ vector<int> t(60); for(int i = 0;i < 60; ++i) t[i] = sum[n-k][i] - sum[pos-1][i]; for(int i = 0;i < 60; ++i) if(t[i] != (n-k-pos+1) && ((val>>i)&1)) val ^= (1ll<<i); } if(k >= 1){ vector<int> t(60); for(int i = 0;i < 60; ++i) t[i] = sum[n][i] - sum[n - k][i]; for(int i = 0;i < 60; ++i) if(t[i]) val |= (1ll<<i); } return val; } signed main(){ #ifdef ONLINE_JUDGE infile("in.in");outfile("out.out"); #else #endif cin.tie(0)->sync_with_stdio(false); cout.tie(0)->sync_with_stdio(false); cin>>n>>k; for(int i = 1;i <= n; ++i) cin >> a[i]; for(int i = 1;i <= n; ++i){ for(int j = 0;j < 60; ++j) sum[i][j] = sum[i-1][j]; for(int j = 0;j < 60; ++j) sum[i][j] += ((a[i]>>j)&1); } ll mx = check(2,a[1],k); cout<<mx<<'\n'; int nowk = k;ll ans = 1; for(int i = 2;i <= n; ++i){ if(nowk >= 1 && check(i+1,ans|a[i],nowk-1) == mx){ cout<<'|'; ans |= a[i]; nowk--; } else cout<<'&',ans &= a[i]; } }
T4 跳舞
用
再考虑设
则有
注意处理ok的边界,
点此查看代码
#include<bits/stdc++.h> #include<bits/extc++.h> // using namespace __gnu_pbds; // using namespace __gnu_cxx; using namespace std; #define infile(x) freopen(x,"r",stdin) #define outfile(x) freopen(x,"w",stdout) #define errfile(x) freopen(x,"w",stderr) using ll=long long;using ull=unsigned long long; const int N = 510; bitset<N> ok[N]; int n,a[N],f[N]; bitset<N> gcd[N]; signed main(){ #ifndef ONLINE_JUDGE infile("in.in");outfile("out.out"); #else #endif cin.tie(0)->sync_with_stdio(false); cout.tie(0)->sync_with_stdio(false); cin >> n; for(int i = 1;i <= n; ++i) cin >> a[i]; for(int i = 1;i <= n; ++i) for(int j = 1;j <= n; ++j) gcd[i][j] = (__gcd(a[i],a[j])>1); for(int i = 1;i <= n; ++i) if(gcd[i][i-1] || gcd[i][i+1]) ok[i][i] = true; for(int i = 1;i <= n; ++i){ for(int j = 1;j < i; ++j){ ok[i][j] = true; } } for(int len = 2;len <= n; ++len){ for(int i = 1;i + len - 1 <= n; ++i){ int ed = i + len - 1; for(int j = i;j <= ed; ++j){ if(ok[i][ed]) break; ok[i][ed] = (ok[i][j-1]&&ok[j+1][ed]&&(gcd[j][i-1]||gcd[j][ed+1])); } } } for(int i = 2;i <= n+1; ++i){ for(int j = 0; j < i; ++j){ f[i] = max(f[i],f[j]+(i-j-1)*ok[j+1][i-1]); } } cout<<f[n+1]; }
T5 音乐播放器
概率dp,不会……,待填
总结:
还是
__________________________________________________________________________________________
本文来自博客园,作者:CuFeO4,转载请注明原文链接:https://www.cnblogs.com/hzoi-Cu/p/18290661
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】