zoukankan      html  css  js  c++  java
  • 【codeforces1058】Vasya and Golden Ticket 枚举+暴力+模拟

    #点击传送

    题目描述

    Recently Vasya found a golden ticket — a sequence which consists of nn digits a1a2…ana1a2…an. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178350178 is lucky since it can be divided into three segments 350350, 1717 and 88: 3+5+0=1+7=83+5+0=1+7=8. Note that each digit of sequence should belong to exactly one segment.

    Help Vasya! Tell him if the golden ticket he found is lucky or not.

    题目大意

    判断能否就是将一个数字串,分成连续的若干段,使其每一段的和相等

    分析

    也没什么好讲的,数据很小,直接上暴力,枚举每一段的和,判断是否成立。
    注意:!!!要判断0的情况,这是一个坑!!!!

    AC代码

    #include <bits/stdc++.h>
    
    using namespace std;
    
    char ch[105];
    int a[105];
    
    int main() {
        int len; scanf("%d",&len);
        scanf("%s",ch);
        for (int i=1;i<=len;i++) a[i]=ch[i-1]-'0';
        int fg=0;
        for (int i=0;i<=900;i++) {
            int sum=0,cnt=0;
            for (int j=1;j<=len;j++) {
                sum+=a[j];
                if (sum==i) sum=0,cnt++; else if (sum>i) break;
            }
            if (sum==0 && cnt>=2) fg=1;
        }
        if (fg) printf("YES
    "); else printf("NO
    ");
        return 0;
    }
    
  • 相关阅读:
    zech的神秘题库(武汉理工夜莺杯)
    回归第六题
    同余方程
    牛牛选路径(牛客)
    回归第三题
    区间dp复习提高专题
    乘法逆元(线性递推)
    回归第八题
    JAVA启动参数大全之二:非标准参数(转)
    (转)Spring Security 3.1 自定义实例之登陆
  • 原文地址:https://www.cnblogs.com/Dawn-Star/p/9715985.html
Copyright © 2011-2022 走看看