当前位置: 首页 > news >正文

CCPC2025郑州区域赛题解

b5ecafc83d0f4428bfa9b16beeb1b54e
//B
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;using ll = long long;
const ll mod = 1e9 + 7;void solve() {const int D = 3;vector<ll> sz(D);for (int i = 0; i < D; i++) cin >> sz[i];vector<ll> cut(D); // p, q, rfor (int i = 0; i < D; i++) {cin >> cut[i];cut[i]++;}ll n;cin >> n;vector<vector<ll>> pts(n, vector<ll>(D));for (int i = 0; i < n; i++) {for (int j = 0; j < D; j++) {cin >> pts[i][j];}}ll total = 1;for (int w = 0; w < D; w++) total *= cut[w];if (n % total != 0) {cout << 0 << endl;return;}ll each = n / total;vector<vector<ll>> pos(D);ll ans = 1;for (int w = 0; w < D; w++) {vector<ll> v(n);for (int i = 0; i < n; i++) v[i] = pts[i][w];sort(v.begin(), v.end());ll step = n / cut[w];for (int i = 0; i < n; i += step) {pos[w].push_back(v[i]);if (i != 0) {ans = ans * (v[i] - v[i - 1]) % mod;}}}vector<ll> cnt(total, 0);for (auto& p : pts) {ll id = 0;for (int w = 0; w < D; w++) {ll j = upper_bound(pos[w].begin(), pos[w].end(), p[w]) - pos[w].begin() - 1;id = id * cut[w] + j;}cnt[id]++;}for (ll x : cnt) {if (x != each) ans = 0;}cout << ans << endl;
}int main() {ios::sync_with_stdio(false);cin.tie(0);solve();return 0;
}
//G
#include <bits/stdc++.h>
#define int long long 
using namespace std;
int T,a,b,c,dis[2010][2010],inq[2010][2010],md;
queue<pair<int,int> > q;
void dijkstra(){md=(1<<((int)floor(log2(b))+1));for(int i=0;i<md;i++){for(int j=0;j<b;j++){dis[i][j]=2e18;}}dis[a%md][a%b]=a;q.push({a%md,a%b});while(!q.empty()){int x=q.front().first,y=q.front().second;q.pop();inq[x][y]=0;if(dis[(x+b)%md][y]>dis[x][y]+b){dis[(x+b)%md][y]=dis[x][y]+b;if(!inq[(x+b)%md][y]){q.push({(x+b)%md,y});inq[(x+b)%md][y]=1;}}if(dis[x^b][(y-x+(x^b)+b)%b]>(dis[x][y]^b)){dis[x^b][(y-x+(x^b)+b)%b]=dis[x][y]^b;if(!inq[x^b][(y-x+(x^b)+b)%b]){q.push({x^b,(y-x+(x^b)+b)%b});inq[x^b][(y-x+(x^b)+b)%b]=1;}}}for(int i=0;i<md;i++){if(dis[i][c%b]<=c){cout<<"YES"<<endl;return ;}}cout<<"NO"<<endl;
}
signed main(){ios::sync_with_stdio(0);cin>>T;while(T--){cin>>a>>b>>c;dijkstra();}return 0;
}
/*
5
1 6 7
7 5 13
8 3 16
7 6 17
2 7 8
*/
//I
#include<bits/stdc++.h>
using namespace std;
#define int long longconst int mod = 998244353;
const int maxn = 5010;
int n, k, ans;
int fact[maxn], inv_fact[maxn], v[maxn];int inv(int a)
{int res = 1;int b = mod - 2;while (b){if (b & 1)res = res * a % mod;a = a * a % mod;b >>= 1;}return res;
}int C(int n, int m)
{if (n < m) return 0;return fact[n] * inv_fact[m] % mod * inv_fact[n - m] % mod;
}signed main()
{cin >> n >> k;fact[0] = 1;for (int i = 1; i <= maxn - 10; i++)fact[i] = fact[i - 1] * i % mod;for (int i = 0; i <= maxn - 10; i++)inv_fact[i] = inv(fact[i]);for (int i = 1; i <= n; i++)v[i] = i;int base_poss = inv_fact[n];int poss = 1;for (int i = 1; i <= k; i++){int res = 1ll;for (int j = 1; j < n; j++){res = res * (1ll + v[j]) % mod;v[j] = v[j] * j % mod;}if (i % 2 == 0)res = (mod - res) % mod;res = res * C(k, i) % mod;poss = poss * base_poss % mod;ans = (ans + res * poss) % mod;}cout << ans;return 0;
}
//J
#include <iostream>
#include<vector>
#include<map>
using namespace std;using ll = long long;
const int BIT = 32;
const ll mod = 998244353;ll qpow(ll a, ll b) {ll res = 1;while (b) {if (b & 1) res = res * a % mod;b >>= 1;a = a * a % mod;}return res;
}void solve() {int n, m;cin >> n >> m;vector<ll> row(n), col(m);for (ll& x : row) cin >> x;for (ll& x : col) cin >> x;vector<map<ll, ll>> mp(BIT);for (int j = 0; j + 1 < m; j++) {if ((col[j] ^ col[j + 1]) != 1) continue;for (int d = 2; d < BIT; d++) {ll mask = 1LL << d;mp[d][col[j] % mask]++;}}ll ans = 0;for (int i = 0; i + 1 < n; i++) {ll delta = row[i] ^ row[i + 1];for (int d = 2; d < BIT; d++) {ll mask = 1LL << d;if (delta != mask - 2) continue;ll tar = (mask - 2) - (1LL << (d - 1));tar ^= row[i];tar %= mask;ans += mp[d][tar];}}cout << ans << endl;
}int main() {ios::sync_with_stdio(false);cin.tie(nullptr);int T;cin >> T;while (T--) solve();return 0;
}
//K
#include<bits/stdc++.h>
using namespace std;
const int inf=1e9;
int T,n,a[500050],st0[500050][30],st1[500050][30],vis[1000010],mx[1000010];
int ed0[500050][30],ed1[500050][30],mxr[1000010];
stack<int> s;
int Ask(int l,int r,int id){if(l>r){return inf;}int k=log2(r-l+1),x=r-(1<<k)+1;if(id){return min(st0[l][k],st0[x][k]);}return min(st1[l][k],st1[x][k]);
}
int Askr(int l,int r,int id){if(l>r){return inf;}int k=log2(r-l+1),x=r-(1<<k)+1;if(id){if(st0[l][k]<st0[x][k]){return ed0[l][k];}return ed0[x][k];}if(st1[l][k]<st1[x][k]){return ed1[l][k];}return ed1[x][k];
}
void solve(){cin>>n;while(!s.empty()){s.pop();}for(int i=1;i<=n;i++){vis[i]=mx[i]=mxr[i]=0;}for(int j=0;j<25;j++){for(int i=1;i+(1<<(j+1))-1<=n;i++){st0[i][j]=st1[i][j]=ed0[i][j]=ed1[i][j]=0;}}for(int i=1;i<=n;i++){cin>>a[i];if(i%2==1){ed0[i][0]=i;st0[i][0]=a[i];st1[i][0]=inf;continue;}ed1[i][0]=i;st1[i][0]=a[i];st0[i][0]=inf;}for(int j=0;j<25;j++){for(int i=1;i+(1<<(j+1))-1<=n;i++){if(st0[i][j]<st0[i+(1<<j)][j]){st0[i][j+1]=st0[i][j];ed0[i][j+1]=ed0[i][j];}else{st0[i][j+1]=st0[i+(1<<j)][j];ed0[i][j+1]=ed0[i+(1<<j)][j];}if(st1[i][j]<st1[i+(1<<j)][j]){st1[i][j+1]=st1[i][j];ed1[i][j+1]=ed1[i][j];}else{st1[i][j+1]=st1[i+(1<<j)][j];ed1[i][j+1]=ed1[i+(1<<j)][j];}}}//cout<<777<<endl;for(int i=1;i<=n;i++){//    cout<<i<<endl;if(s.empty()){s.push(i);vis[i]=0;mx[i]=Ask(i,n,(i+1)%2);mxr[i]=Askr(i,n,(i+1)%2);//cout<<777<<endl;continue;}int u=s.top();//cout<<778<<endl;mx[i]=Ask(i,mxr[u]-1,(i+1)%2);if(mx[i]>=a[u]&&mx[u]==a[i]){vis[i]=1;//cout<<777<<endl;
            s.pop();continue;}//    cout<<777<<endl;vis[i]=0;mxr[i]=Askr(i,mxr[u]-1,(i+1)%2);s.push(i);}for(int i=1;i<=n;i++){if(vis[i]){cout<<")";continue;}cout<<"(";}cout<<endl;
}
int main(){ios::sync_with_stdio(0);cin>>T;while(T--){solve();}return 0;
}
/*
5
6
4 1 5 4 1 1
4
1 2 3 2
4
1 3 1 2
2
2 1
8
8 5 2 6 1 4 3 7
*/
//M
#include<bits/stdc++.h>
using namespace std;int T;
string s;string oplus(string a, string b)
{int alen = a.size(), blen = b.size();
// cout <<"A:" << a << ' ' <<"B:" << b << '\n';int i;for (i = 0; i < alen && a[i] == '0'; i++);if (i == alen)a = "0";elsea = a.substr(i);for (i = 0; i < blen && b[i] == '0'; i++);if (i == blen)b = "0";else b = b.substr(i);alen = a.size(), blen = b.size();string ans = "";for (int j = 0; j < min(alen, blen); j++)ans += (a[alen - j - 1] == b[blen - j - 1] ? '0' : '1');if (alen > blen){for (int j = alen - blen - 1; j >= 0; j--)ans += a[j];}else if (alen < blen){for (int j = blen - alen - 1; j >= 0; j--)ans += b[j];}reverse(ans.begin(), ans.end());int len = ans.size();for (i = 0; i < len && ans[i] == '0'; i++);if (i == len)return "0";return ans.substr(i);
}string maxx(string a, string b)
{int alen = a.size(), blen = b.size();if (alen != blen)return alen > blen ? a : b ;for (int i = 0; i < alen; i++){if (a[i] > b[i])return a;else if (a[i] < b[i])return b;}return a;
}int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin >> T;while (T--){cin >> s;int n = s.size();string cuta, cutb;if (n == 3){cuta = s[0], cutb = s[n - 1];cout << oplus(cuta, cutb) << '\n';continue;}cuta = s[0], cutb = s.substr(2);string ans1 = oplus(cuta, cutb);cuta += s[1];cutb = s.substr(3);string ans2 = oplus(cuta, cutb);cuta = s.substr(0, n - 2);cutb = s[n - 1];string ans3 = oplus(cuta, cutb);cout << maxx(ans1, maxx(ans2, ans3)) << '\n';}return 0;
}

 

