首页 > 其他分享 >牛客小白月赛98 A~D

牛客小白月赛98 A~D

时间:2024-10-13 11:48:58浏览次数:1  
标签:const 98 int ll cin long 牛客 小白月赛 mod

牛客小白月赛98 A~D

A-骰子魔术

签到不多说

// AC one more times
// nndbk
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
    ios::sync_with_stdio(false);   cin.tie(nullptr), cout.tie(nullptr);
    int n,x; cin>>n>>x;
    bool ok = false;
    for(int i = 1;i <= n; i++)
    {
        int t; cin>>t;
        if(x==t)ok = true;
    }   
    cout<<(ok?"YES":"NO")<<"\n";

    return 0;
}

B-最少剩几个?

思路:奇数+偶数=奇数,奇数*奇数=奇数。那么优先用奇数和偶数配对,剩下的奇数两两配对。

// AC one more times
// nndbk
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
    ios::sync_with_stdio(false);   cin.tie(nullptr), cout.tie(nullptr);
    int n; cin>>n;
    int even = 0,odd = 0;
    for(int i = 1;i <= n; i++)
    {
        int x; cin>>x;
        even += (x%2==0);
        odd += (x%2!=0);
    }

    int res = min(even,odd);
    odd -= res;
    res += odd/2*2;

    cout<<n-res<<'\n';

    return 0;
}

C-两个函数

思路:\(\sum_{i = 1}^{x-1}f(f(i)) = \sum_{i = 1}^{x-1}a(ax) = a^2\sum_{i = 1}^{x-1}x = a^2\dfrac{x(x-1)}{2}\)。取模小心点就行了。

