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;
    }
    
  • 相关阅读:
    seajs模块化开发
    agularJs 路由
    sass
    web工作流
    lufylegend游戏引擎
    canvas游戏之贪食蛇
    [bzoj3743 Coci2015] Kamp(树形dp)
    [bzoj2662 BeiJing wc2012] 冻结 (分层图+最短路)
    [luogu2680] 运输计划 (lca+二分+树上差分)
    [luogu1463 HAOI2007] 反素数 (约数)
  • 原文地址:https://www.cnblogs.com/Dawn-Star/p/9715985.html
Copyright © 2011-2022 走看看