Vasya and Golden Ticket CodeForces - 1030C
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的更多相关文章
- 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 ...
- CodeForces 1058C C. Vasya and Golden Ticket
C. Vasya and Golden Ticket time limit per test1 second memory limit per test256 megabytes inputstand ...
- 【codeforces1058】Vasya and Golden Ticket 枚举+暴力+模拟
#点击传送 题目描述 Recently Vasya found a golden ticket - a sequence which consists of nn digits a1a2-ana1a2 ...
- cf#512 C. Vasya and Golden Ticket
题目链接 http://codeforces.com/contest/1058/problem/C 这题还是暴力最方便,和的情况最多有n*a[i] 900种把每种都试一遍 #include<b ...
- Vasya and a Tree CodeForces - 1076E(线段树+dfs)
I - Vasya and a Tree CodeForces - 1076E 其实参考完别人的思路,写完程序交上去,还是没理解啥意思..昨晚再仔细想了想.终于弄明白了(有可能不对 题意是有一棵树n个 ...
- Vasya and Beautiful Arrays CodeForces - 354C (数论,枚举)
Vasya and Beautiful Arrays CodeForces - 354C Vasya's got a birthday coming up and his mom decided to ...
- CodeForces - 837E - Vasya's Function | Educational Codeforces Round 26
/* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f( ...
- Vasya And Password(CodeForces - 1051A)
Vasya came up with a password to register for EatForces — a string ss. The password in EatForces sho ...
- 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 ...
- 黄金票据(Golden Ticket)的原理与实践
0.黄金票据是什么? 在与认证过程中,经过client与AS的通信会得到TGT,带着TGT想TGS请求,得到票据ticket,用这个ticket可以来访问应用服务器.如果这段有什么疑问,欢迎参考Ker ...
随机推荐
- 会用 AI 的工程师,效率已经拉开差距了 - “ 我们曾经引以为傲的编码能力,正在被改写。”
最近尝试用Cursor做了几个内部业务系统,发现一个越来越明显的趋势 真正会用 AI 的工程师,效率已经拉开差距了. 做了十几年 Java, 这波 AI 编程浪潮来得快,一开始我也没太当回事,以为这波 ...
- 解决Mac IntellIJ Idea 卡顿问题,修改内存大小
我们在工作中,经常会遇到因为IntellIJ Idea内存不足而卡顿的问题,可以通过两种方法调整idea的内存大小.我的IDEA版本是2021.2. 第一种调整内存的方法是 Change Me ...
- java等比压缩图片工具类
工具类 package com.chinaums.abp.util; import javax.imageio.ImageIO; import java.awt.*; import java.awt. ...
- 【ASP.NET Core】调用 Web API 备份数据库
老周不经意间翻了一下博客列表,上一篇水文竟然在 一个月前.啊,大海啊,全是水:时间啊,你跑得真快!过了一个月老周竟没感觉出来,可是这一个月里,好像啥事也没干成,就改了一下几个旧项目.也许是现在大环境真 ...
- 《Nginx核心技术》第01章:安装Nginx
作者:冰河 星球:http://m6z.cn/6aeFbs 博客:https://binghe.gitcode.host 文章汇总:https://binghe.gitcode.host/md/all ...
- 基于TCP实现简单的聊天室
原文出处:<Go 语言编程之旅>第四章4.1节 基于TCP的聊天室 1.服务端 新用户到来,生成一个User的实例,代表该用户. type User struct{ ID int // 用 ...
- 关于学习率-----linearLR
1. lr_scheduler综述 torch.optim.lr_scheduler模块提供了一些根据epoch训练次数来调整学习率(learning rate)的方法.一般情况下我们会设置随着epo ...
- Nginx 配置(Config)中遇到的错误(Error)
原文:https://ichochy.com/posts/software/20231125.html nginx location 正则错误写法 location 错误的写法 匹配请求目录地址 /5 ...
- Java反射与自定义注解实战指南
Java反射与自定义注解实战指南 第一部分:Java反射核心机制 一.反射的本质与价值 反射是Java在运行时动态获取类信息并操作类的能力,它是框架设计的基石.通过反射,我们可以在运行时: 获取类的完 ...
- MKL普通矩阵运算示例及函数封装
本示例将介绍MKL中的矩阵乘法和求逆,使用MKL进行此类大型矩阵运算可大量节省计算时间和空间,但由于MKL中的原生API接口繁杂,因此将常用函数封装,便于后续使用,最后在实际例子中调用接口执行想要的矩 ...