CodeForces 387C George and Number

华为ITR流程实战指南:从设计到落地的全流程解析(附完整方案下载) 本文深度解析华为ITR流程从设计到落地的全流程实战指南。ITR不仅是高效处理客户问题的“救火”系统,更是驱动产品改进、预防问题的企业“免疫系统”。文章详细拆解了流程设计的四步走策略、三层技术支持体系的组织保障、以闭环改进为核心的考核激励,并探讨了如何借鉴其精髓,优化自身问题管理,实现从被动响应到主动服务的跨越。 阅读详情

题目链接:http://codeforces.com/problemset/problem/387/C


George and Number

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

George is a cat, so he really likes to play. Most of all he likes to play with his array of positive integers b. During the game, George modifies the array by using special changes. Let's mark George's current array as b1, b2, ..., b|b| (record |b| denotes the current length of the array). Then one change is a sequence of actions:

  • Choose two distinct indexes i and j (1 ≤ i, j ≤ |b|; i ≠ j), such that bi ≥ bj.
  • Get number v = concat(bi, bj), where concat(x, y) is a number obtained by adding number y to the end of the decimal record of number x. For example, concat(500, 10) = 50010, concat(2, 2) = 22.
  • Add number v to the end of the array. The length of the array will increase by one.
  • Remove from the array numbers with indexes i and j. The length of the array will decrease by two, and elements of the array will become re-numbered from 1 to current length of the array.

George played for a long time with his array b and received from array b an array consisting of exactly one number p. Now George wants to know: what is the maximum number of elements array b could contain originally? Help him find this number. Note that originally the array could contain only positive integers.

Input

The first line of the input contains a single integer p (1 ≤ p < 10100000). It is guaranteed that number p doesn't contain any leading zeroes.

Output

Print an integer — the maximum number of elements array b could contain originally.

Examples
Input
9555
Output
4
Input
10000000005
Output
2
Input
800101
Output
3
Input
45
Output
1
Input
1000000000000001223300003342220044555
Output
17
Input
19992000
Output
1
Input
310200
Output
2
Note

Let's consider the test examples:

  • Originally array b can be equal to {5, 9, 5, 5}. The sequence of George's changes could have been: {5, 9, 5, 5} → {5, 5, 95} → {95, 55} → {9555}.
  • Originally array b could be equal to {1000000000, 5}. Please note that the array b cannot contain zeros.
  • Originally array b could be equal to {800, 10, 1}.
  • Originally array b could be equal to {45}. It cannot be equal to {4, 5}, because George can get only array {54} from this array in one operation.

Note that the numbers can be very large.


题意:有一个游戏规则是这样的:给定一个正整数数组,从数组中选取两个数,将大的放在前面,小的放在后面,然后拼接在一起组成一个数,取代

这两个数放在数组中。如果用同一个数组玩很多次时,最后得到仅仅只有一个数组。问:给你最后那一个数,那么它的原来数组最大元素数目为多大?

给出的数p满足1<=p<10100000.注意的是,原数组只含有正整数。


解法:这是一道贪心。贪心策略是怎样?既然要使得最后元素个数最大,那么我们可以从后面开始将串分成两个部分的子串,该子串满足:

                                                       1.前面的串表示的数大于等于该串表示的数;

                                                       2.该串表示的数要尽量小。找到之后计数一次,接着将前面的串当成新的串继续找,直至不能够找到为止。

                                                          这样求出的解一定是最优的。


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
string str;
bool compare(int L1,int R1,int L2, int R2)
{
    int len1=R1-L1+1,len2=R2-L2+1;
    if(len1>len2) return true;
    else if(len1<len2) return false;
    else{
        int i;
        for(i=0;i<len1;i++){
            if(str[i+L1]>str[i+L2]) return true;
            else if(str[i+L1]<str[i+L2]) return false;
        }
        if(i==len1) return true;
    }
}
int main()
{
    while(cin>>str){
       int y=str.size()-2,r=str.size()-1,ans=1;
       while(y>=0)
       {
          while(y>=0 && str[y+1]=='0') y--;
          if(compare(0,y,y+1,r))
          {
             ans++;
             r=y;
             y--;
          }
          else break;
       }
       cout << ans << endl;
    }
    return 0;
}




Python实战:从中国气象局天擎平台自动化获取与处理雷达基数据 本文详细介绍了如何利用Python脚本实现从中国气象局天擎平台自动化获取与处理雷达基数据。通过环境搭建、安全认证、核心代码编写及工程化优化,构建了一个包含自动查询、批量下载、错误重试和格式转换的完整数据管道,旨在帮助气象水文领域的研究者与数据分析师从繁琐的手动操作中解放出来,高效管理海量数据。 阅读详情

