Codeforces Round 1011 (Div. 2)(A~D,补了E)

news/2025/3/23 3:17:50/文章来源:https://www.cnblogs.com/cjcf/p/18787422

比赛链接:https://codeforces.com/contest/2085

A.Serval and String Theory

思路:我看了快4分钟才明白题意,显然字符串的字符全相等或者k==0时,字符串不符合题意即无解,否则就是对的

#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<functional>
#include<stack>
#include<unordered_map>
#include<string>
#define ll                            long long 
#define lowbit(x) (x & -x)
#define endl "\n"//                           交互题记得删除
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
mt19937 rnd(time(0));
const ll mod = 998244353;
//const ll p=rnd()%mod;
#define F first
#define S second
// tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;find_by_order(k),找第k位(从小到大)的数字,order_of_key(x),x的排名
ll ksm(ll x, ll y)
{ll ans = 1;x %= mod;while (y){if (y & 1){ans = ans * x % mod;}x = x * x % mod;y >>= 1;}return ans;
}
ll gcd(ll x, ll y)
{if (y == 0)return x;elsereturn gcd(y, x % y);
}
inline ll read()
{register ll x = 0, f = 1;char c = getchar();while (c < '0' || c>'9'){if (c == '-') f = -1;c = getchar();}while (c >= '0' && c <= '9'){x = (x << 3) + (x << 1) + (c ^ 48); //等价于x*10+c-48,使用位运算加速c = getchar();}return x * f;
}
void fio()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}
struct s
{ll l,r;friend bool operator<(const s &a, const s& b){return a.l<b.l;};
};
int main()
{fio();ll t;cin >> t;while (t--){ll n,k;cin>>n>>k;string f;cin>>f;ll cnt=0;for(ll i=0;i<n;i++){cnt+=(f[i]==f[0]);}ll pd=0;for(ll i=0;i<n;i++){if(f[i]<f[n-i-1]){pd=1;break;}else if(f[i]>f[n-i-1]){pd=2;break;}}if(cnt==n||(k==0&&(pd==2||pd==0))){cout<<"NO"<<endl;}else cout<<"YES"<<endl;}return 0;
}

B.Serval and Final MEX

思路:全0就分成一半一半,然后统一合并。全为大于0的数字就直接全合成就好了。有0和有大于0的数字,我是这样想的。
如果最后两位有至少一个0出现,那么他们两个合并下,然后去遍历前面的数(n-2个数)看下前面的数否全为大于0的数,如果前面全大于0则不合成,最后大合成就好
否则,最后两个数不合成,前面n-2 个数合成下,最后再大合成即可

#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<functional>
#include<stack>
#include<unordered_map>
#include<string>
#define ll                            long long 
#define lowbit(x) (x & -x)
#define endl "\n"//                           交互题记得删除
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
mt19937 rnd(time(0));
const ll mod = 998244353;
//const ll p=rnd()%mod;
#define F first
#define S second
// tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;find_by_order(k),找第k位(从小到大)的数字,order_of_key(x),x的排名
ll ksm(ll x, ll y)
{ll ans = 1;x %= mod;while (y){if (y & 1){ans = ans * x % mod;}x = x * x % mod;y >>= 1;}return ans;
}
ll gcd(ll x, ll y)
{if (y == 0)return x;elsereturn gcd(y, x % y);
}
inline ll read()
{register ll x = 0, f = 1;char c = getchar();while (c < '0' || c>'9'){if (c == '-') f = -1;c = getchar();}while (c >= '0' && c <= '9'){x = (x << 3) + (x << 1) + (c ^ 48); //等价于x*10+c-48,使用位运算加速c = getchar();}return x * f;
}
void fio()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}
struct s
{ll l,r;friend bool operator<(const s &a, const s& b){return a.l<b.l;};
};
int main()
{fio();ll t;cin >> t;while (t--){ll n;cin>>n;vector<ll>a(n+5);ll cnt=0;ll wz;for(ll i=1;i<=n;i++){cin>>a[i];cnt+=(a[i]==0);}if(cnt==0){cout<<1<<endl;cout<<1<<" "<<n<<endl;}else if(cnt!=n){if(a[n-1]==0||a[n]==0){ll pd=0;ll f=0;for(ll i=1;i<=n-2;i++){if(a[i]>0)f++;}if(f!=n-2){cout<<3<<endl;cout<<n-1<<" "<<n<<endl;cout<<1<<" "<<n-2<<endl;cout<<1<<" "<<2<<endl;}else {cout<<2<<endl;cout<<n-1<<" "<<n<<endl;cout<<1<<" "<<n-1<<endl;}}else{cout<<2<<endl;cout<<1<<" "<<n-2<<endl;cout<<1<<" "<<3<<endl;}}else {cout<<3<<endl;cout<<n-1<<" "<<n<<endl;cout<<1<<" "<<n-2<<endl;cout<<1<<" "<<2<<endl;}}return 0;
}

