2017武汉大学校赛网络预选赛c题

Seven Segment Display(数位dp) A seven segment display, or seven segment indicator, is a form of electronic display device for displaying decimal numerals that is an alternative to the more complex dot matrix displays. Seven segment 阅读详情

无解时输出-1s而不是WTF

数据可能有前导零

Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 512 mebibytes
A positive integer number n is written on a blackboard. It consists of not more than 10^510
​5
​​ digits. You have to transform it into a mogicalnumber by erasing some of the digits, and you want to erase as few digits as possible.

The number is lucky if it consists of at least one digit, doesn’t have leading zeroes and is a multiple of 6. For example, 0, 66,66666 are lucky numbers, and 00, 25, 77 are not.

Write a program which for the given nn will find a mogical number such that nn can be transformed into this number by erasing as few digits as possible. You can erase an arbitraty set of digits. For example, they don’t have to go one after another in the number nn.

Print the length of your answer after the erasing.

If it’s impossible to obtain a lucky number, print -1s.

Input
The first line of input contains nn – a positive integer ( 1\le n \le 10^{100000} 1≤n≤10
​100000
​​ ).

Output
Print one number — the number of your lucky number obtained by erasing as few as possible digits. If there is no answer, print -1s.

Example
Input 1
0010456
Output 1
4
Input 2
11
Output 2
-1s

题意:给你一个非常大的数,让你删除最小个数的数,使之成为一个不含前导零的数,并且这个数可以整除6。最后输出这个数的长度,如果不存在,输出-1s。

解题思路:数位dp,令dp[i][j] 为前i个数字,%6为j的最大长度。然后考虑每个数字,如果把这个数字加进去,长度加一,但是前面的值要乘以10,所有产生新的余数所以状态转移方程为dp[i][(j*10 + s[i])%6] = max(dp[i][(j*10 + s[i])%6],dp[i - 1][j] + 1),如果不加进去状态转移方程为dp[i][j] = max(dp[i - 1][j],dp[i][j])。

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int s[maxn];
char ch[maxn];
int dp[maxn][30];
int main()
{
    memset(dp,0,sizeof(dp));
    scanf("%s",ch);
    int len1 = strlen(ch);
    int loc = -1;
    for(int i = 0; i < len1; i++)
    {
        if(ch[i] == '0') continue;
        else
        {
           loc = i;
           break;
        }
    }
    if(loc == -1) printf("-1s\n");
    else
    {
        int len2 = 0;
        bool flag = false;
        for(int i = 1,j = loc; j < len1; j++,i++)
        {
            s[i] = ch[j] - '0';
            len2++;
            if(s[i] == 0) flag = true;
        }
        dp[1][s[1]%6] = 1;
        for(int i = 2; i <= len2; i++)
        {
            if(s[i] != 0) dp[i][s[i]%6] = 1;
            for(int j = 0; j <= 5; j++)
            {
                dp[i][j] = max(dp[i][j],dp[i - 1][j]);
                if(dp[i - 1][j] != 0)
                dp[i][((10*j) + s[i])%6] = max(dp[i][((10*j) + s[i])%6],dp[i - 1][j] + 1);

            }
        }
        if(dp[len2][0] == 0)
        {
            if(flag) printf("1\n");
            else printf("-1s\n");
        }
        else
        printf("%d\n",dp[len2][0]);
    }
    return 0;
}
HDU6155(dp + 线段树区间更新 + 矩阵性质) Subsequence Count Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others) Total Submission(s): 304    Accepted Submission(s): 126 Problem Description Given a 阅读详情

相关推荐

Ubuntu登录界面黑屏?手把手教你排查和修复lightdm启动失败(附debug命令详解)

本文详细介绍了Ubuntu登录界面黑屏问题的排查与修复方法,重点解决lightdm启动失败问题。通过提供紧急应对措施、深度诊断命令和五大常见故障点的修复方案,帮助用户快速恢复图形界面。文章还包含高级修复技巧和预防措施,确保系统稳定运行。

weixin_33067503的博客 269

POJ 3252(数位dp,前导0)

这题的约束就是一个数的二进制中0的数量要不能少于1的数量,通过上一题,这题状态就很简单了,dp[pos][num],到当前数位pos,0的数量减去1的数量为num的方案数,一个简单的问题,中间某个pos位上num可能为负数(这不一定是非法的,因为我还没枚举完嘛,只要最终的num>=0才能判合法,中途某个pos就不一定了),这里比较好处理,Hash嘛,最小就-32吧(好像),直接加上32,把32当0

