首页 > 其他分享 >(AtCoder Beginner Contest 312)

(AtCoder Beginner Contest 312)

时间:2023-07-29 22:22:12浏览次数:40  
标签:AtCoder typedef const Beginner int 312 long dp define

(AtCoder Beginner Contest 312)

A - Chord

#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;


void solve(){
    string s;cin>>s;
    string a[7]={"ACE","BDF","CEG","DFA","EGB","FAC","GBD"};
    for(int i=0;i<7;++i){
        if(s==a[i]){
            cout<<"Yes";return ;
        }
    }
    cout<<"No";
}
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

 

B - TaK Code

思路:维护黑色的前缀和,枚举每个点,满足左上角和右下角的3、4个宽度的黑色个数都为9则输出

#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 g[105][105];
void solve(){
    int n,m;cin>>n>>m;
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j){
            char c;cin>>c;
            if(c=='#')g[i][j]=1;
            g[i][j]+=(g[i-1][j]+g[i][j-1]-g[i-1][j-1]);
        }
    for(int i=1;i+8<=n;++i)
        for(int j=1;j+8<=m;++j){
            int x1=i+2,y1=j+2,a1,a2,b1,b2;
            a1=g[x1][y1]-g[i-1][y1]-g[x1][j-1]+g[i-1][j-1];
            x1=i+3,y1=j+3;
            a2=g[x1][y1]-g[i-1][y1]-g[x1][j-1]+g[i-1][j-1];
            x1=i+5,y1=j+5;
            int x2=i+8,y2=j+8;
            b1=g[x2][y2]-g[x1-1][y2]-g[x2][y1-1]+g[x1-1][y1-1];
            x1=i+6,y1=j+6;
            b2=g[x2][y2]-g[x1-1][y2]-g[x2][y1-1]+g[x1-1][y1-1];
            //if(i==1&&j==10)cout<<a1<<' '<<a2<<' '<<b1<<' '<<b2<<'\n';
            if(a1==a2&&a2==b1&&b1==b2&&b2==9){
                cout<<i<<' '<<j<<'\n';
            }
        }
}
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

 

C - Invisible Hand

思路:对a、b排序,二分x,比较a中小于等于x的个数和b中大于等于x的个数,找出最小的x

#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;


void solve(){
    int n,m;cin>>n>>m;
    vector<int>a(n),b(m);
    for(int i=0;i<n;++i)cin>>a[i];
    for(int i=0;i<m;++i)cin>>b[i];
    sort(a.begin(),a.end()),sort(b.begin(),b.end());
    int l=1,r=1e9+1,ans;
    auto check=[&](int x){
        int p1= upper_bound(a.begin(),a.end(),x)-a.begin();
        int p2= lower_bound(b.begin(),b.end(),x)-b.begin();
        p2=b.size()-p2;
        return p1>=p2;
    };
    while(l<=r){
        int mid=l+r>>1;
        if(check(mid))ans=mid,r=mid-1;
        else l=mid+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

 

D - Count Bracket Sequences

思路:对于 ‘( ’计一分,‘ )’计-1分;

dp[i][j]表示前i个字符的情况,且第i个字符选定后,当前的分值为j的情况数

枚举到i时,最多有i分,再枚举0~i分的情况;

那么当s[i]='('时,dp[i][j]=dp[i-1][j-1]

当s[i]=')'时,dp[i][j]=dp[i-1][j+1]

当s[i]='?'时,s[i]可以是'('和')',则dp[i][j]=dp[i][j+1]+dp[i][j-1]

最后的答案即为dp[n][0]

#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 double eps=1e-6;

int dp[N][N];
void solve(){
    string s;
    cin>>s;int n=s.size();
    s.insert(0," ");
    dp[0][0]=1;
    for(int i=1;i<=n;++i){
        for(int j=0;j<=i;++j){
            if(s[i]=='(')dp[i][j]=dp[i-1][j-1]%mod;
            else if(s[i]==')')dp[i][j]=dp[i-1][j+1]%mod;
            else{
                dp[i][j]=(dp[i-1][j-1]+dp[i-1][j+1])%mod;
            }
        }
    }
    cout<<dp[n][0];
}
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

 

E - Tangency of Cuboids

F - Cans and Openers

标签:AtCoder,typedef,const,Beginner,int,312,long,dp,define
From: https://www.cnblogs.com/bible-/p/17590676.html

相关文章

  • Atcoder ABC259H Yet Another Path Counting
    首先可以想到有组合数的方法:令起点为\((x1,y1)\),终点为\((x2,y2)\),则路径方案数就为\(\binom{x2+y2-x1-y1}{x2-x1}\),这样设有\(k\)个相同颜色的点,时间复杂度就为\(O(k^2)\)。再考虑到还有\(\text{DP}\)方法:令\(f_{x,y}\)为走到\((x,y)\)的方案数,不限制......
  • Atcoder ARC060D Digit Sum
    看到\(n\le10^{11}\),考虑按根号分为两部分处理。对于\(b\le\sqrt{n}\),考虑直接暴力算\(\operatorname{f}(b,n)\)判断是否等于\(s\),这部分的计算量是\(O(\sqrt{n})\)级别的。对于\(\sqrt{n}<b\len\),则这个时候在\(b\)进制下\(n\)也只有两位,考虑列出\(n,s\)......
  • AtCoder Beginner Contest 311
    AtCoderBeginnerContest311FirstABC思路:找到第一个a,b,c都出现的位置#include<bits/stdc++.h>usingnamespacestd;#defineintlonglong//#defineint__int128typedefpair<int,int>PII;typedefpair<string,int>PSI;typedefpair<string,string&......
  • 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......
  • 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}\),左半部分的就......
  • 练习记录-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模拟,对于能一直走......