1.Educational Codeforces Round 1662.Educational Codeforces Round 171 (Rated for Div
3.Educational Codeforces Round 169 (Rated for Div2)
4.Educational Codeforces Round 80 (Rated for Div2)5.Educational Codeforces Round 172 (Rated for Div2)6.Educational Codeforces Round 157 (Rated for Div2)7.Educational Codeforces Round 173 (Rated for Div2)8.Educational Codeforces Round 165Educational Codeforces Round 169 (Rated for Div. 2) - Codeforces
Problem - A - Codeforces
构造
签到题,明显只有\(n\leq2\)的时候有解
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef pair<int,int> pii;
int n,m;
int a[N];
void solve()
{
cin>>n;
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
if(n==2)
{
if(abs(a[1]-a[2])>1)
{
puts("YES");return ;
}
}
puts("NO");
}
int main()
{
int t;cin>>t;
while(t--)solve();
}
Problem - B - Codeforces
区间合并 构造
如果两者的区间没有交集的话答案就是\(1\),否则就是合并区间内的所有门加上区间合并后的两端的门,要注意如果合并前两端相同的话这这一端的门就不用加了
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef pair<int,int> pii;
int n,m;
int a[N];
void solve()
{
int l,r,L,R;cin>>l>>r>>L>>R;
if(l>L)
{
swap(l,L);swap(r,R);
}
if(r<L)cout<<"1"<<endl;
else
{
int st=L,ed=min(r,R);
int ans=ed-st+2;
if(l==L)ans--;
if(r==R)ans--;
cout<<ans<<endl;
}
}
int main()
{
int t;cin>>t;
while(t--)solve();
}
Problem - C - Codeforces
数学 构造 排序
A要最大化拿到的价值,B同理,A先手,显然\(0\leq A-B\)
将数组排序,显然A每次要拿当前的最大值,B也要拿下一个最大值,这样差值才会最小
如果\(n\)为偶数的话,B只要每次增加奇数位置上的数且使其不大于偶数位置上的数字
如果\(n\)为奇数的话,同理,可以先不看第一个数字,因为B不可能去增加他,只需把后面处理完之后将答案加上第一个数就好了
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef pair<int,int> pii;
int n,m;
int a[N];
void solve()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
sort(a+1,a+1+n);
long long ans=0;
for(int i=n;i>1;i-=2)
{
ans=ans+a[i]-a[i-1];
}
ans=max(0LL,ans-m);
if(n%2)ans+=a[1];
cout<<ans<<endl;
}
int main()
{
int t;cin>>t;
while(t--)solve();
}
Problem - D - Codeforces
图论 最短路 构造 找规律
每个城市有两种颜色,一共有四种颜色,显然会有四种组合,只有两个城市间有至少一种相同颜色才可以传送
对于两个查询的城市,如果他们之间有相同的颜色,那么他们之间的最短路径只可能是\(|i-j|\)
否则,则需要一个中转点,且只能有一个,因为对于两个没有相同的颜色的城市来说,其余四种颜色组合都可以到达他们,
两个中转点只会增加路径长度
那么这题的关键在于如果两个城市不可以直接相通的话该如何快速找到离他们最近的中转点
这里用\(pre,suf\)数组分别记录每个位置的城市,离他最近的,在他之前或者在他之后的可以到达的城市
只需要利用一个\(now\)数组存储在其之前的状态
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef pair<int,int> pii;
int a[N];
int pre[7][N],suf[7][N];
int n,q;
map<string,int>mp;
map<int,int>sp;
void solve()
{
scanf("%d%d",&n,&q);
vector<int>now(7,0),nw(7,0);
for(int i=1;i<=n;i++){string s;cin>>s;a[i]=mp[s];}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=6;j++)
{
if(j!=sp[a[i]])
{
if(now[j])pre[j][i]=now[j];
else pre[j][i]=-1;
}
}
now[a[i]]=i;
}
for(int i=n;i>=1;i--)
{
for(int j=1;j<=6;j++)
{
if(j!=sp[a[i]])
{
if(nw[j])suf[j][i]=nw[j];
else suf[j][i]=-1;
}
}
nw[a[i]]=i;
}
while(q--)
{
int x,y;scanf("%d%d",&x,&y);
if(x>y)swap(x,y);
if(sp[a[x]]!=a[y])
{
cout<<abs(x-y)<<endl;continue;
}
int ans=2e9;
int l=-1,r=2e9;
for(int i=1;i<=6;i++)
{
if(i!=a[x]&&i!=a[y])
{
if(pre[i][x]!=-1)l=max(l,pre[i][x]);
if(suf[i][x]!=-1)r=min(r,suf[i][x]);
}
}
if(l!=-1)ans=min(ans,abs(x-l)+abs(y-l));
if(r<2e9)ans=min(ans,abs(r-x)+abs(r-y));
l=-1,r=2e9;
for(int i=1;i<=6;i++)
{
if(i!=a[x]&&i!=a[y])
{
if(pre[i][x]!=-1)l=max(l,pre[i][x]);
if(suf[i][x]!=-1)r=min(r,suf[i][x]);
}
}
if(l!=-1)ans=min(ans,abs(x-l)+abs(y-l));
if(r<2e9)ans=min(ans,abs(r-x)+abs(r-y));
if(ans<1e9)cout<<ans<<endl;else cout<<"-1"<<endl;
}
}
int main()
{
mp["BG"]=1;mp["BR"]=2;mp["BY"]=3;mp["GR"]=4;mp["GY"]=5;mp["RY"]=6;
sp[1]=6;sp[6]=1;//无法到达的点
sp[2]=5;sp[5]=2;
sp[3]=4;sp[4]=3;
int t;cin>>t;
while(t--)solve();
}
合集:
codeforces edu
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