// AC one more times
// nndbk
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 998244353;
const int N = 2e5 + 10;
ll qmi(ll a, ll b, ll mod)
{
    ll ans = 1 % mod;
    while(b)
    {
        if(b & 1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);   cin.tie(nullptr), cout.tie(nullptr);
    int t; cin>>t;
    ll inv = qmi(2, mod - 2, mod);
    while(t--)
    {
        ll a,x;
        cin>>a>>x;
        if(x==1){
            cout<<a*x%mod<<"\n";
            continue;
        }
        ll ans = a*a%mod;
        ans = ans*x%mod;
        ans = ans*(x-1)%mod;
        if(ans<0) ans += mod;
        ans %= mod;
        ans = ans*inv%mod;
        cout<<ans%mod<<"\n";
    }


    return 0;
}

D-切割 01 串 2.0

思路:发现数据范围很小呀,直接爆搜,加个记忆化。

// AC one more times
// nndbk
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 5e3 + 10;
int n,L,R;
string s;
ll s0[N],s1[N],dp[N][N];

ll dfs(ll l,ll r)
{
    ll& res = dp[l][r];
    if(res != -1)
        return res;
    res = 0;
    for(int i = l;i < r; i++)
    {
        ll t = 0;
        ll c0 = s0[i]-s0[l-1];
        ll c1 = s1[r]-s1[i];
        if(abs(c0-c1)>=L && abs(c0-c1)<=R)
            t = 1ll + dfs(l,i)+dfs(i+1,r);
        res = max(res,t);
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(false);   cin.tie(nullptr), cout.tie(nullptr);
    cin>>n>>L>>R;
    cin>>s;

    s = "?"+s;
    for(int i = 1;i <= n; i++)
    {
        s0[i] = s0[i-1]+(s[i]=='0');
        s1[i] = s1[i-1]+(s[i]=='1');
    }

    memset(dp,-1,sizeof(dp));
    cout<<dfs(1,n)<<"\n";

    return 0;
}

好像很多人用区间dp。不过也差不多

// AC one more times
// nndbk
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 5e3 + 10;
int n,L,R;
string s;
ll s0[N],s1[N],dp[N][N];


int main()
{
    ios::sync_with_stdio(false);   cin.tie(nullptr), cout.tie(nullptr);
    cin>>n>>L>>R;
    cin>>s;

    s = "?"+s;
    for(int i = 1;i <= n; i++)
    {
        s0[i] = s0[i-1]+(s[i]=='0');
        s1[i] = s1[i-1]+(s[i]=='1');
    }

    for(int len = 1;len <= n; len++){
        for(int l = 1;l+len-1<=n;l++)
        {
            int r = l+len-1;
            for(int k = l;k < r; k++){
                int t1 = s0[k]-s0[l-1];
                int t2 = s1[r]-s1[k];
                if(abs(t1-t2)>=L && abs(t1-t2)<=R)
                {
                    dp[l][r] = max(dp[l][r],dp[l][k]+dp[k+1][r]+1);
                }
            }
        }
    }
    cout<<dp[1][n];
    return 0;
}

标签:const,98,int,ll,cin,long,牛客,小白月赛,mod
From: https://www.cnblogs.com/nannandbk/p/18462099

相关文章

  • 牛客小白月赛99 C~E
    牛客小白月赛99C~EC-迷宫思路:其实能不能到达,只要看起点和终点是否能变成连通的。射线技能只能用一次,我们在起点能到的点\((x,y)\)去\(check:x,y,x-1,y-1,y+1\)是否在终点能到达的点的坐标中出现。//AConemoretimes//nndbk#include<bits/stdc++.h>usingnamespacestd;......
  • 每日OJ题_牛客_比那名居的桃子_滑动窗口/前缀和_C++_Java
    目录牛客_比那名居的桃子_滑动窗口/前缀和题目解析C++代码Java代码牛客_比那名居的桃子_滑动窗口/前缀和比那名居的桃子(nowcoder.com)描述:        小红有一天看到了一只桃子,由于桃子看上去就很好吃,小红很想把它吃掉。已知吃下桃子后,每天可以获得ai​的......
  • CF1988C. Increasing Sequence with Fixed OR
    链接:    https://codeforces.com/problemset/problem/1988/Chttps://codeforces.com/problemset/problem/1988/C大意:    给定一个n,找一个最长的正整数递增序列,并满足相邻或等于n思路:    1、显然是要分析二进制方面的规律        2、首先......
  • 题解:牛客小白月赛102(A - C)
    A序列中的排列题意:每次给你两个正整数\(n,k\),并给你一段长度为\(n\)的序列。(所有输入均为小于等于100的正整数)问:原序列中是否存在子序列,使得这个子序列是\(k\)的排列子序列:某个序列的子序列是从最初序列通过去除某些元素但不破坏余下元素的相对位置(在前或在后)而形成的......
  • 985研一学习日记 - 2024.10.11
    偶尔一碗热鸡汤:一个人内耗,说明他活在过去;一个人焦虑,说明他活在未来。只有当一个人平静时,他才活在现在。日常1、6:00起床√2、健身1h今天练了肩部以及背,然后跑步半小时3、LeetCode刷了2题括号生成:回溯、中仍然使用递归+回溯的方法,递归遍历字符串,每遇到一个)就在其......
  • springboot空巢老人健康管理系统小程序-计算机毕业设计源码29889
    摘 要随着社会老龄化程度不断加剧,空巢老人群体的健康管理问题日益引起人们的关注。为了更好地满足空巢老人群体的健康管理需求,本研究致力于设计并实现一款基于SpringBoot框架的空巢老人健康管理系统。该系统旨在为管理员用户、老人用户和医生用户提供全方位的健康管理服务,......
  • 198号资源-源程序:(SCI论文+程序)未知时延下无线传感器网络时钟同步算法研究-----已提供下
    ......
  • 尚雷仕(湖北)健康科技公司5.98MW分布式光伏10KV并网系统应用
    1.概述我国正致力于实现“双碳”目标,新能源装机容量正快速增长,电力系统正在经历向高比例新能源系统的转型。然而,分布式光伏的接入也带来了挑战,例如电能质量的下降和供电可靠性的不足。尽管如此,光伏发电依然具有显著的经济效益和环保优势,能够有效降低煤炭消耗和减少二氧化碳排......
  • 机器学习/数据分析--用通俗语言讲解时间序列自回归(AR)模型,并用其预测天气,拟合度98%+
    时间序列在回归预测的领域的重要性,不言而喻,在数学建模中使用及其频繁,但是你真的了解ARIMA、AR、MA么?ACF图你会看么??时间序列数据如何构造???,我打过不少数学建模,但是都没有弄得很清楚;这篇将详细讲解了基础模型—AR的原理.文章目录1、自回归(AR)详解1、简要说明2、原理讲解......
  • 2024牛客暑假多校第三场 - A. Bridging the Gap 2
    思路全在注释里了:#include<cstdio>#include<cmath>#include<algorithm>usingnamespacestd;constintN=5e5+5;intn,l,r,a[N];boolSolve(){ //打工次数:一个人能将其他人运过去的次数=一个人能过去以后能往返的次数 scanf("%d%d%d",&n,&l,&r); intmin_go=c......