首页 > 其他分享 >AtCoder Beginner Contest 311

AtCoder Beginner Contest 311

时间:2023-07-25 15:11:53浏览次数:46  
标签:AtCoder typedef const Beginner int 311 long solve define

AtCoder Beginner Contest 311

First ABC

思路:找到第一个a,b,c都出现的位置

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
typedef pair<int,int>PII;

typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=1e6+5,INF=0x3f3f3f3f,Mod=1e9+7;
const double eps=1e-6;

void solve(){
    int n;cin>>n;
    string s;
    cin>>s;
    int a=0,b=0,c=0;
    for(int i=0;i<n;++i){
        if(s[i]=='A')a=1;
        if(s[i]=='B')b=1;
        if(s[i]=='C')c=1;
        if(a&&b&&c){
            cout<<i+1;
            return ;
        }
    }
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
    //init();
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
View Code

 

Vacation Together

思路:找到最大的连续'o'的列长度

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
typedef pair<int,int>PII;

typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=1e6+5,INF=0x3f3f3f3f,Mod=1e9+7;
const double eps=1e-6;

void solve(){
    int n,d,ans=0;cin>>n>>d;
    vector<string>ve(n);
    for(int i=0;i<n;++i)cin>>ve[i];
    char pre='o';
    for(int i=0,c=0;i<d;++i){
        bool ok=true;
        for(int j=1;j<n;++j)if(ve[j][i]!=ve[j-1][i]){
            ok=false;break;
        }
        if(ok&&ve[0][i]==pre)c++;
        else c=0;
        ans=max(ans,c);
    }
    cout<<ans;
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
    //init();
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
View Code

 

Find it!

思路:每个点都指向一点,那么一定有环,从一点开始搜,搜到搜过的点即找到环

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
typedef pair<int,int>PII;

typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=2e5+5,INF=0x3f3f3f3f,Mod=1e9+7;
const double eps=1e-6;
int n;
vector<int>ve(N);
vector<int>st(N);
int dfs(int u){
    if(st[u]){
        return u;
    }
    st[u]=1;
    return dfs(ve[u]);
}
void solve(){
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>ve[i];
    }
    st[1]=1;
    int res=dfs(ve[1]);
    vector<int>ans;
    int p=ve[res];
    ans.push_back(res);
    while(p!=res){
        ans.push_back(p);
        p=ve[p];
    }
    cout<<ans.size()<<'\n';
    for(auto v:ans)cout<<v<<' ';
}
signed main(){
    //ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
    //init();
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
View Code

 

Grid Ice Floor

思路:从(1,1)开始bfs,一个方向要搜到底,标记搜过的点,最后统计

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
typedef pair<int,int>PII;

typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=2e5+5,INF=0x3f3f3f3f,Mod=1e9+7;
const double eps=1e-6;
int n,m,ans=0;
vector<string>s(205);
int st[205][205],vis[205][205];
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
void bfs(int x,int y){
    queue<PII>q;
    q.push({x,y});
    st[1][1]=vis[1][1]=1;
    while(q.size()){
        auto [u,v]=q.front();q.pop();
        for(int i=0;i<4;++i){
            int xx=u,yy=v;
            while(s[xx+dx[i]][yy+dy[i]]!='#'){
                xx+=dx[i],yy+=dy[i];
                vis[xx][yy]=1;
            }
            if(!st[xx][yy]){
                q.push({xx,yy});
                st[xx][yy]=1;
            }
        }
    }
    for(int i=0;i<n;++i)
        for(int j=0;j<m;++j)ans+=vis[i][j];
}
void solve(){
    cin>>n>>m;
    for(int i=0;i<n;++i){
        cin>>s[i];
    }
    bfs(1,1);
    cout<<ans;
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t=1;
    //init();
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
View Code

 

 Defect-free Squares

思路:把洞的地方标为1,用前缀和判断是否为正方形。枚举每个点,二分找到以该点为右下角的最大正方形

#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define int __int128
typedef pair<int,int>PII;

typedef pair<string,int>PSI;
typedef pair<string,string>PSS;
const int N=3e3+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353;
const int inf=0x3f3f3f3f3f3f;
const double eps=1e-6;
const int dx[4]={-1,0,1,0};
const int dy[4]={0,1,0,-1};

int h,w,n;
int a[N][N];
void solve(){
    cin>>h>>w>>n;
    for(int i=0,u,v;i<n;++i){
        cin>>u>>v;
        a[u][v]=1;
    }
    int res=0;

    for(int i=1;i<=h;++i)
        for(int j=1;j<=w;++j){
            if(!a[i][j]){
                a[i][j]+=(a[i-1][j]+a[i][j-1]-a[i-1][j-1]);
                int l=0,r=min(i,j)-1,k;
                while(l<=r){
                    int mid=l+r>>1;
                    auto check=[&](int x){
                        int ii=i-x,jj=j-x;
                        int s=a[i][j]-a[i][jj-1]-a[ii-1][j]+a[ii-1][jj-1];
                        return !s;
                    };
                    if(check(mid))k=mid,l=mid+1;
                    else r=mid-1;
                }
                //cout<<i<<' '<<j<<':'<<k<<'\n';
                res+=(k+1);
            }
            else a[i][j]+=(a[i-1][j]+a[i][j-1]-a[i-1][j-1]);
        }
    cout<<res;

}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T=1;
    //init();
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}
View Code

 

标签:AtCoder,typedef,const,Beginner,int,311,long,solve,define
From: https://www.cnblogs.com/bible-/p/17579690.html

相关文章

  • AtCoder Beginner Contest 311
    A-FirstABC#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongint32_tmain(){ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);intn;strings;cin>>n>>s;set<char>c......
  • ABC311
    T1:FirstABC模拟代码实现n=int(input())s=input()A=B=C=Falseforiinrange(n):ifs[i]=='A':A=Trueifs[i]=='B':B=Trueifs[i]=='C':C=TrueifAandBandC:exit(print(i+1))......
  • Toyota Programming Contest 2023#4(AtCoder Beginner Contest 311)
    ToyotaProgrammingContest2023#4(AtCoderBeginnerContest311)A-FirstABC(atcoder.jp)记录一下\(ABC\)是否都出现过了然后输出下标#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;signedmain(){ios::sync_with_stdio(false);cin.tie(n......
  • Atcoder ARC058E Iroha and Haiku
    题目中的式子转化一下即存在一位\(i\)使得到\(i\)时的后缀和存在\(X+Y+Z,Y+Z,Z\),再发现\(X+Y+Z\le17\),考虑状压。设\(f_{i,j}\)为填了\(i\)个数当前后缀和中存在的数的状态为\(j\)(只存\(0\simX+Y+Z\)的数是否存在)的方案数。考虑转移,则下一位可......
  • 「解题报告」Toyota Programming Contest 2023#4(AtCoder Beginner Contest 311)
    比赛地址:ToyotaProgrammingContest2023#4(AtCoderBeginnerContest311)-AtCoder后记:大家都太强了%%%,如果我做不出第四题就要掉分了。。。A-FirstABCA-FirstABC(atcoder.jp)找到第一个\(\texttt{A,B,C}\)三种字符都出现的位置。/*Thecodewaswrittenby......
  • Atcoder ARC058B Iroha and a Grid
    考虑从第\(b\)列与第\(b+1\)之间分开这个矩阵,钦定\((i,b)\)下一步必须走到\((i,b+1)\),可以发现这样是不会漏算或算重的。于是就可以用乘法原理算出这个\(i\)的贡献:\(\binom{(i-1)+(b-1)}{i-1}\times\binom{(n-i)+(m-b-1)}{n-i}\),左半部分的就......
  • ABC311 A~G
    \(Atcoder\)\(Beginner\)\(Contest\)\(311\)首先,ABC题是个人都会,这里就不说了其次,Ex我是人故我不会,这里也不说了DMD读错一个题害的我瞪了好久好久。。。。题意:给定一个矩阵,其中有些是墙(边界也是),最初人在\((2,2)\),每一次可以选择上下左右四个方向中的其中一个行走,直到撞......
  • 练习记录-AtCoder Beginner Contest 311-(A-E)
    写的还挺顺的F之后补A-FirstABC找abc三个字母什么时候出现了一次输出即可B-VacationTogether题意:最长的几个人一排里面均有时间#include<bits/stdc++.h>#defineclosestd::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)usingnamespacestd;typedeflon......
  • Toyota Programming Contest 2023#4(AtCoder Beginner Contest 311)——D
    https://atcoder.jp/contests/abc311/tasks/abc311_d思路题目说如果当前方向的下一个点能走,那么就一直走,否则才能转向。根据题意模拟即可,这道题的难点在于,碰到已经走过的点到底要不要走。如果当前方向走到底,其中的点之前全部都走过那么就不能再走了。我们用bfs模拟,对于能一直走......
  • ABC311(5)
    ABC311A.#include<bits/stdc++.h>usingnamespacestd;typedeflonglongLL;typedefpair<int,int>PII;typedefunsignedlonglongULL;constintINF=0x3f3f3f3f;//无穷大constintMOD=1e9+7;//取余constintN=2e5+10;//初始N......