problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
acwing::acwing4301类 参考

AcWing 4301. 截断数列 更多...

#include <acwing.h>

静态 Public 成员函数

static int main (istream &cin, ostream &cout)
 

详细描述

AcWing 4301. 截断数列

在文件 acwing.h1195 行定义.

成员函数说明

◆ main()

int acwing::acwing4301::main ( istream &  cin,
ostream &  cout 
)
static

在文件 acwing.cpp3850 行定义.

3850 {
3851 int n;
3852 cin >> n;
3853 auto vec = vector<int>();
3854 auto targets = unordered_set<int>();
3855 int sum = 0;
3856 int maximum = 0;
3857 char ch;
3858 vec.resize(n);
3859 for(int i = 0; i < n; i++) {
3860 cin >> ch;
3861 int a = ch - '0';
3862 vec[i] = a;
3863 sum += a;
3864 maximum = max(maximum, a);
3865 }
3866 if(sum == 0) {
3867 cout << "YES";
3868 return 0;
3869 }
3870 for(int i = maximum; i <= sum / 2; i++) {
3871 if(sum % i == 0) {
3872 targets.insert(i);
3873 }
3874 }
3875 for(const auto target: targets) {
3876 int current = 0;
3877 bool ok = true;
3878 for(int i = 0; i < n; i++) {
3879 current += vec[i];
3880 if(current == target) {
3881 current = 0;
3882 } else if(current > target) {
3883 ok = false;
3884 break;
3885 }
3886 }
3887 if(ok && current == 0) {
3888 cout << "YES";
3889 return 0;
3890 }
3891 }
3892 cout << "NO";
3893 return 0;
3894 }
int vec[100010]
Definition: pat.cpp:5095

被这些函数引用 acwing::TEST().


该类的文档由以下文件生成: