自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

转载 【转载】【C/C++】求最大公约数的三种方法

一、最大公约数与最小公倍数最大公约数,属于数论所探究的内容。最大公约数可以通过下面的三种方法求出来。最小公倍数呢,它与最大公约数的乘机为所求数之积。比如求 x,y的最大公约数和最小公倍数记住这个公式:== xy=最小公倍数最大公约数==二、求最大公约数的三种方法①辗转相除法算法流程图代码块:int measure(int x, int y){ int z = y; while(x%y!=0) { z = x%y; x = y; y = z; } retur

2021-11-02 20:57:35 1271

转载 全错位排列问题

问题描述这是一个很经典的数学问题:有一个人写了n封信件,对应n个信封,然而粗心的秘书却把所有信件都装错了信封,那么一共有多少种装错的装法?数学抽象这个问题可抽象为以下一个数学问题:已知一个长度为n的有序序列{a1,a2,a3,…,an},打乱其顺序,使得每一个元素都不在原位置上,则一共可以产生多少种新的排列?例如:原序列为{a,b,c,d,e},则新序列{b,c,d,e,a}为其一个全错位排列,新序列中每一个元素都不在原来的位置上。问题解决首先考虑几种简单的情况:原序列长度为1序列中只有一个

2021-10-01 19:41:25 1268

转载 负数取余问题

前言:对于两个相同符号的数取余大家都很熟悉,但是对于一正一负的数取余呢?大家可能觉得会很陌生,今天在刷leetcode7:整数反转(easy)这道题的时候,想起了这个知识点,遂打算探讨一番。自然数取余定义分为两种:1)定义1:如果a和d是两个自然数,d非零,可以证明存在两个唯一的整数 q 和 r,满足a=qd+r且0 ≤ r < d(其中q为商,r为余数)。定义1一般作为数学中的取余法则,即两个数取余,余数总是为正数。举例:5%3=3x1+2,商为1,余数为2(-5)%(-3)=(-3)

2021-10-01 10:44:05 7319 2

转载 vscode debug 数组

1、添加检测(type()[number])begintype,类型number,查看数量begin,起始地址指针2、直接查看鼠标指向变量名即可转载

2021-09-19 13:47:50 737

原创 1090 Highest Price in Supply Chain (25 分)

A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on the chain buys products from one’s supplier in a price P an

2021-09-16 18:08:07 144

原创 1079 Total Sales of Supply Chain (25 分)

A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on the chain buys products from one’s supplier in a price P an

2021-09-16 18:07:10 85

原创 1102 Invert a Binary Tree (25 分)

The following is from Max Howell @twitter:Google: 90% of our engineers use the software you wrote (Homebrew), but you can't invert a binary tree on a whiteboard so fuck off.Now it’s your turn to prove that YOU CAN invert a binary tree!Input Specificati

2021-09-16 18:06:16 65

原创 1020 Tree Traversals (25 分)

Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the corresponding binary tree.Input Specification:Each input

2021-09-16 18:05:39 65

原创 1086 Tree Traversals Again (25 分)