相关推荐

开源Agent Skill让AI画图不再翻车:从数据到专业图表全流程

在人工智能与数据可视化交叉领域,让模型直接生成图表往往伴随字体乱码、坐标轴密集、配色失调等高频问题。Agent Skill作为一种可复用的能力封装机制,将专业绘图流程固化为标准化操作手册,从数据特征识别、图表类型决策到代码生成与渲染校验形成完整闭环。它不再依赖临时提示词的一次性发挥,而是让AI按领域专家的思维执行任务,显著提升出图质量与稳定性。这种能力在数据分析报告、运营日报、论文插图等场景具有广泛实用价值,尤其适用于需要快速产出规范化图表的工作流。本文即从这一技术范式出发,介绍一个GitHub上获得2.5

weixin_33851429的博客 942

Codeforces 278C Learning Languages(并查集)

题意抽象出来就是求联通块的个数吧,然后添加最少边使图联通。 注意所有人都不会任何语言的时候,答案是n而不是n-1。 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define FF(i

diary_yang的专栏 1613

NRF24L01模块的5个常见问题及解决方案:从信号干扰到功耗优化

本文深入探讨NRF24L01无线模块在STM32开发中的5大常见问题及解决方案,包括通信距离优化、数据丢失排查、电源噪声抑制、SPI通信故障处理以及低功耗设计。通过代码示例和电路图分析,提供实用的优化策略,帮助开发者提升无线通信的稳定性和效率。

weixin_28256233的博客 226

Codeforces 387C George and Number(贪心)

题目链接:Codeforces 387C George and Number 题目大意:给定一个数,要求找到一个集合,通过题目给定的变换方式可以得到给定得数,输出集合元素个数的最大值。变换方式为每次从集合中取出任意两个数,连接成一个新的数,要求两个数中较大的数必须放在前面;然后连接成的新的数放回集合中,重复上述操作,直到只剩一个数。(元素不可以是0) 解题思路:揣摩题意揣了很久

不慌不忙、不急不躁 2408

CAN通信:EB中配置CAN驱动,配置参数解析

以S32K314芯片说明,其他芯片不同,参数配置也有差异。

zhangxiaio1的博客 2167

Part03 数据结构

本文介绍了CSP-S初赛中常见的高级数据结构及其实现,包括: 线性结构:双端栈、双端队列、单调队列、优先队列和ST表,重点分析了它们的特点、时间复杂度及典型应用场景。 集合与森林:并查集(带路径压缩和按秩合并)和树的孩子兄弟表示法,展示了多叉树转化为二叉树存储的方法。 特殊树结构:包括二叉堆、树状数组、线段树和字典树,详细说明了它们的构建、查询和更新操作,特别强调了线段树的递归实现和字典树的前缀匹配特性。 每种数据结构都配有核心C++代码实现,涉及数组模拟、动态规划和树形结构等编程技巧,适合算法竞赛选手快速

weixin_43863957的博客 1179

【CodeForces - 387C】George and Number(思维)

题意: 乔治喜欢对他的数列b进行操作。 我们将乔治的数列表示成b1, b2, ..., b|b|(其中|b|表示数列b的长度)。一次操作分为以下几个步骤: 选择两个不同的数i和j(1 ≤ i, j ≤ |b|;i ≠ j),满足bi ≥ bj. 定义数v = concat(bi, bj),其中concat(x, y)是将数y连接在数x后面形成的新数。举...

__似水流年__的博客 243

【Unity学习笔记】事件系统EventSystem

1.EventSystem物体 第一次在Unity中创建UI元素时,总会自动生成一个EventSystem物体,它包含三个组件:Transform、EventSystem、Standalone Input Module。如果我们把它删除了,会发现UI上的事件(比如点击、拖拽)将不会被检测到。没错,它就是用来处理UI相关的事件的。 1.1 EventSystem组件 EventSystem基于输入给物体发送事件,它在整个事件系统中扮演的主要角色是: 1.管理被选中的物体 2.管理正在使用的Input Modu

一白梦人的博客 1万+

George and Number CodeForces - 387C

George and Number CodeForces - 387C题目描述 George is a cat, so he really likes to play. Most of all he likes to play with his array of positive integers b. During the game, George modifies the array by u

退役的铜牌狗 559

无人机航拍图像匹配——SIFT算法实践(含代码)

无人机航拍图像匹配——SIFT算法实践(含代码)

zhangzhao147的博客 6393

XDMA 驱动安装与性能测试全流程解析

本文详细解析了XDMA驱动的完整安装与性能测试流程。从环境准备、源码获取、编译安装到驱动加载与设备验证,逐步指导用户打通FPGA加速卡与主机间的高速数据通道。重点介绍了如何通过官方测试脚本进行功能验证与带宽性能测试,帮助用户评估XDMA驱动的实际传输效能,为AI推理、高频交易等低延迟高带宽应用奠定基础。

weixin_29216049的博客 524

CodeForces 387 C. George and Number[贪心]

题目链接:点击打开链接 题目意思:

1015

基于咸鱼最新九宫格图标验证码的语义增强模型识别

本文探讨了破解复杂验证码的技术思路,重点分析了某平台的九宫格验证码应对策略。作者提出通过图像语义抽取和增强技术来扩充数据集:先采集少量真实样本,利用形态学操作进行前增强生成变形图像,再通过叠加背景噪声进行后增强。同时强调真实数据集的重要性,建议采用真实+生成数据的混合训练方法。实验表明该方法可使模型准确率达到95%以上,但作者特别声明本文仅供技术研究,严禁用于非法用途。

码王吴彦祖的博客 601

Codeforces 387C George and Number

题意: 给你一串数字,问你如何划分这些数字,使其按严格递减顺序,划分完后的数字个数最多是多少个。 思路: 由于不能有前导0,所以我们先把所有的数字单独划分出来。然后从头开始,枚举每一个数,并维护Max,若该数小于Max,则该数可以独立,ans++,并合并到Max中(由于题目所给的操作是允许不同数合并后成为新数去比较的),否则该数要和之前所有的数都合并,ans=1。注意:由于所给数字太大,得用

w446506278的博客 403

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Codeforces 387C George and Number 暴力

题目大意: 就是给处一个长度不超过10^5的十进制正整数, 是按照题目所给的方法从一个数组中拼出来的 为初始的那个数组最多有多少个元素 大致思路: 就是一个很简单的暴力枚举, 每次后面截下的一段数尽量小即可 代码如下: Result  :  Accepted     Memory  :  100 KB     Time  :  31 ms /* * Author:

Gatevin的专栏 907

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

Codeforces 387C George and Number 贪心

题目大意:给你一个数,问最多可以把这个数分成几个数,shi'de

e的专栏 826

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

Codeforces 387C George and Number【思维】

C. George and Number time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output George is a cat, so he really likes to

mengxiang000000 446

codeforces 387C George and Number

直接从后面往前面扫,如果前面大,就把后面丢掉 再把前面剩下的进行类似的处理就行; #include<cstdio> #include<iostream> #include<cstring> #define maxn 100005 using namespace std; char s[maxn]; int main() { ...

weixin_30345055的博客 74

codeforces 387C George and Number(贪心)

题目链接 George and Number time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output George is a cat, so he really likes to pla

madaidao的专栏 493

CodeForces387C C - George and Number 贪心+递归

George is a cat, so he really likes to play. Most of all he likes to play with his array of positive integers b. During the game, George modifies the array by using special changes. Let's mark George'

你那么爱笑,家里人知道吗? 651

Codeforces Round #227 (Div. 2) / 387C George and Number (贪心)

http://codeforces.com/contest/387/problem/C /*31ms,100KB*/ #include char str[100005]; int main() { gets(str); int i, j, res = 0; for (i = 0; str[i]; i = j) { for (j = i + 1; str[j] == '0

AC,∑ndless 1339

贪心-Code forces -387B -George and Round

大意:乔治要为比赛命题,共n道,每道题的复杂度给出。他自己已经准备好了m道题,复杂度也给出。若命题的复杂度不低于要求的复杂度,则认为此题合格。 问:乔治尽可能多的用自己的题,那么他最少还得出几道新题? 分析:尽量多用已有的题,就要求对自己的题按复杂度由低到高排序,从头到尾遍历,若能用则用(贪心)。对要求的题也排序是为了便于比较。

yichudu 1893

codeforces-387B. George and Round

codeforces-387B. George and Round 题意: 某人G准备了m个题目,难度分别为b1,b2,b3,,,,,bm 他需要使用n个题目,要求难度分别为 a1,a2,a3,an 他有“特异功能”,可以使任意一个题目减低任意难度 给出n,m 【a】【b】 问:使用他准备的题目,同时使用“特异功能”,他还要再准备多少题目 题意抽象: 1、我们尽量

花花的笔记 1275
上一篇: Codeforces 278C. Learning Languages
下一篇: HDU1253:胜利大逃亡(BFS)
hellohelloC
博客等级 码龄12年 15粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值