codeforce #925 (div3) 题解

D. Divisible Pairs

给出数组 a a a,如果二元组 ( i , j ) (i,j) (i,j)满足 a i + a j m o d x = = 0 & & a i − a j m o d y = = 0 a_i + a_j mod x ==0 \&\& a_i - a_j mod y == 0 ai+ajmodx==0&&aiajmody==0,则beauty。其中 i < j i<j i<j

根据题意不难得出,符合条件的二元组应满足
a i m o d x + a j m o d x = x a i m o d y = a j m o d y a_i \mod x + a_j \mod x = x \\ a_i \mod y = a_j \mod y aimodx+ajmodx=xaimody=ajmody

所以用 ( a i m o d x , a i m o d y ) (a_i \mod x, a_i \mod y) (aimodx,aimody)作为key,对于每个元素 a i a_i ai查找 ( x − a i m o d x , a i m o d y ) (x- a_i \mod x, a_i \mod y) (xaimodx,aimody)的个数

#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <time.h>
#include <set>
#include <map>
#include <queue>#define IOS     ios::sync_with_stdio(0);cin.tie(0);
#define rep(index,start,end) for(int index = start;index < end; index ++)
#define drep(index,start,end) for(int index = start;index >= end; index --)using namespace std;typedef long long ll;
ll gcd(ll a, ll b){ll t;while(b){t = b;b = a % b;a = t;}return a;
}const int maxn = 2e5+5;typedef pair<int, int> key;
int n,x,y;
map<key, int> store;
int main() {IOSint t;cin>>t;while(t--) {store.clear();cin>>n>>x>>y;int tmp;ll sum = 0LL;rep(i,0,n) {cin>>tmp;int modx = tmp % x;int mody = tmp % y;key now ={modx, mody};// calint bmody = tmp % y;int bmodx = (x - tmp%x) % x;sum += store[{bmodx, bmody}];if (store.find(now) != store.end()) {store[now] += 1;} else {store[now] = 1;}}cout<<sum<<endl;}return 0;
}

E. Anna and the Valentine’s Day Gift 博弈论

俩人玩游戏,一个能选一个数reverse,一个能选一个数拼接,看最后的结果能不能大于 1 0 m 10^m 10m

如果想要减少最终结果的位数,那么必须reverse之后产生前导零,例如10000,反转后变成1。那么这道题就变成了对反转后产生前导零个数的排序。注意我们的对手不傻,当我们把产生最多前导零的数字反转后,对手肯定会把产生第二多的拼接保护,防止最终结果位数减少,所以只能减去排序结果的偶数位

#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <time.h>
#include <set>
#include <map>
#include <queue>#define IOS     ios::sync_with_stdio(0);cin.tie(0);
#define rep(index,start,end) for(int index = start;index < end; index ++)
#define drep(index,start,end) for(int index = start;index >= end; index --)using namespace std;typedef long long ll;
ll gcd(ll a, ll b){ll t;while(b){t = b;b = a % b;a = t;}return a;
}const int maxn = 2e5+5;struct node{int digit;int zero;
};int n,m;
node store[maxn];
bool cmp(const node& a, const node& b) {return a.zero > b.zero;
}
int main() {IOSint t;cin>>t;while(t--) {int tmp;cin>>n>>m;int sum = 0;rep(i,0,n) {cin>>tmp;int dig = 0;int zero = 0;bool leading = true;while(tmp > 0) {dig ++;if (leading && !(tmp % 10)) {zero ++;} else {leading = false;}tmp /= 10;}
//            cout<<"dig :"<<dig<<" zero:"<<zero<<endl;store[i].digit = dig;store[i].zero = zero;sum += dig;}sort(store, store+n, cmp);
//        cout<<"test log:"<<store[0].zero<<endl;for(int i=0;i<n;i+=2) {sum -= store[i].zero;}if (sum < m+1) {cout<<"Anna"<<endl;} else {cout<<"Sasha"<<endl;}}return 0;
}

https://codeforces.com/contest/1931/problem/F 拓扑排序

给几个数组,第一位没有用,问有没有一个排列能满足这几个数组中元素的先后关系。

数组给出的顺序天然形成有向图。像 1 → 2 1 \rightarrow 2 12 2 → 1 2 \rightarrow 1 21这种矛盾的顺序必然是不存在序列的,也就是说给出的关系不能有环。所以简单套一个拓扑排序就可以了


#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <time.h>
#include <set>
#include <map>
#include <queue>#define IOS     ios::sync_with_stdio(0);cin.tie(0);
#define rep(index,start,end) for(int index = start;index < end; index ++)
#define drep(index,start,end) for(int index = start;index >= end; index --)using namespace std;const int maxn = 2e5+5;int store[maxn];
vector<int> adj[maxn];
int in_degrad[maxn];
queue<int> Q;
int main() {IOSint t;cin>>t;while(t--) {int n,k;cin>>n>>k;// initmemset(in_degrad, 0, sizeof(in_degrad));rep(i,0,n+1) adj[i].clear();while(!Q.empty()) Q.pop();rep(i,0,k) {rep(j,0,n) cin>>store[j];rep(j,1,n-1) {int commonA = store[j];int commonB = store[j+1];if (find(adj[commonA].begin(), adj[commonA].end(), commonB) == adj[commonA].end()) {adj[commonA].push_back(commonB);in_degrad[commonB] ++;}}}rep(i,1,n+1) {if (!in_degrad[i])Q.push(i);}while (!Q.empty()) {int now = Q.front();Q.pop();int len = adj[now].size();rep(i,0,len) {int next = adj[now][i];if (-- in_degrad[next] == 0)Q.push(next);}}bool _loop = false;rep(i,1,n+1)if (in_degrad[i]) {
//                cout<<i<<' '<<in_degrad[i]<<endl;_loop = true;break;}cout<<(_loop? "NO":"YES")<<endl;}return 0;
}

G. One-Dimensional Puzzle 高二排列组合问题

题干太长懒得翻译 有多少种排列方式可以把给出的所有形状拼成一个长条。

请添加图片描述
大概就是这么个拼接的方法。shape 1和shape 2的个数相差不能超过1,超过就拼不出来;shape 3和shape 4就是造成不同拼接方式的关键,穿插在shape 1和shape 2的间隙,要注意shape 3是可以自拼接,并不是每个间隙只能塞一个

#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <time.h>
#include <set>
#include <map>
#include <queue>#define IOS     ios::sync_with_stdio(0);cin.tie(0);
#define mem(A,B) memset(A,B,sizeof(A));
#define rep(index,start,end) for(int index = start;index < end; index ++)
#define drep(index,start,end) for(int index = start;index >= end; index --)using namespace std;typedef long long ll;const int maxn = 3e6+5;
const int mod = 998244353;ll fact[maxn];ll pow_mod(ll x, ll p) {if (p == 0) {return 1;}if (p % 2 == 0) {ll y = pow_mod(x, p / 2);return (y * y) % mod;}return (x * pow_mod(x, p - 1)) % mod;
}ll inv(ll x) {return pow_mod(x, mod - 2);
}
ll cnk(ll n, ll k) {ll res = fact[n];res = (res * inv(fact[k])) % mod;res = (res * inv(fact[n - k])) % mod;
//    cout<<"n:"<<n<<" k:"<<k<<" res:"<<res<<endl;return res;
}
int abs(int num) {return num<0 ? -num :num;
}int store[5];
int main() {IOSfact[0] = fact[1] = 1;rep(i,2,maxn)fact[i] = (fact[i-1] * i) % mod;int t;cin>>t;while(t--) {rep(i,0,4) cin>>store[i];if (store[0] == 0 && store[1] == 0) {cout<<((store[2]!=0 && store[3] != 0)? 0:1)<<endl;continue;}int dfi = abs(store[1] - store[0]);if (dfi > 1) {cout<<0<<endl;continue;}ll ans = 0;if (dfi == 0) {// same and not 0int x3,x4;x3 = store[1];x4 = x3 + 1;ans += (cnk(store[2]+x3-1, store[2]) * cnk(store[3]+x4-1, store[3])) % mod;x4 = store[1];x3 = x4 + 1;ans = ans + (cnk(store[2]+x3-1, store[2]) * cnk(store[3]+x4-1, store[3])) % mod;ans = ans % mod;} else {// greater than oneint x3,x4;x3 = x4 = max(store[0], store[1]);ans = (cnk(store[2]+x3-1, store[2]) * cnk(store[3]+x4-1, store[3])) % mod;}cout<<ans<<endl;}return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/818955.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

BEVFormer代码阅读

1. 代码地址 https://github.com/fundamentalvision/BEVFormer 2. 代码结构 个人理解&#xff0c;代码库中的代码与两篇论文都略有不同&#xff0c;总结起来&#xff0c;其结构如下。 3. BEVFormer 的 Pipeline 根据自己调试算法模型以及对论文的理解&#xff0c;我这里将 …

牛客网刷题 :BC50 你是天才吗

描述 据说智商140以上者称为天才&#xff0c;KiKi想知道他自己是不是天才&#xff0c;请帮他编程判断。输入一个整数表示一个人的智商&#xff0c;如果大于等于140&#xff0c;则表明他是一个天才&#xff0c;输出“Genius”。 输入描述&#xff1a; 多组输入&#xff0c;每…

(十)C++自制植物大战僵尸游戏设置功能实现

植物大战僵尸游戏开发教程专栏地址http://t.csdnimg.cn/m0EtD 游戏设置 游戏设置功能是一个允许玩家根据个人喜好和设备性能来调整游戏各项参数的重要工具。游戏设置功能是为了让玩家能够根据自己的需求和设备性能来调整游戏&#xff0c;以获得最佳的游戏体验。不同的游戏和平…

音视频、网络带宽等常用概念详解

1.aac音频参数解释 AAC帧大小为1024个sample&#xff1a;指AAC编码一般以1024个采样为一个音频帧。 采样率48khz&#xff1a;指1秒&#xff08;即1000毫秒&#xff09;采集48000次。 计算1秒有多少帧&#xff1a;48000 / 1024 46.875 a&#xff08;用a表示计算结果&#xff0…

vite - WebAssembly入门

1. 初始化 vite 项目 1.1 安装 nvm&#xff08;可选&#xff09; brew update brew install nvm在 ~/.zshrc 添加 export NVM_DIR~/.nvm source $(brew --prefix nvm)/nvm.sh执行如下命令 source ~/.zshrc1.2 安装 node nvm install nodenvm ls -> …

PyTorch Scheduler动态调整学习率

文章目录 PyTorch动态调整学习率1.使用官方scheduler2.自定义scheduler参考 PyTorch动态调整学习率 深度学习中长久以来一直存在一个令人困扰的问题&#xff0c;那就是如何选择适当的学习率。如果学习速率设置得过小&#xff0c;会导致模型收敛速度缓慢&#xff0c;训练时间延…

vscode 打代码光标特效

vscode 打代码光标特效 在设置里面找到settings 进入之后在代码最下方加入此代码 "explorer.confirmDelete": false,"powermode.enabled": true, //启动"powermode.presets": "fireworks", // 火花效果// particles、 simple-rift、e…

Day13-C++基础之文件操作

文件操作 #include<iostream> #include<fstream> #include<string> using namespace std; ​ class Person{ public:char m_Name[64];int m_Age; }; ​ int main(){//文本文件操作 ​//写文件//1.包含头文件 fstream//2.创建流对象ofstream ofs;//3.指定打开…

如何利用OceanBase v4.2的 外部表简化外部数据处理

为什么需要使用外表 在日常的业务场景中&#xff0c;经常遇到需要在数据库中处理外部数据的情况&#xff0c;这些数据可能来源于应用程序&#xff0c;或者是其他业务系统。一般来说&#xff0c;常是通过ETL工具将外部数据库的数据导入到数据库内部的表中&#xff0c;再进行分析…

EasyRecovery数据恢复软件好不好用?值不值得下载

EasyRecovery数据恢复软件是一款专业且功能强大的数据恢复工具&#xff0c;它旨在帮助用户从各种存储设备中恢复由于各种原因&#xff08;如误删除、格式化、病毒攻击、系统崩溃等&#xff09;导致丢失的数据。这款软件支持多种存储介质&#xff0c;包括但不限于硬盘驱动器、U盘…

分布式监控平台---Zabbix

一、Zabbix概述 作为一个运维&#xff0c;需要会使用监控系统查看服务器状态以及网站流量指标&#xff0c;利用监控系统的数据去了解上线发布的结果&#xff0c;和网站的健康状态。 利用一个优秀的监控软件&#xff0c;我们可以&#xff1a; 通过一个友好的界面进行浏览整个…

go结构体嵌套递归调用的2种方式--struct和func

1: 需要嵌套部分是结构体类型的&#xff0c;例如&#xff1a;快照 套 子快照&#xff0c;但是子快照长得和快照一样&#xff08;同一份结构体&#xff09;&#xff0c;可以无限递归套娃&#x1fa86; // ResRootSnapshot ... type ResRootSnapshot struct {// 快照标识Urn str…

Java实现单点登录(SSO)详解:从理论到实践

✨✨谢谢大家捧场&#xff0c;祝屏幕前的小伙伴们每天都有好运相伴左右&#xff0c;一定要天天开心哦&#xff01;✨✨ &#x1f388;&#x1f388;作者主页&#xff1a; 喔的嘛呀&#x1f388;&#x1f388; ✨✨ 帅哥美女们&#xff0c;我们共同加油&#xff01;一起进步&am…

【Maven工具】

maven Maven是一个主要用于Java项目的构建自动化工具。它有助于管理构建过程&#xff0c;包括编译源代码、运行测试、将编译后的代码打包成JAR文件以及管理依赖项。Maven使用项目对象模型&#xff08;POM&#xff09;文件来描述项目配置和依赖关系。 Maven通过提供标准的项目…

(三)C++自制植物大战僵尸游戏项目结构说明

植物大战僵尸游戏开发教程专栏地址http://t.csdnimg.cn/ErelL 一、项目结构 打开项目后&#xff0c;在解决方案管理器中有五个项目&#xff0c;分别是libbox2d、libcocos2d、librecast、libSpine、PlantsVsZombies五个项目&#xff0c;除PlantsVsZombies外&#xff0c;其他四个…

第十五届蓝桥杯研究生组Java软件开发组总结

2024年十五届蓝桥杯研究生组 今年的题较去年难度降低了很多&#xff0c;题量也少了2道。 Q1 劲舞团 读文件&#xff0c;找到最长的满足条件的子数组的长度 答案是&#xff1a;9 BufferedReader&#xff0c;fopen&#xff0c;open Q2 召唤数学精灵 找规律&#xff0c;周期…

SELinux详解

SELinux是一种安全增强的Linux操作系统的安全子系统。它是由美国国家安全局&#xff08;NSA&#xff09;与Red Hat公司合作开发的&#xff0c;旨在提供高级的访问控制和强制访问控制&#xff08;MAC&#xff09;机制。 SELinux的目标是通过在操作系统内核中实施强大的访问控制…

【算法】快速排序的基本思想、优化 | 挖坑填补法和区间分割法

创作不易&#xff0c;本篇文章如果帮助到了你&#xff0c;还请点赞 关注支持一下♡>&#x16966;<)!! 主页专栏有更多知识&#xff0c;如有疑问欢迎大家指正讨论&#xff0c;共同进步&#xff01; 更多算法分析与设计知识专栏&#xff1a;算法分析&#x1f525; 给大家跳…

基于springboot+vue实现的疫情防控物资调配与管理系统

作者主页&#xff1a;Java码库 主营内容&#xff1a;SpringBoot、Vue、SSM、HLMT、Jsp、PHP、Nodejs、Python、爬虫、数据可视化、小程序、安卓app等设计与开发。 收藏点赞不迷路 关注作者有好处 文末获取源码 技术选型 【后端】&#xff1a;Java 【框架】&#xff1a;spring…

家居网购项目(权限验证+事务管理)

文章目录 1.过滤器权限认证1.程序框架图2.web.xml3.编写AdminAuthorization4.编写MemberAuthorization5.细节6.结果展示1.未登录可以任意浏览商品2.点击添加购物车提示登录3.点击后台管理&#xff0c;提示管理员登录4.也做了其余资源的访问验证 2.事务管理1.思路分析2.重写JDBC…