mosquito_zm的博客 884

MIT液态神经网络(LNN)深度研究:原理、应用与未来

液态神经网络(Liquid Neural Networks, LNNs)代表了人工智能领域,特别是神经网络架构设计中的一次范式转移。它从根本上挑战了传统深度学习模型依赖大规模参数和静态架构的惯例,转而寻求一种更为动态、高效且受生物神经系统启发的计算范式。LNN的核心创新在于其将神经网络的计算过程从离散的、基于时间步的更新,转变为连续的、由微分方程驱动的动态系统演化。这种转变不仅赋予了模型前所未有的适应性和鲁棒性,还使其在处理复杂的时序数据和因果推断任务时表现出色。本章节将深入剖析LNN的技术原理,从其核心的

步子哥的博客 2607

woj-Divide by Six

无解时输出-1s而不是WTF 数据可能有前导零 Input file: standard input Output file: standard output Time limit: 1 second Memory limit: 512 mebibytes A positive integer number n is written on a blackboard. It con

w571523631的博客 487

如何在多 GPU 配置上运行 Unsloth:数据并行或模型并行

当工作负载受限于内存(模型或批次无法放入单张显卡)、或受限于计算且计算与通信比率较高时(即每块 GPU 的额外计算量超过同步参数的开销,如在 DDP 中,或超过传递激活值的开销,如在模型并行中),多 GPU 配置才开始显现优势。在松散连接的显卡上(尤其是 PCIe 版本的 H100 或 A100),额外的设备间数据传输会导致性能显著低于单 GPU 运行。让我们厘清概念,明确说明如何通过模型并行(将模型拆分到多个 GPU)或数据并行(在每个 GPU 上复制模型)来跨多 GPU 运行 Unsloth。

人工智能领域专家 654

Android面试必考问题:Android性能优化最全面试题及参考答案(8万字长文)

Android 中的 OOM(Out Of Memory,内存溢出)异常是指应用程序在运行过程中,由于申请的内存空间超过了系统所能提供的最大内存限制而导致的错误。在 Android 中,内存泄漏是指应用中的某些对象在不再被使用后,仍然被其他对象持有引用,导致这些对象无法被垃圾回收器回收,从而占用内存空间,随着时间的推移可能会导致应用内存不足,甚至崩溃。在一次开发 Android 应用的过程中,我发现应用在长时间运行后会出现内存占用过高的情况,导致应用变得卡顿,甚至可能会被系统强制关闭。

大模型大数据攻城狮的专栏 2549

整除15问题 | 贪心

整除15问题 成绩 10 开启时间 2020年03月30日 星期一 07:55 折扣 0.8 折扣时间 2020年04月26日 星期日 23:55 允许迟交 否 关闭时间 2020年04月26日 星期日 23:55 给定一个只包含数字 [0..9] 的字符串,求使用字符串中的某些字符,构造一个能够被15整除的最大整数。注意,字符...

weixin_43787043的博客 1889

【科研数据获取】根据Excel表个中的企业/公司信息批量获取经纬度坐标,并进行地图可视化

批量获取企业/公司的经纬度坐标,并进行地图可视化1 需求2 实现途径3 需求逐步实现 1 需求 在做项目的时候,老板或者项目答辩时候甲方最喜欢看到的就是可视化结果,尤其是涉及到地图可视化。很多时候会遇到企业/公司的数据,想要做地图可视化,必不可少的就是要获取它们具体地址:第一种就是像查户口一样精准一下具体的城镇街道,还有一种就是经纬度信息,前一种属于文字内容往往用于管理方面,第二种数字信息多用于数据处理与分析。 2 实现途径 获取地理信息数据,自然需要使用到地图的功能,这里直接采用百度地图的拾取坐标系统,

lys_828的博客 2341

Divide by Three

A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase

z980339009的博客 539

【毕设救星】从0到1打造YOLOv8货架商品检测与可视化系统,让你的毕设脱颖而出

本文介绍了一个基于YOLOv8的货架商品检测系统毕设项目。系统采用YOLOv8模型进行商品检测,包含环境搭建、数据集准备、模型训练与验证等完整流程,并开发了可视化UI界面。项目聚焦智能零售应用场景,技术栈完整且易于实现,适合作为计算机视觉方向的毕业设计。文章详细指导了从数据标注、模型训练到界面开发的全过程,提供代码示例和实用建议,帮助学生快速完成毕设并提升答辩表现。

