当前位置:网站首页>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;
}边栏推荐
- PMP考生,请查收7月PMP考试注意事项
- 十年不用一次的JVM调用
- Use of snippets in vscode (code template)
- How can the Solon framework easily obtain the response time of each request?
- Unity card flipping effect
- Haut OJ 1347: addition of choice -- high progress addition
- Do a small pressure test with JMeter tool
- MySQL数据库(一)
- [sum of two numbers] 169 sum of two numbers II - enter an ordered array
- cocos_ Lua listview loads too much data
猜你喜欢
![[depth first search] 695 Maximum area of the island](/img/08/cfff4aec667216e4f146205a12c13f.jpg)
[depth first search] 695 Maximum area of the island

Count sort

Simple modal box

Embedded database development programming (VI) -- C API

A new micro ORM open source framework

一个新的微型ORM开源框架

Shell Sort
![[转]MySQL操作实战(一):关键字 & 函数](/img/b1/8b843014f365b786e310718f669043.png)
[转]MySQL操作实战(一):关键字 & 函数
![[转]MySQL操作实战(三):表联结](/img/70/20bf9b379ce58761bae9955982a158.png)
[转]MySQL操作实战(三):表联结

Applet Live + e - commerce, si vous voulez être un nouveau e - commerce de détail, utilisez - le!
随机推荐
Listview pull-down loading function
Improvement of pointnet++
2022 / 7 / 1 Résumé de l'étude
C语言杂谈1
Cocos2dx Lua registers the touch event and detects whether the click coordinates are within the specified area
Solon Auth 认证框架使用演示(更简单的认证框架)
软件测试 -- 0 序
Lua wechat avatar URL
[paper notes] multi goal reinforcement learning: challenging robotics environments and request for research
JVM call not used once in ten years
使用命令符关闭笔记本自带键盘命令
【论文笔记】Multi-Goal Reinforcement Learning: Challenging Robotics Environments and Request for Research
SAP-修改系统表数据的方法
2022/7/1 learning summary
Do a small pressure test with JMeter tool
[转]MySQL操作实战(三):表联结
Reverse one-way linked list of interview questions
Shell Sort
利用HashMap实现简单缓存
Ue4/ue5 illusory engine, material part (III), material optimization at different distances