牛客小白月赛28

牛客小白月赛28

A 牛牛和牛可乐的赌约

#include <bits/stdc++.h>
//#define int ll
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 3e3+ 10;

ll pow_mod(long long a,long long b){
    ll ret=1;
    a%=mod;
    while(b){
        if(b&1)ret=ret*a%mod;
        a=(a*a)%mod,b>>=1;
    }
    return ret%mod;
}

void extend_gcd(long long a,long long b,long long &x,long long &y){
    if(b==0){x=1,y=0;return;}
    extend_gcd(b,a%b,x,y);
    long long tmp=x;
    x=y,y=tmp-(a/b)*y;
}

long long mod_inverse(long long a,long long m){
    long long x,y;
    extend_gcd(a,m,x,y);
    return (m+x%m)%m;
}

void solve() {
    ll n,m,ans;
    cin>>n>>m;
    ans=pow_mod(n%mod,m%mod);
    cout<<mod_inverse(ans,mod)%mod<<"\n";
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

B 牛牛和牛可乐的赌约2

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
//const int INF = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const int maxn = 3e3+ 10;

void solve() {
    ll x,y;
    cin>>x>>y;
    if (x+y==0)cout<<"awsl"<<"\n";
    else {
        if (x%3^y%3) cout<<"yyds"<<"\n";
        else cout<<"awsl"<<"\n";
    }
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}


C 单词记忆方法

#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
//const int INF = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const int maxn = 3e3+ 10;
int i=0;string s;
int solve() {
    int sum=0,a=0;
    for(;i<s.size();i++){
        int k=0;
        while  (s[i]<='9'&&s[i]>='0') k=k*10+s[i++]-'0';
        sum+=a*max(k,1ll),a=0;
        if (s[i]<='Z'&&s[i]>='A') a+=s[i]-'A'+1;
        if (s[i]=='(') i++,a=solve();
        else if (s[i]==')') break;
    }
    sum+=a;
    return sum;
}

signed main() {
    //ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
    //cin >> _;
    while (_--) {cin>>s;
        cout<<solve();
    }
    return 0;
}

D 位运算之谜

在这里插入图片描述

#include <bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 3e3+ 10;

void solve() {
    int x,y;
    cin>>x>>y;
    int t=x-(y<<1);
    cout<<(t<0||t&y?-1:t)<<"\n";
}

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

G 牛牛和字符串的日常

#include <bits/stdc++.h>
//#define int ll
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 1e6 + 10;

string a, s;
int nextt[maxn];

void init(){
    nextt[0]=nextt[1]=0;
    for (int i = 1; i < s.size(); ++i) {
        int j = nextt[i];
        while (j and s[i]!=s[j]) j=nextt[j];
        nextt[i+1]=(s[i]==s[j]?j+1:0);
    }
}

int kmp() {
    int mx = 0;
    int j = 0;
    for (int i = 0; i < a.size(); ++i) {
        while (j and a[i] != s[j]) j = nextt[j];
        if (a[i] == s[j]) j++;
        mx = max(mx, j);
    }
    return mx;
}

void solve() {

    int t, ans = 0;
    cin >> s >> t;
    init();
    while (t--) {
        cin >> a;
        ans += kmp();
    }
    cout << ans << "\n";
}

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

I 迷宫

bitset学习1

#include <bits/stdc++.h>
//#define int ll
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 1e6 + 10;
bitset<10010> dp[105][105];
int a[105][105];

void solve() {
    int n, m, mo = 1e4 + 7;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            cin >> a[i][j], a[i][j] %= mo;
    dp[1][1].set(a[1][1]);
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (i == 1 and j == 1)continue;
            dp[i][j] |= (dp[i - 1][j] << a[i][j]) | (dp[i - 1][j] >> (mo - a[i][j]));
            dp[i][j] |= (dp[i][j - 1] << a[i][j]) | (dp[i][j - 1] >> (mo - a[i][j]));
        }
    }
    cout << dp[n][m].count() << "\n";
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;
//    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值