【Codeforces】补题合集

1|0Educational Codeforces Round 143 (Rated for Div. 2)

1|1A. Two Towers

拼接序列。枚举相邻相同字母。如果 >1 则无解。否则可以做一个断点,有解。

点击查看代码
// Problem: A. Two Towers // Contest: Codeforces - Educational Codeforces Round 143 (Rated for Div. 2) // URL: https://codeforces.com/contest/1795/problem/A // Memory Limit: 256 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include <bits/stdc++.h> using namespace std; #define Multicase() for(int T = read() ; T ; T--) #define lowbit(x) (x & (-x)) #define ls(p) (p<<1) #define rs(p) (p<<1|1) #define l(p) tree[p].ls #define r(p) tree[p].rs #define sum(p) tree[p].sum #define tag(p) tree[p].tag #define F(i,a,b) for(int i=(a) ;i<=(b);++i) #define F2(i,a,b) for(int i=(a);i< (b);++i) #define dF(i,a,b) for(int i=(a);i>=(b);--i) #define debug(...) fprintf(stderr,__VA_ARGS__) #define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__) #define clr(a,x) memset(a,x,sizeof(a)) #define pb push_back #define mkp make_pair #define fi first #define se second #define endl '\n' #define ENDL putchar('\n') #define forGraph(u) for(int i=head[u];i;i=G[i].next) const int N=5e5+5; const int M=1e6+5; const int MN=1e3+5; const int iinf=INT_MAX; const double eps=1e-9; const double pi=acos(-1); const long long linf=LLONG_MAX; const long long mod=1000000007,mod2=998244353; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef map<int,int> mii; typedef map<ll,ll> mll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef map<string,int> msi; inline int read(){int x(0), f(0); char ch=getchar(); while(ch<'0'||ch>'9'){f|=ch=='-';ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48); ch=getchar();} return f?-x:x;} template <typename T> void read(T &x){x=0; T f(0); char ch=getchar(); while(ch<'0'||ch>'9'){f|=ch=='-';ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48); ch=getchar();} x=f?-x:x;} template <typename T,typename ...Arg>void read(T& x,Arg& ...arg){read(x);read(arg...);} template <typename T> inline void write(T x){static char buf[64]; static int tot(0); if(x<0) putchar('-'),x=-x; do buf[++tot]=(x%10)+48,x/=10; while(x); do putchar(buf[tot--]); while(tot);} template <typename T> void write(T x,char c){static char buf[64]; static int tot(0); if(x<0) putchar('-'),x=-x; do buf[++tot]=(x%10)+48,x/=10; while(x); do putchar(buf[tot--]); while(tot); putchar(c);} void judge(bool x){printf(x?"YES\n":"NO\n");} void Solve(); struct Graph{ int to,w,next; }G[M<<1]; int head[N],cnt; void addEdge(int u,int v,int w=1){G[++cnt]=(Graph){v,w,head[u]}; head[u]=cnt;} template<class T,class U> void chkmax(T &x, U y) { if(x < y) x = y; } template<class T,class U> void chkmin(T &x, U y) { if(x > y) x = y; } int n,m,q,k,p; int a[N],b[N],f[N]; vector<int> v; int main(){ Multicase() Solve(); } string s,t; void Solve(){ p=0; read(n,m); cin>>s>>t; reverse(t.begin(),t.end()); s+=t; F(i,1,n+m-1) if(s[i]==s[i-1]) p++; if(p<=1) judge(1); else judge(0); }

1|2B. Ideal Point

典中典之线段交集。先把不包含 k 的全去了,然后扫一遍,看看被每个线段都覆盖的点是否只有 k 一个即可。

点击查看代码
// Problem: B. Ideal Point // Contest: Codeforces - Educational Codeforces Round 143 (Rated for Div. 2) // URL: https://codeforces.com/contest/1795/problem/B // Memory Limit: 256 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include <bits/stdc++.h> using namespace std; #define Multicase() for(int T = read() ; T ; T--) #define lowbit(x) (x & (-x)) #define ls(p) (p<<1) #define rs(p) (p<<1|1) #define l(p) tree[p].ls #define r(p) tree[p].rs #define sum(p) tree[p].sum #define tag(p) tree[p].tag #define F(i,a,b) for(int i=(a) ;i<=(b);++i) #define F2(i,a,b) for(int i=(a);i< (b);++i) #define dF(i,a,b) for(int i=(a);i>=(b);--i) #define debug(...) fprintf(stderr,__VA_ARGS__) #define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__) #define clr(a,x) memset(a,x,sizeof(a)) #define pb push_back #define mkp make_pair #define fi first #define se second #define endl '\n' #define ENDL putchar('\n') #define forGraph(u) for(int i=head[u];i;i=G[i].next) const int N=5e5+5; const int M=1e6+5; const int MN=1e3+5; const int iinf=INT_MAX; const double eps=1e-9; const double pi=acos(-1); const long long linf=LLONG_MAX; const long long mod=1000000007,mod2=998244353; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef map<int,int> mii; typedef map<ll,ll> mll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef map<string,int> msi; inline int read(){int x(0), f(0); char ch=getchar(); while(ch<'0'||ch>'9'){f|=ch=='-';ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48); ch=getchar();} return f?-x:x;} template <typename T> void read(T &x){x=0; T f(0); char ch=getchar(); while(ch<'0'||ch>'9'){f|=ch=='-';ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48); ch=getchar();} x=f?-x:x;} template <typename T,typename ...Arg>void read(T& x,Arg& ...arg){read(x);read(arg...);} template <typename T> inline void write(T x){static char buf[64]; static int tot(0); if(x<0) putchar('-'),x=-x; do buf[++tot]=(x%10)+48,x/=10; while(x); do putchar(buf[tot--]); while(tot);} template <typename T> void write(T x,char c){static char buf[64]; static int tot(0); if(x<0) putchar('-'),x=-x; do buf[++tot]=(x%10)+48,x/=10; while(x); do putchar(buf[tot--]); while(tot); putchar(c);} void judge(bool x){printf(x?"YES\n":"NO\n");} void Solve(); struct Graph{ int to,w,next; }G[M<<1]; int head[N],cnt; void addEdge(int u,int v,int w=1){G[++cnt]=(Graph){v,w,head[u]}; head[u]=cnt;} template<class T,class U> void chkmax(T &x, U y) { if(x < y) x = y; } template<class T,class U> void chkmin(T &x, U y) { if(x > y) x = y; } int n,m,q,k,p; int a[N],b[N],f[N]; vector<pii> seg; int main(){ Multicase() Solve(); } void Solve(){ vector<pii> ().swap(seg); read(n,k); F(i,1,n){ int l,r; read(l,r); if(l>k || r<k) continue; else seg.pb(mkp(l,r)); } int L=-iinf,R=iinf; for(auto it:seg){ L=max(L,it.fi); R=min(R,it.se); } if(L==k && R==k) judge(1); else judge(0); }

__EOF__

本文作者TheSky233
本文链接https://www.cnblogs.com/TheSky233/p/17133537.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   TheSky233  阅读(46)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示