这次感觉难度偏低(A B C都是水题)。
比赛链接:ABC377
Problem A:
Code
#include <bits/stdc++.h>
using namespace std;
bool ok[10];
int main(){
string S;
cin>>S;
for(int i=0;i<S.size();i++)
ok[S[i]-'A']=true;
for(int i=0;i<3;i++){
if(!ok[i]){
cout<<"N0"<<endl;
return 0;
}
}
cout<<"Ye5"<<endl;
return 0;
}
Problem B:
Code
#include <bits/stdc++.h>
using namespace std;
bool ok[10][10];
string S[10];
void print(){
for(int i=0;i<8;i++){
for(int j=0;j<8;j++)
cout<<ok[i][j]<<' ';
cout<<endl;
}
}
int main(){
memset(ok,true,sizeof(ok));
for(int i=0;i<8;i++){
cin>>S[i];
for(int j=0;j<8;j++){
if(S[i][j]=='#'){
ok[i][j]=false;
for(int k=0;k<8;k++)
ok[i][k]=false;
for(int k=0;k<8;k++)
ok[k][j]=false;
}
}
print();
}
int ans=0;
for(int i=0;i<8;i++){
for(int j=0;j<8;j++)
ans+=ok[i][j];
}
cout<<ans<<endl;
return 0;
}
Problem C:
Code
#include <bits/stdc++.h>
using namespace std;
const int dx[]={0,2,1,-1,-2,-2,-1,1,2};
const int dy[]={0,1,2,2,1,-1,-2,-2,-1};
int main(){
int N,M;
cin>>N>>M;
long long ans=1ll*N*N;
//cout<<ans<<endl;
set<pair<int,int>> st;
for(int i=1;i<=M;i++){
int a,b;
cin>>a>>b;
for(int j=0;j<9;j++){
int x=a+dx[j];
int y=b+dy[j];
cout<<"第"<<i<<"组第"<<j<<"个:"<<x<<' '<<y<<endl;
if(0<x && x<=N && 0<y && y<=N && st.find(make_pair(x,y))==st.end()){
//cout<<"???"<<endl;
ans--;
st.insert(make_pair(x,y));
}
}
}
cout<<ans<<endl;
return 0;
}
Problem D:
Sol
首先,如果满足题意,那么
肯定也满足题意。因此,存在一个
,使得:
- 对于每一个
,当且仅当
,都有
满足要求。
因此,只要找到所有的,那么答案就是
。
接下来是求解的过程:
假设我们知道要求
。如果没有 i 使得
,那么
,否则
,其中
是最大的满足
的
。
因此我们可以通过递推求出,时间复杂度为
。
Code
//十年OI一场空,后面忘了
#include <bits/stdc++.h>
using namespace std;
const int MAX=200005;
int d[MAX]={1};
int main(){
int N,M;
cin>>N>>M;
for(int i=1;i<=N;i++){
int L,R;
cin>>L>>R;
d[R]=max(d[R],(long long)L+1);
}
for(int r=1;r<=M;r++)
d[r]=max(d[r],d[r-1]);
int ans=0;
for(int r=1;r<=M;r++)
ans+=(r-d[r]+1);
cout<<ans<<endl;
return 0;
}