CodeForces 387C George and Number

一文带你看懂SAP-HANA的基本架构与原理 创作不易,希望大家一键三连支持!!!♥♥♥创作不易,希望大家一键三连支持!!!♥♥♥创作不易,希望大家一键三连支持!!!♥♥♥。 阅读详情

题目链接: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;
}




沙猫群优化算法(SCSO)详解:从沙漠生存智慧到全局优化引擎 本文详细介绍了沙猫群优化算法(SCSO),这是一种新型元启发式优化算法,灵感来源于沙猫在沙漠环境中的卓越狩猎行为。SCSO通过模拟沙猫的低频探测能力和精确攻击策略,将优化问题转化为搜索和捕获"猎物"的过程。算法核心包括探索阶段(全局搜索)和开发阶段(局部精细搜索),通过灵敏度范围模型和自适应控制参数实现两者的平衡。SCSO具有参数简单、收敛性能好等优点,适用于解决复杂全局优化问题。 阅读详情

相关推荐

thinkcmf 代码执行 (CVE-2019-7580) 漏洞复现

所有文章,仅供安全研究与学习之用,后果自负! thinkcmf 代码执行 CVE-2019-7580thinkcmf 代码执行 (CVE-2019-7580)0x01 漏洞描述0x02 影响范围0x03 漏洞复现3.1 登录后台3.2 漏洞利用3.2.1webshell3.2 phpinfo3.3 获取系统命令0x04 漏洞修复 thinkcmf 代码执行 (CVE-2019-7580) 复现小心会搞崩环境。 0x01 漏洞描述 ThinkCMF是一款支持Swoole的开源内容管理框架(CMF),基于Thi

YouthBelief的博客 4263

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

ComfyUI破限版全中文AI绘画环境搭建与工作流实战指南

节点式工作流是AI绘画领域的核心技术架构,通过将图像生成过程拆分为可配置的模块化节点,实现了对Stable Diffusion模型的精细化控制。其技术原理基于数据流编程范式,每个节点负责特定功能处理,如文本编码、采样器配置和VAE解码等。这种设计在工程实践中的核心价值在于提供了可追溯、可复用的可视化工作流,特别适合需要参数调优和批量生产的商业场景。ComfyUI作为典型的节点式AI绘画工具,在破限版中针对中文用户优化了界面支持和显卡兼容性,显著降低了技术门槛。在实际应用中,结合ControlNet和LoRA

weixin_29038155的博客 447

Codeforces 387C George and Number(贪心)

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

不慌不忙、不急不躁 2408

HT7036计量芯片SPI通信与数据读取实战解析

本文详细解析HT7036计量芯片的SPI通信与数据读取实战,涵盖SPI时序配置、命令发送、数据读取及常见问题排查。重点介绍如何通过SPI接口与MCU通信,实现电能数据的稳定采集与处理,为智能电表等应用提供实用解决方案。

vscode5coder的博客 264

apollo-减速带通行

主车在通过减速带时速度不超过3m/s

是菜鸟o的博客 389

【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

④ Django创建用户中心应用users,扩展用户信息

本章配套视频教程 Django创建用户中心应用users,扩展用户数据 在settings.py文件中配置项目 1、语言配置:LANGUAGE_CODE = 'zh-hans’ 2、时区配置:TIME_ZONE = 'Asia\Shanghai’ 3、模板路径配置:‘DIRS’: [os.path.join(BASE_DIR, ‘templates’)], 并创建templates文件

轻编程的博客 671

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

Linux系统中u-boot启动流程分析(详解)

代码部分,具体如下;

嵌入式技术开发 1991

1-Spring Security OAuth2专栏介绍

我自己 我是码农小胖哥,一名后端软件工程师,有多年的后端开发经验,同时也是一名热衷于技术分享、拥抱开源的技术博主。我的技术栈主要是Java、Python、Kotlin,欢迎各位同行进行交流和分享。 个人技术公众号:码农小胖哥 个人博客:https://felord.cn Gitee: https://gitee.com/felord 你可以通过以上方式和我交流、解决学习中的疑难杂症。 2021年开源Spring Security 干货系列教程,2022年又开源Spring Security进阶版,帮

码农小胖哥 7935

CodeForces 387 C. George and Number[贪心]

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

1015

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

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破解工具

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

Codeforces 387C George and Number 暴力

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

Gatevin的专栏 907

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Codeforces 387C George and Number 贪心

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

e的专栏 826

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、付费专栏及课程。

余额充值