http://www.jsqmd.com/news/681949/

相关文章:

  • 从零到一:手把手教你用Zephyr RTOS在STM32上点亮第一个LED(附完整工程)
  • 别再死记硬背了!用ChatGPT/Notion AI帮你快速生成LaTeX数学公式(附常用符号清单)
  • 用TensorFlow Lite在树莓派上部署目标检测
  • 番茄小说下载器完整使用指南:从零开始掌握小说离线保存技巧
  • 仅限内部分享:微软Build 2024未公开的.NET 11 System.AI预览版API清单(含3个已标记[Obsolete]但仍在用的关键接口)
  • PowerToys中文汉化版:解锁Windows效率潜能的终极解决方案
  • League Akari:英雄联盟玩家的智能私人助手,全面解决游戏效率与数据隐私难题
  • 用LVGL官方Demo给你的STM32 TFT屏快速做个UI原型:以Widgets Demo为例
  • 别再手动克隆了!用VMware SRM搞定多站点容灾,这份部署避坑指南请收好
  • Blender建筑建模终极指南:Building Tools插件让你的3D创作提速10倍
  • 从‘乱炖’到‘泾渭分明’:一致性聚类(Consensus)如何拯救你的生物信息学数据分析
  • 别再手动导数据了!用Kettle 9.2零代码搞定MySQL表同步(附JDBC驱动避坑指南)
  • Java原生镜像内存优化已进入深水区!这4个被官方文档刻意弱化的Substrate VM内存陷阱,正在 silently 吞噬你的SLA
  • 魔兽争霸3优化升级指南:5分钟解锁现代游戏体验
  • 别再傻傻分不清了!一文搞懂Autosar NVM里的Sector、Page和Block(以英飞凌TC3xx为例)
  • claude学习
  • 别再为IRF堆叠脑裂发愁了!手把手教你用LACP MAD给H3C交换机上个双保险
  • Matlab数据处理进阶:手把手教你用textscan函数解析带引号、日期和空值的CSV文件
  • 【DeepSeek】ARM 异常级别切换机制详解
  • 手机打字效率翻倍:搜狗输入法隐藏的拼音分词和发送键优化全攻略
  • 别再只会arp -a了!揭秘Wireshark抓包找IP的底层原理与常见误区
  • Easy-Scraper终极指南:用Rust快速简化网页数据提取的完整方案
  • Docker容器逃逸防护升级(沙箱纵深防御白皮书):基于seccomp-bpf+userns+no-new-privileges的生产级加固实践
  • 富士胶片ApeosPort 3410SD网络打印机安装:从驱动下载到静态IP设置,保姆级避坑全记录
  • QT窗体自适应避坑指南:为什么你的resizeEvent总失效?
  • 终极免费激活方案:5分钟搞定Windows与Office永久激活的完整指南
  • 知识图谱实战:手把手用PyTorch复现TuckER模型完成链接预测任务
  • Vue Antd Admin架构实战:如何构建高性能企业级中后台系统
  • 基于安卓的心理健康自评与干预系统毕设
  • 别再死记硬背DC脚本了!一个真实项目带你搞定Synopsys DC综合全流程(附完整脚本)