A题最差题解

校园活动

https://ac.nowcoder.com/acm/contest/10845/A

菜鸡唯一会的一个题
首先读题 对队列 进行分割后要求和相等
1e3的数据 我想了一下 直接跑on2
跑第一组占用几个 然后得出和 然后用这个和 算能不能正好把数列分割
如果可以就用max记录一下 注意只能分割不了的话 输出-1

#include<iostream>
#include<math.h>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
int n, jg = 0;
string s;
int pd(int fz)
{
    int num = 0,jl=0;
    for (int i = 1; i <=fz; i++)
    {
        num += s[i-1]-'0';
    }
    int numz = 0;
    for (int i = 0; i <s.length(); i++)
    {
        numz += s[i] - '0';
        if (num == numz)
        {
            jl++;
            numz = 0;
        }
        else if(num < numz)
        {
            return 1;
        }
    }

    if(jl<2)
    {
        return 0;
    }
    if (numz != 0 && num < numz)
    {
        return 1;
    }
    if (numz != 0 && num > numz)
    {
        return 2;
    }

    jg = max(jg,jl);
    return 1;
}
int main() {
    cin >> n >> s;
    for (int i = 1; i < n; i++)
    {
        pd(i);
    }
    if (jg == 0)
        cout << -1;
    else
    cout << jg;
}
全部评论
jg==坚果(逃
点赞 回复 分享
发布于 2021-01-15 22:27

相关推荐

27届学院本誓死冲击...:自我评价和校园经历全删了,荣誉经历只留奖学金,项目也全得换都不如外卖
点赞 评论 收藏
分享
03-06 20:09
贵州大学 Java
King987:你这个学历找个中大厂刷实习经历都是可以的,但是项目要有亮点才行,这个什么外卖就不要做了,去找找最新的项目,至少涉及高并发或者是新型的AI技术mcp rag啥的 ,我在出简历点评,但是你这个没什么好点评的,内容太少,而且含金量太低。自己改一改吧,或者看一下我的项目地址中,那里有大厂最近做过的实习项目
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
正在热议
更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务