An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbered from 1 to 6) is traversed, the stack operations are: push(1); push(2); push(3); pop(); pop(

2021-09-16 18:05:01 72

原创 1091 Acute Stroke (30 分)

One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the results of image analysis in which the core regions are identified in each MRI slice, your job is to calculate the volume of the stroke core.Input Specificat

2021-09-14 16:39:44 75

原创 1103 Integer Factorization (30 分)

The K−P factorization of a positive integer N is to write N as the sum of the P-th power of K positive integers. You are supposed to write a program to find the K−P factorization of N for any positive integers N, K and P.Input Specification:Each input fi

2021-09-14 16:39:09 66

原创 1056 Mice and Rice (25 分)

Mice and Rice is the name of a programming contest in which each programmer must write a piece of code to control the movements of a mouse in a given map. The goal of each mouse is to eat as much rice as possible in order to become a FatMouse.First the pl

2021-09-14 16:37:57 140

原创 1051 Pop Sequence (25 分)

Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, …, N and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of the stack. For example, if M is 5 and N is 7, we can obtain

2021-09-14 16:37:02 93

原创 1071 Speech Patterns (25 分)

People often have a preference among synonyms of the same word. For example, some may prefer “the police”, while others may prefer “the cops”. Analyzing such patterns can help to narrow down a speaker’s identity, which is useful when validating, for exampl

2021-09-14 16:35:49 79

原创 1054 The Dominant Color (20 分)

Behind the scenes in the computer’s memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the dominant color. A strictly dominant color takes more than

2021-09-14 16:34:59 100

原创 1100 Mars Numbers (20 分)

People on Mars count their numbers with base 13:Zero on Earth is called “tret” on Mars.The numbers 1 to 12 on Earth is called “jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec” on Mars, respectively.For the next higher digit, Mars people name

2021-09-14 16:34:04 70

原创 1060 Are They Equal (25 分)

If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered equal since they are both saved as 0.123×10510^5105 with simple chopping. Now given the number of significant digits on a machine and two float numbers, you

2021-09-14 08:16:22 62

原创 1063 Set Similarity (25 分)

Given two sets of integers, the similarity of the sets is defined to beNc/Nt×100N_c/N_t×100Nc​/Nt​×100​%, whereNcN_cNc​​​ is the number of distinct common numbers shared by the two sets, and NtN_tNt​​​ is the total number of distinct numbers in the two set

2021-09-13 23:16:57 69

原创 1047 Student List for Course (25 分)

Zhejiang University has 40,000 students and provides 2,500 courses. Now given the registered course list of each student, you are supposed to output the student name lists of all the courses.Input Specification:Each input file contains one test case. For

2021-09-13 23:16:04 89

原创 1039 Course List for Student (25 分)

Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists of all the courses, you are supposed to output the registered course list for each student who comes for a query.Input Specification:Each input file contai

2021-09-13 23:15:26 62

原创 1049 Counting Ones (30 分)

The task is simple: given any positive integer N, you are supposed to count the total number of 1’s in the decimal form of the integers from 1 to N. For example, given N being 12, there are five 1’s in 1, 10, 11, and 12.Input Specification:Each input fil

2021-09-13 23:14:16 85

原创 1104 Sum of Number Segments (20 分)

Given a sequence of positive numbers, a segment is defined to be a consecutive subsequence. For example, given the sequence { 0.1, 0.2, 0.3, 0.4 }, we have 10 segments: (0.1) (0.1, 0.2) (0.1, 0.2, 0.3) (0.1, 0.2, 0.3, 0.4) (0.2) (0.2, 0.3) (0.2, 0.3, 0.4)

2021-09-13 23:13:30 86

原创 1101 Quick Sort (25 分)

There is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the pivot are moved to its left and those larger than the pivot to its right. Given N

2021-09-13 23:10:47 69

原创 1093 Count PAT‘s (25 分)

The string APPAPT contains two PAT's as substrings. The first one is formed by the 2nd, the 4th, and the 6th characters, and the second one is formed by the 3rd, the 4th, and the 6th characters.Now given any string, you are supposed to tell the number of

2021-09-13 22:53:55 73

原创 1029 Median (25 分)

Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1 = { 11, 12, 13, 14 } is 12, and the median of S2 = { 9, 10, 15, 16, 17 } is 15. The median of two sequences is defined to be the me

2021-09-13 22:51:16 2138

原创 1089 Insert or Merge (25 分)

According to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list, an

2021-09-13 22:50:26 56

原创 1044 Shopping in Mars (25 分)

Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$$). When making the payment, the chain can be cut at any position for only once and some of the diamonds are taken off th

2021-09-13 22:49:01 2221

原创 1085 Perfect Sequence (25 分)

