当前位置:网站首页>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;
}
边栏推荐
- Solon Logging 插件的添加器级别控制和日志器的级别控制
- [paper notes] multi goal reinforcement learning: challenging robotics environments and request for research
- National teacher qualification examination in the first half of 2022
- [allocation problem] 455 Distribute cookies
- [speed pointer] 142 circular linked list II
- Binary search basis
- Development error notes
- [转]MySQL操作实战(一):关键字 & 函数
- Haut OJ 1357: lunch question (I) -- high precision multiplication
- [leetcode] integer inversion [7]
猜你喜欢
Heap sort summary
Embedded database development programming (zero)
Generate filled text and pictures
Learning notes of "hands on learning in depth"
Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
Introduction to tools in TF-A
GBase数据库助力湾区数字金融发展
[轉]: OSGI規範 深入淺出
National teacher qualification examination in the first half of 2022
[to be continued] [UE4 notes] L1 create and configure items
随机推荐
Embedded database development programming (VI) -- C API
[转]:Apache Felix Framework配置属性
What is the agile proportion of PMP Exam? Dispel doubts
National teacher qualification examination in the first half of 2022
2022/7/1學習總結
Haut OJ 1347: addition of choice -- high progress addition
Solon Logging 插件的添加器级别控制和日志器的级别控制
《动手学深度学习》学习笔记
Grail layout and double wing layout
Download and use of font icons
When will Wei Lai, who has been watched by public opinion, start to "build high-rise buildings" again?
Double pointer Foundation
Haut OJ 1352: string of choice
记录QT内存泄漏的一种问题和解决方案
发现一个很好的 Solon 框架试手的教学视频(Solon,轻量级应用开发框架)
[轉]: OSGI規範 深入淺出
xftp7与xshell7下载(官网)
小程序直播+電商,想做新零售電商就用它吧!
Demonstration of using Solon auth authentication framework (simpler authentication framework)
[turn]: OSGi specification in simple terms