ICode9

精准搜索请尝试: 精确搜索
  • 牛客华为机试HJ612022-04-21 07:33:29

    原题传送门 1. 问题描述 2. Solution import sys """ 放苹果分为两种情况,一种是有盘子为空,一种是每个盘子均均不空 设f(m, n) 为求解函数 case 1: 若有一个盘子为空,则问题转换为f(m, n-1) 将m个苹果放到 n-1个盘子中 case 2: 若每个盘子均不空,则在每个盘子上都先放1个苹果,问题转

  • 牛客华为机试HJ622022-04-21 07:33:22

    原题传送门 1. 题目描述 2. Solution 1 1、思路分析 最朴素的想法直接转换成二进制字符串,统计1的个数。 2、代码实现 import sys if sys.platform != "linux": sys.stdin = open("input/HJ15.txt") def solve(n): n_bin = bin(n).replace("0b", "") print(n_bi

  • 牛客华为机试HJ632022-04-21 07:33:02

    原题传送门 1. 题目描述 2. Solution 1 1、思路分析 遍历所有的长度为n的子串,统计每个子串的字符串g、c出现次数,保存g、c出现次数最多的子串为最终答案。 2、代码实现 import sys if sys.platform != "linux": file_in = open("input/HJ63.txt") sys.stdin = file_in

  • 牛客华为机试HJ642022-04-21 07:32:46

    原题传送门 1. 问题描述 2. Solution 滑动窗口 import sys if sys.platform != "linux": file_in = open("input/HJ64.txt") sys.stdin = file_in def solve(n, s): cur = 1 start = 1 for c in s: if c == 'U':

  • 牛客华为机试HJ652022-04-21 07:32:26

    原题传送门 1. 问题描述 2. Solution import sys if sys.platform != "linux": sys.stdin = open("input/HJ65.txt") """ 1) 状态定义 dp[i][j] 表示字符串s1中第i个字符和s2中第j个字符所构成的最长公共子串。 2) 初始状态 dp[i][j] = {0} 3)

  • 牛客华为机试HJ662022-04-21 07:32:18

    原题传送门 1. 问题描述 2. Solution import re import sys if sys.platform != "linux": file_in = open("input/HJ66.txt") sys.stdin = file_in command_map = { # ("reset", ""): "reset what", ("res

  • 牛客华为机试HJ672022-04-21 07:32:05

    原题传送门 1. 问题描述 2. Solution import sys if sys.platform != "linux": file_in = open("input/HJ67.txt") sys.stdin = file_in def solve(nums, target): if len(nums) == 1: return nums[0] == target else: for i

  • 牛客华为机试HJ682022-04-21 07:31:30

    原题传送门 1. 题目描述 2. Solution import sys if sys.platform != "linux": file_in = open("input/HJ68.txt") sys.stdin = file_in def solve(): n = int(input().strip()) order = input().strip() # 0代表从高到低,1代表从低到高 reverse =

  • 牛客华为机试HJ692022-04-21 07:31:22

    原题传送门 1. 题目描述 2. Solution 1 1、思路分析 按公式计算,。 2、代码实现 import sys if sys.platform != "linux": sys.stdin = open("input/HJ69.txt") while True: try: m = int(input().strip()) p = int(input().strip()) n = int(

  • 牛客华为机试HJ702022-04-21 07:31:06

    原题传送门 1. 题目描述 2. Solution 1 1、思路分析 dim(A) = (m, n), dim(B) = (n, p) AB = mp 2、代码实现 import sys if sys.platform != "linux": sys.stdin = open("input/HJ70.txt") while True: try: n = int(input().strip()) dims = []

  • 牛客华为机试HJ522022-04-21 07:00:05

    原题传送门 1. 问题描述 2. Solution java版思路分析,来自LeetCode 72 /* DP 1. Define the state dp[i][j] to be the minimum number of operations to convert word1[0...i) to word2[0...j) 2. Initial state For the base case, that is, to con

  • 牛客华为机试HJ442022-04-20 21:03:35

    原题传送门 1. 题目描述 2. Solution 1、思路 从上到下,从左到右遍历,每个空位置。在第一个空位置,随便填一个合法的数字,递归在填充后续空位置。如果,期间出现没有数字可以填的话,就回退到上一个位置,换下一个数字,继续。 import sys if sys.platform != "linux": file_in = open(

  • 牛客华为机试HJ312022-04-20 08:02:38

    原题传送门 1. 问题描述 2. Solution import re org = input().strip() words = re.split(r'\W+', org) words.reverse() print(" ".join(words))

  • 牛客华为机试HJ322022-04-20 08:02:26

    原题传送门 1. 问题描述 2. Solution 参考LeetCode5 Longest Palindromic Substring import sys if sys.platform != "linux": file_in = open("input/HJ32.txt") sys.stdin = file_in def solve(s): n = len(s) dp = [[False] * n for _ in ra

  • 牛客华为机试HJ332022-04-20 08:02:08

    原题传送门 1. 问题描述 2. Solution 1、思路 bit对齐 2、实现 import sys if sys.platform != "linux": file_in = open("input/HJ33.txt") sys.stdin = file_in def int2bin(n, bits=8): n_b = bin(n).replace("0b", "") return

  • 牛客华为机试HJ342022-04-20 08:01:51

    原题传送门 1. 问题描述 2. Solution 1、思路分析 按ASCII码排序 2、代码实现 import sys if sys.platform != "linux": sys.stdin = open("input/HJ34.txt") for line in sys.stdin: s = line.strip() sorted_s = sorted(s, key=lambda x: ord(x)) print(&qu

  • 牛客华为机试HJ352022-04-20 08:01:42

    原题传送门 1. 问题描述 2. Solution 1、思路分析 找规律 0 | 1 3 6 10 1 | 2 5 9 2 | 4 8 3 | 7 0 1 0 2 1 0 3 2、代码实现 import sys if sys.platform != "linux": file_in = open("input/HJ35.txt") sys.stdin = file_in """ 0 | 1 3 6 10 1 | 2

  • 牛客华为机试HJ362022-04-20 08:01:12

    原题传送门 1. 题目描述 2. Solution 1 1、思路分析 先生成密钥,对输入的key按输入序去重(即保留第1次出现的字符)保存结果到letters2,然后遍历a~z,把未出现在letters2中的字符加入到letters2。 之后就是加密过程,按照下标取出对应字符即可。 2、代码实现 import sys if sys.platfor

  • 牛客华为机试HJ372022-04-20 08:00:38

    原题传送门 1. 题目描述 2. Solution 1、思路分析 斐波那契数列 2、代码实现 import sys if sys.platform != "linux": sys.stdin = open("input/HJ37.txt") # 迭代实现 def solve(n): a, b = 0, 1 for i in range(n): a, b = b, a + b print(a) de

  • 牛客华为机试HJ382022-04-20 08:00:28

    原题传送门 1. 题目描述 2. Solution 1 import sys if sys.platform != "linux": file_in = open("input/HJ38.txt") sys.stdin = file_in for line in sys.stdin: n = int(line.strip()) sum = n for i in range(4): n /= 2

  • 牛客华为机试HJ392022-04-20 08:00:16

    原题传送门 1. 题目描述 2. Solution 1、思路 把ip全转换为32bit 字符串,模拟与运算。 2、实现 import sys if sys.platform != "linux": file_in = open("input/HJ39.txt") sys.stdin = file_in """ 若IP地址或子网掩码格式非法则输出1,若IP1与IP2属于同一子网络输出0,

  • 牛客华为机试HJ402022-04-20 08:00:05

    原题传送门 1. 题目描述 2. Solution 1 import sys if sys.platform != "linux": file_in = open("input/HJ40.txt") sys.stdin = file_in for line in sys.stdin: result = dict(letters=0, spaces=0, digits=0, other=0) s = line.strip()

  • 牛客华为机试HJ282022-04-19 20:33:46

    原题传送门 1. 题目描述 2. Solution 1、思路分析 匈牙利算法: https://blog.csdn.net/u013384984/article/details/90718287 本题的思路是:如果是素数,一定是奇数和偶数结合(奇数)才有可能是素数,所以将需要配对的数分为两组,一组是奇数,一组是偶数,通过匈牙利算法求得最大的配对数 配对

  • 牛客华为机试HJ232022-04-19 07:32:59

    原题传送门 1. 题目描述 2. Solution Java package huawei.HJ023; import java.io.IOException; import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Main { static Scanner in; static String inp

  • 牛客华为机试HJ242022-04-19 07:32:44

    原题传送门 1. 题目描述 2. Solution 1、思路分析 此题是最长递增子序列的变体,基本思路是对原序列从左到右和从右到左分别求出到每个元素的最长递增子序列的长度。例如,原序列为长度为n的序列[8,20,12,15,10,9],从左至右的到序列里每个元素的最长递增子序列为l1=[1,2,2,3,2,2],从右

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有