CodeForces 844A Diversity (超级超级水唯一需要想得就是开个标记数组吧)

告别LM2596!用LM5175打造400W自动升降压数控电源(附完整电路图与代码) 本文详细介绍了如何利用LM5175芯片设计400W自动升降压数控电源,替代传统的LM2596方案。通过四开关Buck-Boost拓扑结构,LM5175实现了高达98%的转换效率和400W大功率输出,支持无缝升降压切换。文章涵盖芯片选型、电路设计、PCB布局及STM32数控实现,为工程师提供完整的实践指南。 阅读详情
                     **A. Diversity**
          time limit per test :1 second
          memory limit per test: 256 megabytes
          input: standard input
          output: standard output

Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible.

String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.

Input
First line of input contains string s, consisting only of lowercase Latin letters (1 ≤ |s| ≤ 1000, |s| denotes the length of s).

Second line of input contains integer k (1 ≤ k ≤ 26).

Output
Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.

**

**Examples**
**input**
yandex
6
**output**
0
**input**
yahoo
5
**output**
1
**input**
google
7
**output**
impossible

**
In the first test case string contains 6 different letters, so we don’t need to change anything.

In the second test case string contains 4 different letters: {‘a’, ‘h’, ‘o’, ‘y’}. To get 5 different letters it is necessary to change one occurrence of ‘o’ to some letter, which doesn’t occur in the string, for example, {‘b’}.

In the third test case, it is impossible to make 7 different letters because the length of the string is 6.

题意
就是给你个字符串 然后给你个k代表有不重复的字符 求你要达到这个k 最少需要
思路:
求出字符串长度 如果比k小直接输出 impossible,如果比k大 那就用标记数组来找不重复的最多有多少 如果比k大就输出 0;如果比k小输出k-不重复的字符的个数


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;

int flag[2000];

int main()
{
    char s[2000];
    int k;
    cin>>s;
    memset(flag,0,sizeof(flag));  //数组初始化
    cin>>k;
    int m=strlen(s);
    if(k>m)

        {
            cout<<"impossible"<<endl;
            return 0;
        }
    int ans=0;
    for(int i=0;i<m;i++)
    {
        if(flag[s[i]]==0)  //标记数组 
        {
            flag[s[i]]=1;
            ans++;
        }
    }
    if(ans>=k)
        cout<<0<<endl;
    else
    cout<<k-ans<<endl;
    return 0;
}
怀旧版电脑GBC模拟器 再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。 立即下载

相关推荐

opencv实践项目-图片拼接之缝合线算法

opencv 图片缝合线算法

wyw0000的博客 2624

Codeforces 844A Diversity

题目链接:CF-844A 水题做多了真的是有快感的。 给一个字符串s和一个整数k,可以改变字符串s中的任意一个字母,问最少改变几次可以使得s中有k个不同字母。 无脑记录原来s中不同的字母,也可以用set做。 #define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include

Polanwind 328

深入解析国家企业征信系统瑞数6vmp算法逆向实战

本文深入解析了国家企业征信系统所采用的双层防护机制,重点聚焦于瑞数6代vmp算法的逆向实战。文章详细拆解了从加速乐521状态码的绕过,到瑞数412挑战的核心算法还原过程,提供了通过动态Hook、日志分析进行算法逆向,并用Python实现自动化请求链的完整技术方案,旨在为安全研究与技术学习提供参考。

yellow的专栏 608

codeforces 844A Diversity

点击打开链接 A. Diversity time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Calculate the minimum num

zhang__liuchen的博客 792

合并数组与非合并数组——SystemVerilog

合并型数组(packed): — 合并型数组可以实现连续的存储,赋值时不需要用 '{ }。 //合并型数组 bit [3] [7:0] b_pack // 表示3行 x 8列的数组,[3]是高维度(高维度),[7:0]是低维度(第一维) 数组中,数据排列为{b_pack[3],b_pack[2],b_pack[1],b_pack[0]},其中每个b_pack为8个bit; bit是二值逻辑,每位bit只占据1位。故24位bit只占据一个word(一般一个word为32bit)的存储空间

SummerXRT的博客 7638

别只刷题了!我用834分经验告诉你,华为HCIP大数据考试(H13-723)这样准备更高效

本文分享了华为HCIP大数据认证(H13-723)834分通关的高效备考经验。通过分析考试动态、题库验证技巧和章节优先级策略,帮助考生超越单纯刷题,系统化掌握核心知识点。特别强调实时流处理和离线批处理等重点章节,提供黄金90分钟临场发挥策略,助力考生一次性通过考试。

weixin_38168786的博客 458

codeforce_844A

Diversity Time Limit: 1000msMemory Limit: 262144KB This problem will be judged on CodeForces. Original ID: 844A 64-bit integer IO format: %I64d Java class name: (Any) Prev Submit Status Statis...

NITjianbagengmu的博客 504

语音增强评价指标全解析:从MOS到eSTOI的实战指南

本文全面解析了语音增强领域的核心评价指标,包括主观评价的黄金标准MOS,以及PESQ、STOI、eSTOI等关键客观指标。文章详细阐述了各指标的原理、适用场景与实战计算方法,并提供了Python代码示例,旨在帮助开发者和研究者建立科学的评估体系,以平衡语音可懂度与音质,从而优化算法效果。

