当前位置:网站首页>Acwing 4301. Truncated sequence
Acwing 4301. Truncated sequence
2022-07-05 05:20:00 【hunziHang】
Given a by n A sequence of digits a1a2…an.
among , Every number is 0∼9 One of .
Please judge , Whether the sequence can be truncated from the middle into two or more non empty parts , The sum of the figures in each part is required to be equal .
for example ,350178 Can be truncated to 3 Parts of 350、17、8, And satisfy 3+5+0=1+7=8.
Input format
The first line contains an integer n.
The second line contains n A digital a1,a2,…,an, No spaces between numbers .
Output format
If you can truncate the sequence as required , The output YES, Otherwise output NO.
Data range
front 6 Test points meet 2≤n≤10.
All test points meet 2≤n≤100,0≤ai≤9.
Direct enumeration
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+100;
typedef pair<int,int> PII;
#define x first
#define y second
#define INF 0x3f3f3f3f
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
const int mod=1e9+7;
int n,m;
int a[N];
int sum;
int main()
{
string st;
cin>>n;
cin>>st;
for(int i=0;i<n;i++)
{
a[i]=st[i]-'0';
sum+=a[i];
}
for(int i=2;i<=n;i++) // Enumerate the number of segments divided into
{
if(sum%i==0) // If you can divide it, you can continue to judge
{
int f=sum/i,flag=1;
for(int j=0,s=0;j<n;j++)
{
s+=a[j];
if(s>f) // If exceeded f Then it will only get bigger and bigger , It is illegal.
{
flag=0;
break;
}
else if(s==f) // For the initial 0
s=0;
}
if(flag)
{
cout<<"YES"<<endl;
return 0;
}
}
}
cout<<"NO"<<endl;
return 0;
}边栏推荐
- Double pointer Foundation
- Research on the value of background repeat of background tiling
- Embedded database development programming (VI) -- C API
- [allocation problem] 455 Distribute cookies
- 嵌入式数据库开发编程(五)——DQL
- The next key of win generates the timestamp file of the current day
- 第六章 数据流建模—课后习题
- Demonstration of using Solon auth authentication framework (simpler authentication framework)
- 利用HashMap实现简单缓存
- Bubble sort summary
猜你喜欢

Data is stored in the form of table

小程序直播+電商,想做新零售電商就用它吧!

Pointnet++的改进

Page countdown

嵌入式数据库开发编程(六)——C API

【论文笔记】Multi-Goal Reinforcement Learning: Challenging Robotics Environments and Request for Research

object serialization

Learning notes of "hands on learning in depth"

《动手学深度学习》学习笔记

Do a small pressure test with JMeter tool
随机推荐
C language Essay 1
Embedded database development programming (V) -- DQL
Ue4/ue5 illusory engine, material chapter, texture, compression and memory compression and memory
小程序直播+电商,想做新零售电商就用它吧!
嵌入式数据库开发编程(五)——DQL
Fragment addition failed error lookup
cocos_ Lua listview loads too much data
Haut OJ 1321: mode problem of choice sister
ssh免密登录设置及使用脚本进行ssh登录并执行指令
Web APIs DOM节点
[to be continued] [depth first search] 547 Number of provinces
MySQL数据库(一)
Use of snippets in vscode (code template)
Solon 框架如何方便获取每个请求的响应时间?
Heap sort summary
Listview is added and deleted at the index
Magnifying glass effect
A three-dimensional button
Lua determines whether the current time is the time of the day
FVP和Juno平台的Memory Layout介绍