https://vjudge.net/contest/356807#problem/A

题意:

  给一段数字,问是否能拆分成若干段,使得各段的数字和相等

思路:

  暴力 搜索

  串的长度最大100,单个段数字和最大为100 * 9 = 900,以单个段数字和为线索进行搜索

  对每个单段长度 i ∈(1 , 900),尝试分段,能分尽即为有解

  时间复杂度O(N),N为最小的单段数字和

  最坏情况下进行900 * 100 = 90000次判断

代码:

 1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<algorithm>
5 #include<bitset>
6 #include<cassert>
7 #include<cctype>
8 #include<cmath>
9 #include<cstdlib>
10 #include<ctime>
11 #include<deque>
12 #include<iomanip>
13 #include<list>
14 #include<map>
15 #include<queue>
16 #include<set>
17 #include<stack>
18 #include<vector>
19 #include <vector>
20 #include <iterator>
21 #include <utility>
22 #include <sstream>
23 #include <limits>
24 #include <numeric>
25 #include <functional>
26 using namespace std;
27 #define gc getchar()
28 #define mem(a) memset(a,0,sizeof(a))
29 //#define sort(a,n,int) sort(a,a+n,less<int>())
30
31 #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
32
33 typedef long long ll;
34 typedef unsigned long long ull;
35 typedef long double ld;
36 typedef pair<int,int> pii;
37 typedef char ch;
38 typedef double db;
39
40 const double PI=acos(-1.0);
41 const double eps=1e-6;
42 const ll mod=1e9+7;
43 const int inf=0x3f3f3f3f;
44 const int maxn=1e5+10;
45 const int maxm=100+10;
46
47 char c[100] = {0};
48 int num[100] = {0};
49 int main()
50 {
51 int length = 0;
52 cin >> length;
53 cin >> c;
54 for(int i = 0;i<length;i++)
55 {
56 num[i]=c[i]-'0';
57 //cout << num[i];
58 }
59 bool flag = 0;
60 for(int i = 0;i<=900;i++)
61 {
62 int sum = 0 , counter = 0;
63 for (int j = 0;j<length;j++)
64 {
65 sum += num[j];
66 if(sum == i)
67 {
68 sum = 0;
69 counter++;
70 }
71 else if(sum>i) break;
72 }
73 if (sum == 0 && counter > 1)
74 {
75 flag = 1;
76 //cout<<"!"<<endl;
77 }
78 }
79 if(flag)
80 {
81 cout << "YES" << endl;
82 }
83 else
84 {
85 cout << "NO" << endl;
86 }
87 return 0;
88 }