yhn456789的博客 1198

Diversity

Calculate the minimum number of characters you need to change in the strings, so that it contains at leastkdifferent letters, or print that it is impossible. Stringsconsists only of lowercase L...

Y_yunhu的博客 309

C# 上位机内存泄漏排查指南:3 个工具 + 4 个技巧,从 GC 频繁到稳定运行 720 小时

C# 上位机内存泄漏排查的核心是「先定位泄漏存在,再追溯引用根源,最后修复验证通过「Visual Studio 诊断工具(快速定位)+ dotMemory(深度分析)+ PerfView(生产监控)」三个工具的配合,结合「复现场景、排查静态成员+事件、检查非托管资源、GC 日志验证」四个技巧,可高效解决绝大多数泄漏问题。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 735

Apache DolphinScheduler 实现了对 OceanBase 的元数据库支持

Apache DolphinScheduler 是一款开源的分布式工作流任务调度系统,它提供了可视化的工作流设计和调度功能,支持大数据任务的自动化调度和监控。最近的更新中,Apache DolphinScheduler 引入了对 OceanBase 数据库的元数据库支持,这为用户在大数据环境中管理和调度任务提供了更多选择。用户可以通过 DolphinScheduler 提供的可视化界面进行工作流的设计和调度,也可以通过 DolphinScheduler 提供的 API 进行任务的编程调度。

VavzNvml的博客 495

Codeforces 844A

#include<cstdio> #include<cstring> bool cnt[30]; int main() { char t; int ans=0; //重复字符数 int num=0; //字符长度 memset(cnt,false,sizeof(cnt)); while(1) ...

aaron1027的博客 804

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

88.You need to calculate the number of days from 1st January 2007 till date.

88.You need to calculate the number of days from 1st January 2007 till date.

dwj19830118的专栏 1633

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

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

VC中sqlite的使用

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

How to calculate the number of parameters in CNNs?

How to calculate the number of parameters in&nbsp;CNNs?This post comes from https://stackoverflow.com/questions/28232235/how-to-calculate-the-number-of-parameters-of-convolutional-neural-networks.If y...

Dby_freedom的博客 923

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Codeforces805D. Minimum number of steps

D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output We have a string of letters 'a' a

Jelly_acm的博客 1001

cfB. Luba And The Ticket time limit per test2 seconds memory limit per test256 megabytes inputstanda

B. Luba And The Ticket time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Luba has a ticket consisting of 6 di

Dosth_Magic 5068

CodeForces 1417B Two Arrays

题目连接 题意: 给你一个组数和一个不幸数字T,要求把数组分成两部分,标记为1or0,同为1或者0的两个数相加尽可能的不等于T,求任意一种分法。 解题思路: T/2+T/2=T,既然这样,把所有小于T/2的数字放在一边,大于T/2的数放在另一边,这样无论怎么加都不会加到T。刚好等于T/2的数据就一个为0一个为1这样交替分开放。 #include<bits/stdc++.h> #define maxn 1000001 using namespace std; long long int a[max

qq_45824115的博客 1491

Codeforces_844

A.统计字母个数。 #include<bits/stdc++.h> using namespace std; string s; int n; map<char,int> mp; int main() { ios::sync_with_stdio(0); cin >> s >> n; ...

diaotan0836的博客 178

C. Dishonest Sellers

Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is ai, and after a week of discounts it

Accepted ALL lve 717

time limit per test/memory limit per test

time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4

qq_44470353的博客 1291

K - Diversity (总结概括思维)

Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible.String s consists only of lowercase Lati...

放纵不羁爱自由 276

Codeforces 844 A Diversity

题目地址 题意:给你一个序列,求把它变成至少有m个不同字母的序列需要变换几个字母。 思路:如果序列都没有m长就输出impossible,否则就是计算现在有的不同字母是不是大于m,如果是就输出0,否则输出两者的差。

不要錯過才珍惜 476

AI对话语义分析:从海量日志中挖掘用户意图与任务价值

在人工智能与自然语言处理领域,如何从非结构化文本数据中提取有意义的洞察,一直是数据科学的核心挑战。传统基于规则或简单统计的方法,在面对开放域、多轮对话数据时,往往难以准确理解语义和用户意图。其原理在于利用大型语言模型(LLM)自身的理解能力,通过提示工程构建自动化分类流水线,实现对海量对话的语义归纳与意图识别。这项技术的价值在于,它将“暗数据”转化为可量化的业务信号,使产品团队能够超越表面的交互统计,深入理解用户如何使用AI完成实际任务。在应用场景上,它特别适用于智能助手、代码补全工具、内容生成平台等生成式

weixin_30247307的博客 406

[LeetCode 871] Minimum Number of Refueling Stops

题目 A car travels from a starting position to a destination which is target miles east of the starting position. Along the way, there are gas stations. Each stations[i] represents a gas station that...

wlhwaii的博客 598

leetcode(121-140)简单题python

532. K-diff Pairs in an Array(121) Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i, j...

weixin_42307828的博客 1826
上一篇: (CodeForces 883A) The Meaningless Game 纯正的数学思维题(有点卡cin时间)
下一篇: CodeForces 875B ( Sorting the Coins) 难度蛮大的一道题目 题目说了一堆主要还是找规律
Puppet__
博客等级 码龄10年 319粉丝 328原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值