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

AtCoder Beginner Contest 042

时间:2023-01-12 13:55:24浏览次数:45  
标签:AtCoder return Beginner int invFact Iroha 042 fact mod

A - Iroha and Haiku (ABC Edition)

#include<bits/stdc++.h>

using namespace std;

int32_t main() {
    int a = 2 , b = 1;
    for( int i = 1 , x ; i <= 3 ; i ++ ){
        cin >> x;
        if( x == 5 ) a --;
        if( x == 7 ) b --;
    }
    if( a == b && b == 0 ) printf("YES\n");
    else printf("NO");
    return 0;
}

B - Iroha Loves Strings (ABC Edition)

简单的给字符串拍个序就好

#include<bits/stdc++.h>

using namespace std;

int32_t main() {
    int n , l;
    cin >> n >> l;
    vector<string> s(n);
    for( auto &i : s ) cin >> i;
    sort( s.begin() , s.end() , [](string a , string b ){
        return a+b < b+a;
    });
    for( auto i : s )
        cout << i;
    return 0;
}

C - Iroha's Obsession

其实就是暴力的做一下就好了,把每个数都拆分开判断有没有不喜欢的

#include <bits/stdc++.h>
#define ll long long 
using namespace std;
bool vis [15];

int check (int a){
	while(a!=0){
		int tmp = a%10;
		if(vis[tmp] ==true)
		return 0;
		a/=10;
	}
	return 1;
}
int main (){
     int n , m;
     cin >> n >> m;
     for (int i = 0;i<m;i++){
     	int tmp;
     	cin >> tmp;
     	vis[tmp] = true;
     }
     int f = 0;
	 while(1){
     	if(f) break;
     	if(check(n))
     	f = 1;
     	n++;
     }
     cout << n-1;
	return 0;     
}

D - Iroha and a Grid

这道题算是本场最难的了,其实如果去除左下角不能走的点很简单,就是一共简单的组合数的计算。

从下图我们可以知道,符合要求的任意一种情况都一定是先走到1,2,2中任意一格,然后向下走一步,然后再走到终点,所以我们枚举一下这些点,计算从起点到这里,然后向下走一步,最后再走到终点的情况即可。

#include<bits/stdc++.h>
#define int long long
using namespace std;

const int N = 1e6+5 , mod = 1e9+7;
int fact[N] , invFact[N];

int power( int x , int y ){
    int ans = 1;
    x %= mod;
    while( y ){
        if( y & 1 ) ans = ans * x % mod;
        x = x * x % mod , y >>= 1;
    }
    return ans;
}

int inv( int x ){
    return power( x , mod-2 );
}

int C( int x , int y ){
    return fact[x] * invFact[x-y] % mod * invFact[y] % mod;
}

int cnt( int ax , int ay, int bx , int by ){
    return C( bx+by-ax-ay , bx-ax );
}

void init(){
    fact[0] = 1 , invFact[0] = inv(1);
    for( int i = 1 ; i < N ; i ++ )
        fact[i] = fact[i-1] * i % mod , invFact[i] = inv(fact[i]);
    return;
}

int32_t main() {
    init();
    int n , m , a , b , res = 0;
    cin >> n >> m >> a >> b;
    a = n - a ;
    for( int j = b + 1 ; j <= m ; j ++ )
        res = ( res + cnt( 1 , 1 , a , j ) * cnt( a+1 , j , n , m ) % mod ) % mod;
    cout << res ;
    return 0;
}

标签:AtCoder,return,Beginner,int,invFact,Iroha,042,fact,mod
From: https://www.cnblogs.com/PHarr/p/17046445.html

相关文章

  • AtCoder Beginner Contest 133
    AtCoderBeginnerContest133https://atcoder.jp/contests/abc133A-TorT#include<bits/stdc++.h>usingnamespacestd;intmain(){inta,b,n;ci......
  • AtCoder Beginner Contest 171
    A-αlphabet(abc171a)题目大意给定一个字母,其大写字母则输出A,否则输出a。解题思路isupper函数或者在'A'与Z之间即为大写字母。神奇的代码#include<bits/stdc+......
  • AtCoder284 D - Happy New Year 2023
    AtCoder284D-HappyNewYear2023[Editorial](Editorial-AtCoderBeginnerContest284)Youaregivenapositiveinteger\(N\).Itisknownthat\(N\)canbe......
  • AtCoder Beginner Contest 284
    A-SequenceofStrings#include<bits/stdc++.h>usingnamespacestd;int32_tmain(){intn;cin>>n;vector<string>s(n);for(auto&i:s)......
  • Atcoder ABC112D Partition
    链接难度:\(\texttt{1025}\)找到最大的正整数\(x\)使得\(m\modx=0\)且\(\frac{m}{x}\gen\)。难度在于读题,简化后就简单的一批了。暴力都能过。枚举\(m\)的......
  • AtCoder Beginner Contest 284(D,E,F)
    AtCoderBeginnerContest284(D,E,F)DD这可题的大意是有一个很大的数,n,它可以变成pXpXq(p,q是质数),要我们找出这两个质数我们可以发现,这一个n的质因数一定只有两个,p,q,而我......
  • C - Count Connected Components -- ATCODER
    C-CountConnectedComponentshttps://atcoder.jp/contests/abc284/tasks/abc284_c 思路寻找独立的子连通图个数。 使用map记录边,即点之间的连通性使用vector记......
  • AtCoder Beginner Contest 284
    AtCoderBeginnerContest284https://atcoder.jp/contests/abc284被D卡了,感觉十分的弱智。GEx看不懂题解(A-SequenceofStrings#include<bits/stdc++.h>usingn......
  • AtCoder Beginner Contest 284 C - Count Connected Components DFS的应用
    TimeLimit:2sec/MemoryLimit:1024MBScore: 300300 pointsProblemStatementYouaregivenasimpleundirectedgraphwith NN verticesnumbered 11 ......
  • Atcoder ABC284 前五题题解
    ABC284A-SequenceofStrings题意:有n个字符串\(s_1,s_2,s_3,...,s_n\),要求按\(n,n-1,n-2,...,1\)的顺序输出样例:输入3TakahashiAokiSnuke输出......