Given a sequence of positive integers and another positive integer p. The sequence is said to be a perfect sequence if M≤m×pM≤m×pM≤m×p​​ whereMMM​​and mmm​​ are the maximum and minimum numbers in the sequence, respectively.Now given a sequence and a param

2021-09-11 15:08:11 68

原创 1067 Sort with Swap(0, i) (25 分)

Given any permutation of the numbers {0, 1, 2,…, N−1}, it is easy to sort them in increasing order. But what if Swap(0, *) is the ONLY operation that is allowed to use? For example, to sort {4, 0, 2, 1, 3} we may apply the swap operations in the following

2021-09-11 15:06:00 61

原创 10050 String Subtraction (20 分)

Given two strings S1S_1S1​and S2S_2S2​, S=S1−S2S=S_1-S_2S=S1​−S2​is defined to be the remaining string after taking all the characters in S2S_2S2​ from S1S_1S1​. Your task is simply to calculate for S1−S2S_1-S_2S1​−S2​ any given strings. However, it mig

2021-09-11 15:04:42 60

原创 1041 Be Unique (20 分)

Being unique is so important to people on Mars that even their lottery is designed in a unique way. The rule of winning is simple: one bets on a number chosen from [1,10410^4104]. The first one who bets on a unique number wins. For example, if there are 7

2021-09-11 15:03:17 70

原创 1092 To Buy or Not to Buy (20 分)

Eva would like to make a string of beads with her favorite colors so she went to a small shop to buy some beads. There were many colorful strings of beads. However the owner of the shop would only sell the strings in whole pieces. Hence Eva must check whet

2021-09-11 15:02:13 52

原创 1084 Broken Keyboard (20 分)

On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on screen.Now given a string that you are supposed to type, and the string that you actually type out, please

2021-09-11 15:01:11 63

原创 1089 Insert or Merge (25 分)

1089 Insert or Merge (25 分)According to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data, finds the location it belong

2021-09-11 14:59:05 86

原创 1083 List Grades (25 分)

1083 List Grades (25 分)Given a list of N student records with name, ID and grade. You are supposed to sort the records with respect to the grade in non-increasing order, and output those student records of which the grades are in a given interval.Input S

2021-09-11 14:55:19 158

原创 1055 The World‘s Richest (25 分)

Forbes magazine publishes every year its list of billionaires based on the annual ranking of the world’s wealthiest people. Now you are supposed to simulate this job, but concentrate only on the people in a certain range of ages. That is, given the net wor

2021-09-11 14:54:18 213

原创 1028 List Sorting (25 分)

1028 List Sorting (25 分)Excel can sort records according to any column. Now you are supposed to imitate this function.Input Specification:Each input file contains one test case. For each case, the first line contains two integers N (≤10510^5105) and C,

2021-09-11 14:50:58 74

原创 1025 PAT Ranking (25 分)

1025 PAT Ranking (25 分)Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after

2021-09-10 23:55:47 88

原创 高精度减法

题目描述高精度减法。输入格式两个整数 a,b(第二个可能比第一个大)。输出格式结果(是负数要输出负号)。输入输出样例输入21输出1说明/提示20%20\%20% 数据 a,b 在 long long 范围内;100%100\%100% 数据 0<a,b≤10100860<a,b\le 10^{10086}0<a,b≤1010086#include<algorithm>#include<string.h>#include<ios

2021-09-09 22:33:24 124

原创 P1601 A+B Problem(高精)

题目描述高精度加法,相当于a+b problem,不用考虑负数.输入格式分两行输入。a,b \leq 10^{500}a,b≤10500输出格式输出只有一行,代表a+ba+b的值输入输出输入11输出2输入10019099输出10100昨天做了一个题关于高精度的,正好又碰到了,写了一下#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;

2021-09-08 19:15:31 190

空空如也

空空如也

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

TA关注的人

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