LXY_LOVE36的博客 106

103.在 Vue 3 中使用 OpenLayers 控制图层来显示/隐藏地图

是一个强大的开源库,可以用于构建各种地理信息系统应用。在 Vue 3 中,我们可以结合。方法,可以直接控制某个图层是否可见,而不需要删除或重新创建图层。在开始之前,确保你已经搭建了 Vue 3 项目,并安装了。本文将详细介绍如何在 Vue 3 组合式 API (,并实现按钮控制地图的显示/隐藏功能。会导致 OSM 瓦片地图无法加载。方法控制地图图层的显示与隐藏。安装完成后,即可开始编写代码。在本教程中,我们介绍了如何在。来实现地图的显示/隐藏功能。来实现交互式地图,并通过。在 WebGIS 开发中,

小彭的博客 1567

数位dp无前导零

题目链接:http:// www.lydsy.com/JudgeOnline/problem.php?id=1026 #include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #...

weixin_30507481的博客 151

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

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

Codeforces 792C Divide by Three By Assassin [模拟]

A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as

Assassin 519

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

[京东2017实习生笔试] 通过考试

时间限制C/C++语言:1000MS其它语言:3000MS 内存限制C/C++语言:65536KB其它语言:589824KB 题目描述 小明同学要参加一场考试,考试一共有n道题目,小明必须做对至少60%的题目才能通过考试。考试结束后,小明估算出每题做对的概率,p1,p2,...,pn。你能帮他算出他通过考试的概率吗? 输入 输入第一行一个数n(1<=n<=10...

weixin_30568715的博客 230

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

2017武汉大学校赛网络预选赛g题

Input file: standard input Output file: standard output Time limit: 1 second Memory limit: 512 mebibytes Everyone hates the verdict “Time Limit Exceeded” or “TLE”. However, sometimes, we can’t com

creatorx的博客 556

Educational Codeforces Round 18 C. Divide by Three

C. Divide by Three time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output A positive integer number n is written on a blackboard. It consists of n

nare123的博客 702

codeforce 792C - Divide by Three(思维)

A positive integer numbernis written on a blackboard. It consists of not more than105digits. You have to transform it into abeautifulnumber by erasing some of the digits, and you want to erase

ShiWaiGaoRen12345的博客 1131

woj~24. Divide by Six(dp)

Input file: standard input Output file: standard output Time limit: 1 second Memory limit: 512 mebibytes A positive integer number n is written on a blackboard. It consists of not more than 10^51

gyr 485

WOJ 24. Divide by Six

题目分析 一道非常好的dp题,不是很难,但是细节问题很多,比赛的时候瞎搞的,搞了半天没出来,亏我还是队里面写dp的,非常惭愧,比赛的时候一直想着能被6整除的数是一个偶数并且各个数位上的数字相加和mod3等于0,然后写了2个小时,wa了11次,好气呀!!代码上有注释,参考大神解法。 #include <cstdio> #include <cstring> #include <iostream> #

你真的介意真的在乎真的想要真的渴望的话你一定能够做到 815

woj Divide by Six 数位dp

数据可能有前导零 Input file: standard input Output file: standard output Time limit: 1 second Memory limit: 512 mebibytes A positive integer number n is written on a blackboard. It consists of

lifelike 524

2017武大校赛网络预选赛C题 Divide by Six

DIVIDE BY SIX 无解时输出-1s而不是WTF 数据可能有前导零 Input file: standard input Output file: standard output Time limit: 1 second Memory limit: 512 mebibytes A positive integer number n is written on a b

Hi_jiaxinwei的博客 549

dp处理大数整除6的最大位数Divide by Six

题意:一个小于等于100000位的数字n,(10^100000>=n>=1);在这个数字中选出一些数字(不可改变顺序)组成6的倍数,输出符合条件的最长的位数。

Accepted 684

codeforces/contest/796/problem/E

E. Exam Cheating time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Zane and Zane’s crush have just decided to date! However, the girl is hav

creatorx的博客 1010

2017icpc北京网络赛c题(最大连续子段和)

时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Once upon a time, there was a little dog YK. One day, he went to an antique shop and was impressed by a beautiful picture. YK loved it very much. H

creatorx的博客 741
上一篇: 2017武汉大学校赛网络预选赛d题
下一篇: codeforces contest/796/problem/D
creatorx
博客等级 码龄10年 127粉丝 145原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值