Vasya and Golden Ticket CodeForces - 1030C的更多相关文章

  1. Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) C. Vasya and Golden Ticket 【。。。】

    任意门:http://codeforces.com/contest/1058/problem/C C. Vasya and Golden Ticket time limit per test 1 se ...

  2. CodeForces 1058C C. Vasya and Golden Ticket

    C. Vasya and Golden Ticket time limit per test1 second memory limit per test256 megabytes inputstand ...

  3. 【codeforces1058】Vasya and Golden Ticket 枚举+暴力+模拟

    #点击传送 题目描述 Recently Vasya found a golden ticket - a sequence which consists of nn digits a1a2-ana1a2 ...

  4. cf#512 C. Vasya and Golden Ticket

    题目链接 http://codeforces.com/contest/1058/problem/C 这题还是暴力最方便,和的情况最多有n*a[i]  900种把每种都试一遍 #include<b ...

  5. Vasya and a Tree CodeForces - 1076E(线段树+dfs)

    I - Vasya and a Tree CodeForces - 1076E 其实参考完别人的思路,写完程序交上去,还是没理解啥意思..昨晚再仔细想了想.终于弄明白了(有可能不对 题意是有一棵树n个 ...

  6. Vasya and Beautiful Arrays CodeForces - 354C (数论,枚举)

    Vasya and Beautiful Arrays CodeForces - 354C Vasya's got a birthday coming up and his mom decided to ...

  7. CodeForces - 837E - Vasya's Function | Educational Codeforces Round 26

    /* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f( ...

  8. Vasya And Password(CodeForces - 1051A)

    Vasya came up with a password to register for EatForces — a string ss. The password in EatForces sho ...

  9. The Golden Age CodeForces - 813B (数学+枚举)

    Unlucky year in Berland is such a year that its number n can be represented as n = xa + yb, where a  ...

  10. 黄金票据(Golden Ticket)的原理与实践

    0.黄金票据是什么? 在与认证过程中,经过client与AS的通信会得到TGT,带着TGT想TGS请求,得到票据ticket,用这个ticket可以来访问应用服务器.如果这段有什么疑问,欢迎参考Ker ...

随机推荐

  1. BS直聘职位数据采集与分析(爬虫)

    一.项目介绍 在当今竞争激烈的就业市场中,及时掌握职位信息和市场动态变得尤为重要.本文将详细介绍如何使用Python开发一个爬虫项目,自动采集BOSS直聘网站的职位数据,并对数据进行处理和分析. 1. ...

  2. Java 压缩成zip文件

    综述 在< 把多个文件打包压缩成tar.gz文件并解压的Java实现>中介绍了如何把文件压缩车gz文件,这里介绍如何把文件压缩成zip文件.支持如下方式的压缩: 压缩单个文件 压缩文件夹下 ...

  3. 2025 年实用、全面的 VS Code 插件推荐!

    前言 VS Code是一款由微软开源免费.轻量级.功能强大的源代码编辑器.其轻量级体现在基础安装简洁,仅含核心编辑功能.功能强大则源于它支持丰富的语言环境插件拓展,这种模块化设计让VS Code在源代 ...

  4. 万字长文彻底剖析Python正则表达式

    正则表达式在各种语言中都是一个复杂的主题,在Python中,正则表达式设计的尤其复杂以适应不同场景下的脚本. python官方文档提供了正则表达式使用中的各种细节: <正则表达式指南> & ...

  5. .NET 8 gRPC 实现高效100G大文件断点续传工具

    前言 随着数字化和信息化的发展,大文件传输在企业.科研以及个人用户中变得越来越常见.传统的文件传输方式在面对大文件(如几十GB甚至上百GB的视频.工程数据)时,常常因网络不稳定.程序崩溃等原因导致传输 ...

  6. CAE和CAD的区别

    CAE又被叫做"计算机辅助工程",而CAD则是"计算机辅助设计".虽然CAE和CAD是两种不同的技术,但它们却有着一定联系.在如今这个遍布科技与狠活的社会里,C ...

  7. Let’s Encrypt申请证书

    前提 安装好ngixn,并配置解析好你的域名,仅仅留下证书配置处不填写即可. 安装certbot certbot 官方推荐的自动化脚本, 用来申请免费SSL证书的. (certbot中文翻译是 证书机 ...

  8. 前端开发系列024-基础篇之Canvas绘图(基础)

    本文将对Canvas绘图技术进行简单介绍,主要包括Canvas标签.CanvasRenderingContext2D对象核心API的使用以及复杂图形的绘制等内容. 一.Canvas简单介绍 基本信息 ...

  9. GDB转载 调试 linux

    GDB调试工具总结 ==== 144 作者 Manfred_Zone 2016.04.12 15:19* 字数 7616 阅读 636评论 0喜欢 4 <Linux C编程一站式学习> h ...

  10. IPC 共享信号量 共享内存的创建失败的原因分析 LINUX 网络编程第二版

    linux 网络编程书 对于 semid = semget(key,1,IPC_CREAT|0666); /获得信号量的ID/ 写错了 书里面写的是0 ,这个参数的意义代表的是,信号量的数量. 有点烦 ...