#点击传送

题目描述

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\n"); else printf("NO\n");
return 0;
}

【codeforces1058】Vasya and Golden Ticket 枚举+暴力+模拟的更多相关文章

  1. CodeForces 1058C C. Vasya and Golden Ticket

    C. Vasya and Golden Ticket time limit per test1 second memory limit per test256 megabytes inputstand ...

  2. Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) C. Vasya and Golden Ticket 【。。。】

    任意门:http://codeforces.com/contest/1058/problem/C C. Vasya and Golden Ticket time limit per test 1 se ...

  3. cf#512 C. Vasya and Golden Ticket

    题目链接 http://codeforces.com/contest/1058/problem/C 这题还是暴力最方便,和的情况最多有n*a[i]  900种把每种都试一遍 #include<b ...

  4. 51nod 1414 冰雕 思路:暴力模拟题

    题意是现在有n个雕像把一个圆等分了,每一个雕像有一个吸引力. 叫你不移动雕像只去掉雕像让剩下的雕像还能等分这个圆,求剩下的雕像的吸引力之和的最大值. 显然去掉后剩下雕像的间隔应该是n的因子,因为这样才 ...

  5. hdu_1006 Tick and Tick(暴力模拟)

    hdu1006 标签(空格分隔): 暴力枚举 好久没有打题了,退队了有好几个月了,从心底不依赖那个人了,原来以为的爱情戏原来都只是我的独角戏.之前的我有时候好希望有个人出现,告诉自己去哪里,做什么,哪 ...

  6. bnuoj 20832 Calculating Yuan Fen(暴力模拟)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=20832 [题意]: 给你一串字符串,求一个ST(0<ST<=10000),对字符串中字符 ...

  7. POJ 1013 小水题 暴力模拟

    Counterfeit Dollar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 35774   Accepted: 11 ...

  8. hihoCoder #1871 : Heshen's Account Book-字符串暴力模拟 自闭(getline()函数) (ACM-ICPC Asia Beijing Regional Contest 2018 Reproduction B) 2018 ICPC 北京区域赛现场赛B

    P2 : Heshen's Account Book Time Limit:1000ms Case Time Limit:1000ms Memory Limit:512MB Description H ...

  9. 美团2018年CodeM大赛-资格赛 分数 暴力模拟

    链接:https://www.nowcoder.com/acm/contest/138/D来源:牛客网 小胖参加了人生中最重要的比赛——MedoC资格赛.MedoC的资格赛由m轮构成,使用常见的“加权 ...

随机推荐

  1. Java SSM框架理论知识

    一.Spring理论知识 1.Spring 在ssm中起什么作用? Spring:轻量级框架 作用:Bean工厂,用来管理Bean的生命周期和框架集成. 两大核心:1.IOC/DI(控制反转/依赖注入 ...

  2. windows10下JDK9的环境配置

    JDK版本:jdk-9.0.4_windows-x64_bin.exe windows版本:windows10 专业版 64位 需要在系统变量中新建如下3个变量: JAVA_HOME=jdk安装路径J ...

  3. linux用户组添加和权限的设置

    1.useradd  添加用户 useradd [选项]... 用户名 -u 用户id.-d 家目录路径.-s 登录Shell(解释器).-G 附加组 /sbin/nologin  :禁止用户登陆系统 ...

  4. spring赌上未来的一击:WebFlux性能实测

    最近花了一点时间系统的测试验证了在SpringBoot框架下使用SpringMVC和Spring WebFlux两种框架开发接口,对比了响应时间以及压测吞吐量的区别. WebFlux&Spri ...

  5. AVAssetWriter视频数据编码

    AVAssetWriter介绍 可以通过AVAssetWriter来对媒体样本重新做编码. 针对一个视频文件,只可以使用一个AVAssetWriter来写入,所以每一个文件都需要对应一个新的AVAss ...

  6. 简单聊聊Ehcache缓存

    最近工作没有那么忙,有时间来写写东西.今年的系统分析师报名已经开始了,面对历年的真题,真的难以入笔,所以突然对未来充满了担忧,还是得抓紧时间学习技术. 同事推了一篇软文,看到了这个Ehcache,感觉 ...

  7. 在Visual Studio 中使用git——同步到远程服务器-下(十二)

    在Visual Studio 中使用git--什么是Git(一) 在Visual Studio 中使用git--给Visual Studio安装 git插件(二) 在Visual Studio 中使用 ...

  8. 最多能创建多少个 TCP 连接?

    我是一个 Linux 服务器上的进程,名叫小进. 老是有人说我最多只能创建 65535 个 TCP 连接. 我不信这个邪,今天我要亲自去实践一下. 我走到操作系统老大的跟前,说: "老操,我 ...

  9. 让Qt5默认支持C++17的设置方法

    单个项目的设置方法 打开项目的 pro 文件,将CONFIG += console c++11改为CONFIG += console c++17即可. 永久默认支持 c++17 的设置方法 找到 Qt ...

  10. 7、linux快捷键

    ctrl +a:切换到命令行开始 ctrl+e:切换到命令行结尾 ctrl+c:终止当前命令或脚本 ctrl+d:退出当前shell,相当于exit ctrl+l:清除当前屏幕的内容,相当于clear ...