C.Serval and The Formula

思路:其实仔细写写发现就是去尽量消除x和y在某个二进制位同为1的情况,发现能消除的方法就是找更低的二进制位为(0和1)的情况,然后不断进位即可。写的时间复杂度就60*60吧,其实还有O(1)办法,应该是这个吧,(1ll<<30)-max(x,y).

#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<functional>
#include<stack>
#include<unordered_map>
#include<string>
#define ll                            long long 
#define lowbit(x) (x & -x)
#define endl "\n"//                           交互题记得删除
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
mt19937 rnd(time(0));
const ll mod = 998244353;
//const ll p=rnd()%mod;
#define F first
#define S second
// tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;find_by_order(k),找第k位(从小到大)的数字,order_of_key(x),x的排名
ll ksm(ll x, ll y)
{ll ans = 1;x %= mod;while (y){if (y & 1){ans = ans * x % mod;}x = x * x % mod;y >>= 1;}return ans;
}
ll gcd(ll x, ll y)
{if (y == 0)return x;elsereturn gcd(y, x % y);
}
inline ll read()
{register ll x = 0, f = 1;char c = getchar();while (c < '0' || c>'9'){if (c == '-') f = -1;c = getchar();}while (c >= '0' && c <= '9'){x = (x << 3) + (x << 1) + (c ^ 48); //等价于x*10+c-48,使用位运算加速c = getchar();}return x * f;
}
void fio()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}
struct s
{ll l,r;friend bool operator<(const s &a, const s& b){return a.l<b.l;};
};
int main()
{fio();ll t;cin >> t;while (t--){ll x,y;cin>>x>>y;//cout<<ll k=0;ll ok=0;for(ll i=0;i<=60;i++){ll z=(1ll<<i);if((x&z)&&(y&z)){while((x&z)&&(y&z)){   ll pd=0;for(ll j=i-1;j>=0;j--){ll o=1ll<<j;if(((x&o)==0&&(y&o)>0)||((y&o)==0&&(x&o)>0)){pd=1;x+=o;y+=o;k+=o;break;}}if(pd==0)break;}if(((x&z)&&(y&z))&&i>=55){ok=1;break;}else if((x&z)&&(y&z)){x+=z;y+=z;k+=z;}}}if(ok||k>1e18)cout<<-1<<endl;else cout<<k<<endl;}return 0;
}
//100100100100100100100
// 10010010010010010100

D.Serval and Kaitenzushi Buffet

思路:反悔贪心,每次看吃的时间够不够,够得话就拿走吃的,否则就看要不要最小的换下即可

#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<functional>
#include<stack>
#include<unordered_map>
#include<string>
#define ll                            long long 
#define lowbit(x) (x & -x)
#define endl "\n"//                           交互题记得删除
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
mt19937 rnd(time(0));
const ll mod = 998244353;
//const ll p=rnd()%mod;
#define F first
#define S second
// tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;find_by_order(k),找第k位(从小到大)的数字,order_of_key(x),x的排名
ll ksm(ll x, ll y)
{ll ans = 1;x %= mod;while (y){if (y & 1){ans = ans * x % mod;}x = x * x % mod;y >>= 1;}return ans;
}
ll gcd(ll x, ll y)
{if (y == 0)return x;elsereturn gcd(y, x % y);
}
inline ll read()
{register ll x = 0, f = 1;char c = getchar();while (c < '0' || c>'9'){if (c == '-') f = -1;c = getchar();}while (c >= '0' && c <= '9'){x = (x << 3) + (x << 1) + (c ^ 48); //等价于x*10+c-48,使用位运算加速c = getchar();}return x * f;
}
void fio()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}
struct s
{ll v, id;friend bool operator<(const s& a, const s& b){return a.v > b.v;};
};
int main()
{fio();ll t;cin >> t;while (t--){ll n, k;cin >> n >> k;vector<ll>a(n + 5);for (ll i = 1; i <= n; i++){cin >> a[i];}ll cnt = k;priority_queue<s>f;ll ans = 0;ll sum = 0;for (ll i = n - k; i >= 1; i--){if (cnt >= k){f.push({ a[i],i });sum += a[i];cnt -= k;}else{ll v = f.top().v;if (v >= a[i]){cnt++;continue;}else{sum -= v;f.pop();f.push({ a[i],i });cnt++;sum += a[i];}}ans = max(ans, sum);}cout << ans << endl;}return 0;
}
//100100100100100100100
// 10010010010010010100

E.Serval and Modulo

思路:赛后补的。看了jangly的代码。对于正确的{a[i],b[i]}对,其实(a[i]-b[i])一定是k的倍数,除了a数组等于b数组情况。
所以我们可以把所有(a[i]-b[i])加起来即可,然后分解因数去检测下就可以做出来,实际因数不多,其实不等于nsqrt(n)logn,时间复杂度远比这个小,因为因数其实很少,不是因数的时间复杂度上算加法

#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<deque>
#include<cctype>
#include<string.h>
#include<math.h>
#include<time.h>
#include<random>
#include<functional>
#include<stack>
#include<unordered_map>
#include<string>
#define ll                            long long 
#define lowbit(x) (x & -x)
#define endl "\n"//                           交互题记得删除
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
mt19937 rnd(time(0));
const ll mod = 998244353;
//const ll p=rnd()%mod;
#define F first
#define S second
// tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;find_by_order(k),找第k位(从小到大)的数字,order_of_key(x),x的排名
ll ksm(ll x, ll y)
{ll ans = 1;x %= mod;while (y){if (y & 1){ans = ans * x % mod;}x = x * x % mod;y >>= 1;}return ans;
}
ll gcd(ll x, ll y)
{if (y == 0)return x;elsereturn gcd(y, x % y);
}
inline ll read()
{register ll x = 0, f = 1;char c = getchar();while (c < '0' || c>'9'){if (c == '-') f = -1;c = getchar();}while (c >= '0' && c <= '9'){x = (x << 3) + (x << 1) + (c ^ 48); //等价于x*10+c-48,使用位运算加速c = getchar();}return x * f;
}
void fio()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}
struct s
{ll v, id;friend bool operator<(const s& a, const s& b){return a.v > b.v;};
};
int main()
{fio();ll t;cin >> t;while (t--){ll n;cin>>n;//如果有答案,那么差值一定包含这个答案的倍数vector<ll>a(n+5,0),b(n+5,0);for(ll i=1;i<=n;i++)cin>>a[i];for(ll i=1;i<=n;i++)cin>>b[i];sort(a.begin()+1,a.begin()+1+n);sort(b.begin()+1,b.begin()+1+n);ll f=0;for(ll i=1;i<=n;i++){f+=a[i]-b[i];}if(a==b){cout<<(ll)1e9<<endl;continue;}if(f<=0){cout<<-1<<endl;continue;}function<ll(ll)>ck=[&](ll x){if(x>(ll)1e9)return 0;vector<ll>f(n+5,0);f=a;for(ll i=1;i<=n;i++){f[i]%=x;}sort(f.begin()+1,f.begin()+1+n);if(f==b)return 1;else return 0;};ll ans=-1;for(ll i=1;i*i<=f;i++){if(f%i==0){if(ck(i)){ans=i;break;}if(ck(f/i)){ans=f/i;break;}}}cout<<ans<<endl;}
}
//100100100100100100100
// 10010010010010010100

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

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

相关文章

2025年3月月记

2025.3.1 新的一月到来啦!今天干了个啥呢?好像没干啥也是把昨天编程学习的作业做了,待会又要去学S组的知识了,我先去刷题了。。。 OK啊,也是把课学完了,待会我又要去打atcoder了,今天学的是差分约束,其实就是图上的知识,主要的表达形式是:u <= v + w或者u >= v…

Linux版本的MAT(Eclipse Memory Analyzer)内存分析工具使用

首先先下载对应平台的工具 官方地址:https://eclipse.dev/mat/download/ 因为我是arm的架构 所以下载的是arm64的安装包 下载完成后解压 得到以下内容 先修改初始化的启动的内存大小 vim MemoryAnalyzer.ini 主要修改这个值 这个要尽量大点 不然我们的内存分析文件很大 会执行…

【CodeForces训练记录】Codeforces Round 1011 (Div. 2)

训练情况赛后反思 B题因为分讨的问题WA了一发,异或还是不大会做 A题 猜猜题,显然对于字符串全部都是一个字母的,无论怎么换字典序都不可能更小,对于其他情况因为可以选择两个字母互换,我们容易观察到对于某一个字符串一定存在一种换法能让字典序更小(无非就是换头或者换尾…

集美大学课程实验报告-实验3:栈、队列与递归

集美大学课程实验报告-实验3:栈、队列与递归项目名称 内容课程名称 数据结构班级 网安2413指导教师 郑如滨学生姓名 林沁茹学号 202421336067实验项目名称 实验3:栈、队列与递归上机实践日期上机实践时间 2学时一、目的(本次实验所涉及并要求掌握的知识点) 以下内容请根据实…

2025-03-22 闲话

2025-03-22 闲话有些闲话是纪实的,它们可能只是平淡的文字。它们可能没有感受,不带思考。你看不到装饰,只有琐碎、补也补不到自圆其说的细节。柴米油盐大抵是这样的。 来北京独居后的生活着实安逸。每天执行一个蛮正常的作息,保证三顿饮食、偶尔晚上和网友去搓搓夜宵。睡觉…

3.22 三重积分计算方法

三重积分的实际意义:计算一个立体的质量(可以) 1 投影法(先一后二)(一个土豆切成土豆丝,最后再累加Dxy平面) 一个立体图形可以看成是两个曲面拼接而成,z=(x,y)可表示一个曲面假设x和y都是确定的,然后就累加z,最后再算面积分 先假设有一条竖线,注意竖线是从哪里进入…

15.数组

数组C 语言支持数组数据结构,它可以存储一个固定大小的相同类型元素的顺序集合。 数组是用来存储一系列数据,但它往往被认为是一系列相同类型的变量。数组中的特定元素可以通过索引访问,第一个索引值为 0。声明数组在 C 中要声明一个数组,需要指定元素的类型和元素的数量 下…

逆向中简单的shellcode

做题时遇到了,简单记录一下 一,介绍: shellcode分为广义和狭义,狭义指的仅仅是通过命令行shell攻击靶机,并取得控制权的代码,广义的指能完成类似任务的代码,通常是汇编/机器码。 不过这里是RE,不是PWN,所以不会有靶机,那么在下文指的是广义的shellcode,注入程序,控…

linux一些好用命令:w,fuer,getfacl,usermod,chmod

一.命令 w w 是显示用户登录时间、空闲时间、当前执行的命令等。 2.示例 pst/* : 这是ssh登录 tty: 这是直接本地登录(ctrl+alt +F* 都可以) 这个是没本地登录显示的进程 二. 命令 fuser fuser 是一个可以查看使用此文件的进程号。 1.一般使用 fuser -a /path/to/filename…

Aligning the Objective of LLM-based Program Repair 论文笔记

介绍 (1) 发表 2025-02 ICSE24 (2) 挑战当前方法的推理目标与 LLM 的训练目标没有对齐。现有 LLM-based 方法通常采用 MLM 的方式预测修复代码(然而尽管模型参数被增大百倍但修复结果甚至没有翻一番,这与其他任务的明确可伸缩性形成对比)。因此本文假设在训练中 <masked,…

监狱智能视频分析告警系统解决方案

监狱智能视频分析告警系统解决方案能够精准监测到静坐不动、离床、攀高、独处等行为。例如,当一名囚犯长时间静坐不动时,监狱智能视频分析告警系统解决方案会自动识别并发出预警,以便管理人员及时了解情况,防止囚犯出现自伤、自残等危险行为。在洗手间场景中,系统对入厕超…

昆明理工大学最新《现代材料测试技术》复试真题及答案

-材料测试 昆工材料物理与化学、材料学、材料表征与分析、材料工程、F001现代材料测试技术、864材料科学基础、昆明理工大学材料调剂