【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\n"); else printf("NO\n");
return 0;
}
【codeforces1058】Vasya and Golden Ticket 枚举+暴力+模拟的更多相关文章
- CodeForces 1058C C. Vasya and Golden Ticket
C. Vasya and Golden Ticket time limit per test1 second memory limit per test256 megabytes inputstand ...
- 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 ...
- cf#512 C. Vasya and Golden Ticket
题目链接 http://codeforces.com/contest/1058/problem/C 这题还是暴力最方便,和的情况最多有n*a[i] 900种把每种都试一遍 #include<b ...
- 51nod 1414 冰雕 思路:暴力模拟题
题意是现在有n个雕像把一个圆等分了,每一个雕像有一个吸引力. 叫你不移动雕像只去掉雕像让剩下的雕像还能等分这个圆,求剩下的雕像的吸引力之和的最大值. 显然去掉后剩下雕像的间隔应该是n的因子,因为这样才 ...
- hdu_1006 Tick and Tick(暴力模拟)
hdu1006 标签(空格分隔): 暴力枚举 好久没有打题了,退队了有好几个月了,从心底不依赖那个人了,原来以为的爱情戏原来都只是我的独角戏.之前的我有时候好希望有个人出现,告诉自己去哪里,做什么,哪 ...
- bnuoj 20832 Calculating Yuan Fen(暴力模拟)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=20832 [题意]: 给你一串字符串,求一个ST(0<ST<=10000),对字符串中字符 ...
- POJ 1013 小水题 暴力模拟
Counterfeit Dollar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 35774 Accepted: 11 ...
- 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 ...
- 美团2018年CodeM大赛-资格赛 分数 暴力模拟
链接:https://www.nowcoder.com/acm/contest/138/D来源:牛客网 小胖参加了人生中最重要的比赛——MedoC资格赛.MedoC的资格赛由m轮构成,使用常见的“加权 ...
随机推荐
- 狂神说redis笔记(四)
十二.Redis主从复制 概念 主从复制,是指将一台Redis服务器的数据,复制到其他的Redis服务器.前者称为主节点(Master/Leader),后者称为从节点(Slave/Follower), ...
- 【NX二次开发】PMI线性标注
PMI线性标注,二次开发的难点在于控制尺寸的位置,多花点儿时间都能搞出来,想走捷径最下面就是源码. 只需要摆好工作坐标,然后指定你要标注尺寸的两个点,就可以很方便得利用这个封装函数做出你想要的PMI. ...
- 【VBA】最大行,最大列
最大行: Range("B" & Cells.Rows.Count).End(xlUp).Row 最大列 colu = Range("XFD2").En ...
- 屏蔽国内app开屏广告接口的记录
脉脉: im-x.jd.com api.taou.com 虎扑: goblin.hupu.com 知乎(屏蔽此接口后,进入知乎会报一次错误,不影响正常使用) api.zhihu.com 豆瓣: api ...
- 【Azure 机器人】微软Azure Bot 编辑器系列(2) : 机器人/用户提问回答模式,机器人从API获取响应并组织答案 (The Bot Framework Composer tutorials)
欢迎来到微软机器人编辑器使用教程,从这里开始,创建一个简单的机器人. 在该系列文章中,每一篇都将通过添加更多的功能来构建机器人.当完成教程中的全部内容后,你将成功的创建一个天气机器人(Weather ...
- 我成了 GitHub Star
能够成为官方认证的 GitHub Star(明星)我和你们一样十分震惊! 可能很多读者不知道这个 GitHub Star 是什么,我先来介绍下它: GitHub Stars(明星)是 GitHub 官 ...
- git schnnel failed to receive handshake, SSLTLS connection failed
git schnnel failed to receive handshake, SSLTLS connection failed 报错,查看原因为git安装时ssl选择的不是openssl.重新安装 ...
- Custom Controller CollectionQT样式自定义 003 :Bubblemessage 气泡消息窗
效果Demo 思路大致上是加定时器,触发完成出现 - 停留 - 消失的效果. 源码:https://github.com/linzD00/CustomControllerLibrary
- webpack(2)webpack核心概念
前言 本质上,webpack 是一个用于现代 JavaScript 应用程序的 静态模块打包工具.当 webpack 处理应用程序时,它会在内部构建一个 依赖图(dependency graph) ...
- Software Architecture软件架构(方法、模式与框架)纵横谈
Software Architecture软件架构是啥 随着软件行业的发展,软件的规模越来越大,"Software Architecture软件架构"这个名词开始频繁出现.&quo ...