Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) C. Vasya and Golden Ticket 【。。。】
任意门:http://codeforces.com/contest/1058/problem/C
1 second
256 megabytes
standard input
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.
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.
If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).
5
73452
YES
4
1248
NO
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 【。。。】的更多相关文章
- 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 个数,对于一个选定的区间,区间内的数可以通过重新排列二进制数的位置得到一个新的数,问 ...
- Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) E. Vasya and Good Sequences
题目链接 官网题解写的好清楚,和昨晚Aguin说的一模一样…… 这题只和每个数1的个数有关,设每个数1的个数的数组为$b$,就是首先一段如果是好的,要满足两个条件: 1.这一段$b$数组和为偶数,因为 ...
- 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++ ...
- (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 ...
- 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/ ...
- 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 ...
- 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 ...
- Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)B. Personalized Cup
题意:把一长串字符串 排成矩形形式 使得行最小 同时每行不能相差大于等于两个字符 每行也不能大于20个字符 思路: 因为使得行最小 直接行从小到大枚举即可 每行不能相差大于等于两个字符相当于 ...
- 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( ...
随机推荐
- Vue添加新的响应式属性
vm.userProfile = Object.assign({}, vm.userProfile, { age: , favoriteColor: 'Vue Green' })
- DP Intro - OBST
http://radford.edu/~nokie/classes/360/dp-opt-bst.html Overview Optimal Binary Search Trees - Problem ...
- nyoj 1239——引水工程——————【最小生成树 prim】
引水工程 时间限制:2000 ms | 内存限制:65535 KB 难度:3 描述 南水北调工程是优化水资源配置.促进区域协调发展的基础性工程,是新中国成立以来投资额最大.涉及面最广的战略性工 ...
- 细说C#中的序列化与反序列化的基本原理和过程
虽然我们平时都使用第三方库来进行序列化和反序列化,用起来也很方便,但至少得明白序列化与反序列化的基本原理. 懂得人就别看了! 注意:从.NET Framework 2.0 开始,序列化格式化器类Soa ...
- 接收时间戳model [JsonConverter(typeof(UnixDateTimeConverter))]
/// <summary> /// 创建时间 /// </summary> [JsonProperty("createtim ...
- 解决npm install安装慢的问题
国外镜像会很慢 可用 get命令查看registry npm congfig get registry 原版结果为 http://registry.npmjs.org 用set命令换成阿里的镜像就可以 ...
- webpack+babel+react操作小结
最近学习了一下Webpack,个人感觉还是非常实用的,现在总结一下自己的学习笔记. 什么是 Webpack Webpack 是一个模块打包器.它将根据模块的依赖关系进行静态分析,然后将这些模块按照指定 ...
- Protocol Buffers序列化原理
1. 使用Varint编码数据,越小的数据,用少的字节编码.如小于128的用一个字节编码,大于128的用多个字节编码.同时,每个字节最高为1或者0表示是否为数字的一部分. 2. 由于负数的补码表示很大 ...
- hibernate的各种保存方式的区别 (save,persist,update,saveOrUpdte,merge,flush,lock)
hibernate的保存hibernate对于对象的保存提供了太多的方法,他们之间有很多不同,这里细说一下,以便区别:一.预备知识:在所有之前,说明一下,对于hibernate,它的对象有三种状态,t ...
- Java中Date()类 日期转字符串、字符串转日期的问题(已解决)
Java中Date()类 日期转字符串.字符串转日期的问题 今天在写东西的时候突然发现一个问题,就是先new 一个Date()然后将生成的值转为字符串, 然后再将转换后的字符串再次用new Date( ...