自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(113)
  • 收藏
  • 关注

原创 KMP算法实现

KMP算法实现#include<iostream>#include<string>using namespace std;void GetNext(string s, int* next){ int len = s.length(); int j = 0, k = -1; next[0] = -1; while (j < len) //查找多次且可重叠 len不能减一 因为该字符串的末尾加一的next下一次查询用到。 {

2021-12-15 19:42:17 461

原创 Expression//表达式求值

Expression//表达式求值#include<iostream>#include<algorithm>#include<stack>#include<stdlib.h>#include<vector>#include<string>using namespace std;string format(string str) //字符串预处理 主要是处理-2+3 1+(-3-3){ for (int i = 0;

2021-12-14 16:51:06 692

原创 LinkList的基本功能实现

LinkList的基本功能实现LinkList的头文件#pragma once#include<iostream>using namespace std;template <typename DataType>struct Node{ DataType data; //数据域 Node* next; //指针域};template <typename DataType>class LinkList{public: LinkList(); //

2021-12-14 16:45:43 761

原创 Day 53 A. Sequence with Digits

ProblemLet’s define the following recurrence:an+1=an+minDigit(an)⋅maxDigit(an).Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes.For examples refer to notes.Your task is calcu

2021-09-04 12:35:54 130

原创 Day 52 B. Sorted Adjacent Differences

ProblemYou have array of n numbers a1,a2,…,an.Rearrange these numbers to satisfy |a1−a2|≤|a2−a3|≤…≤|an−1−an|, where |x| denotes absolute value of x. It’s always possible to find such rearrangement.Note that all numbers in a are not necessarily different

2021-09-03 12:12:36 134

原创 Day 51 B. Dreamoon and WiFi

ProblemDreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon’s smartphone and Dreamoon follows them.Each command is one of the following two types:Go 1 unit towards the positive direction

2021-09-02 17:51:28 128

原创 Day 50 B. Ternary String

ProblemYou are given a string s such that each its character is either 1, 2, or 3. You have to choose the shortest contiguous substring of s such that it contains each of these three characters at least once.A contiguous substring of string s is a string

2021-09-01 19:17:45 184

原创 Day 49 C. Exams

ProblemStudent Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take severa

2021-08-31 22:22:51 181

原创 Day 48 C. Product of Three Numbers

ProblemYou are given one integer number n. Find three distinct integers a,b,c such that 2≤a,b,c and a⋅b⋅c=n or say that it is impossible to do it.If there are several answers, you can print any.You have to answer t independent test cases.InputThe firs

2021-08-30 16:45:59 130

原创 Day 47 D. Same Differences

ProblemYou are given an array a of n integers. Count the number of pairs of indices (i,j) such that i<j and aj−ai=j−i.InputThe first line contains one integer t (1≤t≤10^4). Then t test cases follow.The first line of each test case contains one integ

2021-08-29 15:01:46 125

原创 Day 46 C. Boats Competition

ProblemThere are n people who want to participate in a boat competition. The weight of the i-th participant is wi. Only teams consisting of two people can participate in this competition. As an organizer, you think that it’s fair to allow only teams with

2021-08-28 23:29:29 222

原创 Day 45 D. Buying Shovels

ProblemPolycarp wants to buy exactly n shovels. The shop sells packages with shovels. The store has k types of packages: the package of the i-th type consists of exactly i shovels (1≤i≤k). The store has an infinite number of packages of each type.Polycar

2021-08-27 23:50:51 137

原创 Day 44 D. Anti-Sudoku

ProblemYou are given a correct solution of the sudoku puzzle. If you don’t know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most 9 e

2021-08-26 15:50:35 141

原创 Day 43 B. K-th Beautiful String

ProblemFor the given integer n (n>2) let’s write down all the strings of length n which contain n−2 letters ‘a’ and two letters ‘b’ in lexicographical (alphabetical) order.Recall that the string s of length n is lexicographically less than string t of

2021-08-25 09:17:20 146

原创 Day 42 A. Pashmak and Garden

ProblemPashmak has fallen in love with an attractive girl called Parmida since one year ago…Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden

2021-08-24 16:14:06 167

原创 Day 41 C. Ternary XOR

ProblemA number is ternary if it contains only digits 0, 1 and 2. For example, the following numbers are ternary: 1022, 11, 21, 2002.You are given a long ternary number x. The first (leftmost) digit of x is guaranteed to be 2, the other digits of x can b

2021-08-23 13:02:29 115

原创 Day 40 B. Same Parity Summands

ProblemYou are given two positive integers n (1≤n≤10^9) and k (1≤k≤100). Represent the number n as the sum of k positive integers of the same parity (have the same remainder when divided by 2).In other words, find a1,a2,…,ak such that all ai>0, n=a1+a

2021-08-22 10:25:48 187

原创 Day 39 A. Odd Selection

ProblemShubham has an array a of size n, and wants to select exactly x elements from it, such that their sum is odd. These elements do not have to be consecutive. The elements of the array are not guaranteed to be distinct.Tell him whether he can do so.

