Codeforces Round 909 (Div3)(本菜鸟只补到了E)
Codeforces Round 909 (Div.3)
A. Game with Integers
水题,就是可以被3整除的输出“Second”,不能被3整除的输出“First”
#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--){
int n;
cin>>n;
if(n%3) cout<<"First"<<endl;
else cout<<"Second"<<endl;
}
return 0;
}
B.250 Thousand Tons of TNT
k是n的因子就可以用for(int i=1;i<=n/i;i++)
来找到因子,从而来分组
注:INF不要开的太小
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAX=150000;
const LL INF= 100000000000000;
int a[MAX];
int main()
{
int n;
cin>>n;
while(n--){
LL res=0;
int t;
cin>>t;
if(t==0){
cout<<"0"<<endl;
continue;
}
for(int i=0;i<t;i++){
cin>>a[i];
}
for(int i=1;i<t;i++){//i为几个数一组
if(t%i==0){
LL ma=0,mi=INF,sum=0;
int x=t/i;//x为有几个组
for(int j=0;j<x;j++){
sum=0;
for(int k=0;k<i;k++){
sum+=a[j*i+k];
}
ma=max(ma,sum);
mi=min(mi,sum);
}
res=max(res,ma-mi);
}
}
cout<<res<<"\n";
}
}
C. Yarik and Array
如果前面的和<0就没有必要加前面的数,直接后面相加即可
#include <bits/stdc++.h>
using namespace std;
const int MAX=2e5+10;
int a[MAX];
int main()
{
int t;
cin>>t;
while(t--){
int n;
cin>>n;
memset(a,0,sizeof(a));
for(int i=1;i<=n;i++){
cin>>a[i];
}
int res=a[1],sum=a[1];
for(int i=2;i<=n;i++){
sum=max(sum,0);
if(abs(a[i]+a[i-1])%2==0) sum=0;
sum+=a[i];
res=max(sum,res);
}
cout<<res<<"\n";
}
}
D. Yarik and Musical Notes
$$
要求2 ^{a_i ^ {2 ^ {a_j}}} == 2 ^{a_j ^ {2 ^ {a_i}}} 令b_i=2{a_i}则只需要满足b_ib_j^{b_i} 对该公式进行变形就可以得到b_j*a_ia_j*b_i
$$
$$
即可得a^{j-i}==a_j/a_i有两种情况满足上式,即当a_i=a_j时满足或者a_j=2;a_i=1满足上式
$$
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAX=2e5+10;
int a[MAX];
int main()
{
int t;
cin>>t;
while(t--){
map<int,LL> mp;
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
mp[a[i]]++;
}
LL res=0;
for(auto &[k,v]:mp){
res+=(v-1)*v/2;
}
res+=mp[1]*mp[2];
cout<<res<<"\n";
}
}
E. Queue Sort
大概题意有两种操作
1.将数组的第一个元素插入到末尾
2.将该元素与前一个元素交换,直到它成为第一个元素或严格大于前一个元素。
如果最小值后面的数是无序的那么我们就需要同时进行1,2两个操作,相当于数组依然没变
#include <bits/stdc++.h>
using namespace std;
const int MAX=2e5+10;
int a[MAX];
int main()
{
int m;
cin>>m;
while(m--){
int n,t=1;
cin>>n>>a[1];
int mi=a[1];
for(int i=2;i<=n;i++){
cin>>a[i];
if(a[i]<mi){
mi=a[i];
t=i;
}
}
int x=true;
for(int i=t+1;i<n;i++){
if(a[i]>a[i+1]){
cout<<"-1"<<endl;
x=false;
break;
}
}
if(x) cout<<t-1<<endl;
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现