任意门:http://codeforces.com/contest/1058/problem/C

C. Vasya and Golden Ticket
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Input

The first line contains one integer nn (2≤n≤1002≤n≤100) — the number of digits in the ticket.

The second line contains nn digits a1a2…ana1a2…an (0≤ai≤90≤ai≤9) — the golden ticket. Digits are printed without spaces.

Output

If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).

Examples
input

Copy
5
73452
output

Copy
YES
input

Copy
4
1248
output

Copy
NO
Note

In the first example the ticket can be divided into 77, 3434 and 5252: 7=3+4=5+27=3+4=5+2.

In the second example it is impossible to divide ticket into segments with equal sum.

题意概括:

一串长度为N的数字,判断是否能分成相同和的若干块。

解题思路:

记一道被自己蠢哭的水题,主要是理解题意的问题;

一开始以为分块可以不连续,又是排序又乱七八糟搞一大堆;

结果分块是连续的,活生生的贪心水题。

读题很重要。

AC code:

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int MAXN = ;
char str[MAXN];
int N, sum;
int main()
{
scanf("%d", &N);
scanf("%s", &str);
bool flag = true;
for(int i = ; i < N-; i++){
sum += str[i]-'';
int pos = i+;
flag = true;
while(pos < N){
int sum2 = str[pos++]-'';
while(pos < N && sum2+str[pos]-'' <= sum){
sum2+=str[pos++]-'';
}
if(sum2 != sum) {flag = false; break;}
}
if(flag) {puts("YES"); break;}
}
if(flag == false) puts("NO");
return ;
}

Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) C. Vasya and Golden Ticket 【。。。】的更多相关文章

  1. Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) E. Vasya and Good Sequences(DP)

    题目链接:http://codeforces.com/contest/1058/problem/E 题意:给出 n 个数,对于一个选定的区间,区间内的数可以通过重新排列二进制数的位置得到一个新的数,问 ...

  2. Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) E. Vasya and Good Sequences

    题目链接 官网题解写的好清楚,和昨晚Aguin说的一模一样…… 这题只和每个数1的个数有关,设每个数1的个数的数组为$b$,就是首先一段如果是好的,要满足两个条件: 1.这一段$b$数组和为偶数,因为 ...

  3. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)

    Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++ ...

  4. (AB)Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round

    A. Right-Left Cipher time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path

    http://codeforces.com/contest/1072/problem/D bfs 走1步的最佳状态 -> 走2步的最佳状态 -> …… #include <bits/ ...

  6. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path(字典序)

    https://codeforces.com/contest/1072/problem/D 题意 给你一个n*n充满小写字母的矩阵,你可以更改任意k个格子的字符,然后输出字典序最小的从[1,1]到[n ...

  7. Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) C. Connect Three 【模拟】

    传送门:http://codeforces.com/contest/1087/problem/C C. Connect Three time limit per test 1 second memor ...

  8. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)B. Personalized Cup

    题意:把一长串字符串 排成矩形形式  使得行最小  同时每行不能相差大于等于两个字符 每行也不能大于20个字符 思路: 因为使得行最小 直接行从小到大枚举即可   每行不能相差大于等于两个字符相当于  ...

  9. Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3) C. Playing Piano

    题意:给出一个数列 a1 a2......an  让你构造一个序列(该序列取值(1-5)) 如果a(i+1)>a(i) b(i+1)>b(i) 如果a(i+1)<a(i)  那么b( ...

随机推荐

  1. (转)裸奔的后果!一次ssh被篡改的入侵事件

    裸奔的后果!一次ssh被篡改的入侵事件 原文:http://blog.51cto.com/phenixikki/1546669 通常服务器安全问题在规模较小的公司常常被忽略,没有负责安全的专员,尤其是 ...

  2. unity烘焙记录

    1.Unity Android 阴影不显示.阴影显示不正确 解决 http://blog.csdn.net/xuetao0605/article/details/50626181 2.阴影强度问题 不 ...

  3. lua-遍历集合-ipairs和pairs的区别

    --ipairs和pairs的区别arr = {1,3,[5]=5,name="kaikai",age=12, 89}--arr[4]= 23--ipairs--ipairs仅仅遍 ...

  4. Maven工程红色感叹号,且工程无红叉错误

    很可能是jar包不对,可以将maven库里的jar包删除,从 http://mvnrepository.com/ 根据jar包版本号下载到本地maven库,并在pom.xml里引入jar依赖 这次ja ...

  5. BNU34058——干了这桶冰红茶!——————【递推】

    干了这桶冰红茶! Time Limit: 1000ms Memory Limit: 65536KB 64-bit integer IO format: %lld      Java class nam ...

  6. ztree使用方法 python后台

    一.在提前加载js的地方写一段js,判断该页面是否需要添加ztree,我的项目所有提前加载的js都写在admin.js中 //增加ztree $(document).ready(function() ...

  7. (转)vs2010 vs2013等vs中如何统计整个项目的代码行数

    在一个大工程中有很多的源文件和头文件,我如何快速统计总行数? ------解决方案-------------------- b*[^:b#/]+.*$ ^b*[^:b#/]+.*$ ctrl + sh ...

  8. [SQL SERVER系列]工作经常使用的SQL整理,实战篇(二)[原创]

    工作经常使用的SQL整理,实战篇,地址一览: 工作经常使用的SQL整理,实战篇(一) 工作经常使用的SQL整理,实战篇(二) 工作经常使用的SQL整理,实战篇(三) 接着上一篇“工作经常使用的SQL整 ...

  9. scss-@if指令

    @if指令接受表达式和使用嵌套样式,无论表达式的结果只不过是false或null. 语法: @if expression { //CSS codes are written here } scss实例 ...

  10. scss-数据类型

    scss当前支持七种主要数据类型 (1).数字,1, 2, 13, 10px. (2).字符串,有引号字符串与无引号字符串,"foo", 'bar', baz. (3).颜色,bl ...