2021-08-21 10:51:10 161

原创 Day 38 B. Random Teams

Problemn participants of the competition were split into m teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.Your task is to write a program that will fi

2021-08-20 11:07:18 155

原创 Day 37 C. Kefa and Park

ProblemKefa decided to celebrate his first big salary by going to the restaurant.He lives by an unusual park. The park is a rooted tree consisting of n vertices with the root at vertex 1. Vertex 1 also contains Kefa’s house. Unfortunaely for our hero, th

2021-08-19 12:05:49 166

原创 Day 36 C. Number of Ways

ProblemYou’ve got array a[1], a[2], …, a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.More formally, you need to find the nu

2021-08-18 15:46:26 107

原创 Day 35 A. Two Substrings

ProblemYou are given string s. Your task is to determine if the given string s contains two non-overlapping substrings “AB” and “BA” (the substrings can go in any order).InputThe only line of input contains a string s of length between 1 and 10^5 consis

2021-08-17 09:29:39 216

原创 Day 34 B. Books

ProblemWhen Valera has got some free time, he goes to the library to read some books. Today he’s got t free minutes to read. That’s why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let’s number

2021-08-16 13:50:36 124

原创 Day 33 B. Pashmak and Flowers

ProblemPashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number bi. Parmida is a very strange girl so she doesn’t want to have the two most beautiful flowers necessarily.

2021-08-15 10:37:11 159

原创 Day 32 B. Sort the Array

ProblemBeing a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers.Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger arra

2021-08-14 12:02:23 185

原创 Day 31 C. Alternating Subsequence

ProblemRecall that the sequence b is a a subsequence of the sequence a if b can be derived from a by removing zero or more elements without changing the order of the remaining elements. For example, if a=[1,2,1,3,1,2,1], then possible subsequences are: [1

2021-08-13 11:16:25 155

原创 Day 30 B. Worms

ProblemIt is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab

2021-08-12 11:45:15 193

原创 Day 29 C. K-th Not Divisible by n

ProblemYou are given two positive integers n and k. Print the k-th positive integer that is not divisible by n.For example, if n=3, and k=7, then all numbers that are not divisible by 3 are: 1,2,4,5,7,8,10,11,13…. The 7-th number among them is 10.Input

2021-08-11 11:16:39 166

原创 Day 28 A. Flipping Game

ProblemIahub got bored, so he invented a game to be played on paper.He writes n integers a1, a2, …, an. Each of those integers can be either 0 or 1. He’s allowed to do exactly one move: he chooses two indices i and j (1 ≤ i ≤ j ≤ n) and flips all values

2021-08-10 10:20:25 131

原创 Day 27 B. Two Buttons

ProblemVasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the bl

2021-08-09 11:25:26 98

原创 Day 26 B. BerSU Ball

ProblemThe Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.We know that several boy&girl pairs are going to

2021-08-08 00:53:07 197

原创 Day 24 C. Given Length and Sum of Digits...

ProblemYou have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base wi

2021-08-07 15:41:43 158

原创 Day 24 A. Cheap Travel

ProblemAnn has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will n

2021-08-06 10:35:00 345

原创 Day 23 A. Boredom

ProblemAlex doesn’t like boredom. That’s why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.Given a sequence a consisting of n integers. The player can make several steps. In a single

2021-08-05 11:50:21 148

原创 Day 22 A. Cut Ribbon

ProblemPolycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the following two conditions:After the cutting each ribbon piece should have length a, b or c.After the cutting the number of ribbon pieces should be maxim

2021-08-04 10:29:36 179

原创 Day 21 B. T-primes

ProblemWe know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we’ll call a positive integer t Т-prime, if t has exactly three distinct positive divisors.You are given an array of n positive integers.

2021-08-03 09:20:05 184

原创 Day 20 C. Registration system

ProblemA new e-mail service “Berlandesk” is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that’s why they ask you to help. You’re suggested to implement the prototype of site r

2021-08-02 11:05:20 115

原创 Day 19 B. Flip the Bits

Problem:There is a binary string a of length n. In one operation, you can select any prefix of a with an equal number of 0 and 1 symbols. Then all symbols in the prefix are inverted: each 0 becomes 1 and each 1 becomes 0.For example, suppose a=0111010000

2021-08-01 10:09:17 196

原创 Day 18 C. Coin Rows

Problem:Alice and Bob are playing a game on a matrix, consisting of 2 rows and m columns. The cell in the i-th row in the j-th column contains ai,j coins in it.Initially, both Alice and Bob are standing in a cell (1,1). They are going to perform a sequen

2021-07-31 20:35:03 238

原创 Day 17 B. Cobb

Problem:You are given n integers a1,a2,…,an and an integer k. Find the maximum value of i⋅j−k⋅(ai | aj) over all pairs (i,j) of integers with 1≤i<j≤n.InputThe first line contains a single integer t (1≤t≤10000) — the number of test cases.The first l

2021-07-30 14:52:18 193

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除