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( ...
随机推荐
- shell 实现文件改名
修改文件名可以有不同的命令方式,mv 可以实现,但是使用rename 这种专业的改名字很好 对于单个的文件,可以直接使用以上的命令,那如果有大量的类似格式的文件名需要修改成其他格式的,该如何呢? 创建 ...
- ubuntu系统在安装好mysql后,出现ERROR 2002(HY000: Can't to local MySQL server through socket '/var/run/mysqld/mysqld.sock')(2)(图文详解)
不多说,直接上干货! 问题详情 我在写此博客之前,看了网上各种资料,写的太冗余和繁琐杂乱.最简单的解决方法莫过于我这篇博客.直接如下. 这是liux套接字网络的特性,win平台不会有这个问题. 解决方 ...
- 1、java线程模型
要了解多线程,先需要把java线程模型搞清楚,否则有时候很难理清楚一个问题. 硬件多线程: 物理机硬件的并发问题跟jvm中的情况有不少相似之处,物理机的并发处理方案对于虚拟机也有相当大的参考意义.在买 ...
- vim创建新的命令
转自:http://man.chinaunix.net/newsoft/vi/doc/usr_5F40.html#usr_40.txt *40.1* 键映射 简单的映射已经在 |05.3| 介绍过了. ...
- html和css(一)
简单点来说html和css就是一起连在使用,有了html和css会使网页更加有活力,看起来更加的好看. html是做关于网页标签这一块相当于骨架,更深的还需要另一个来完成,那就是css,相当于向里面加 ...
- 查看和设置Oracle数据库字符集
数据库服务器字符集select * from nls_database_parameters,其来源于props$,是表示数据库的字符集. 客户端字符集环境select * from nls_inst ...
- Hibernate中的session的线程安全问题
SessionFactory的实现是线程安全的,多个并发的线程可以同时访问一 个SessionFactory并从中获取Session实例, 而Session不是线程安全的,Session中包含了数 据 ...
- FTP FileZilla Server 本地加密C# 实现
最近公司要做一个资料管理模块,因系统是C/S架构,原来小文件都是直接使用7Z压缩后保存到SQL Server数据库 而资料管理模块也就是文件上传,下载加权限管理,考虑文件较多,还可能比较大,所以打算在 ...
- Sass学习笔记(三)
一.Sass的控制命令 二.Sass的函数功能 sass中除了可以定义变量,还自备了一系列函数功能,主要包括:字符串函数.数字函数.列表函数.颜色函数.Instrospection函数.三元函数等.当 ...
- oracle学习篇六:子查询
-- 1.查询比7654工资要高的员工 select * from emp where sal>(select sal from emp where empno=7654); ---2.查询最低 ...