![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法和数据结构
算法和数据结构
,,,,,,,,,
这个作者很懒,什么都没留下…
展开
-
大数相加
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.InputThe first line of the input contains an integer T(1<=T<=20) which means the ...原创 2019-11-12 19:07:54 · 194 阅读 · 0 评论 -
任意进制与十进制之间的转换
任意进制转换为十进制 int pow(int n,int time){ int ans=1; for(int i=1;i<=time;i++) ans*=n; return ans;} int change_any_to_10(char *s,int type){ int ans=0; int len = strlen(...原创 2019-08-28 13:12:56 · 276 阅读 · 0 评论 -
数论
1.同余方程:a≡b(mod m)给定一个正整数n,如果两个整数a和b满足a-b能被n整除,即(a-b)modn=0,那么就称整数a与b对模n同余,记作a≡b(modn),同时可成立amodn=b。如果m是a - b的一个因子,那么就说a,b关于模m同余,即为a≡b(mod m)。如果有a≡b(mod m),那么b就是a模m的一个剩余。有关性质:传递性 同加减乘(设函数f,...原创 2019-08-06 16:16:06 · 1459 阅读 · 0 评论 -
树状数组
【例题1】题目描述如题,已知一个数列,你需要进行下面两种操作:1.将某一个数加上x2.求出某区间每一个数的和输入格式第一行包含两个整数N、M,分别表示该数列数字的个数和操作的总个数。第二行包含N个用空格分隔的整数,其中第i个数字表示数列第i项的初始值。接下来M行每行包含3个整数,表示一个操作,具体如下:操作1: 格式:1 x k 含义:将第x个数加上k操作2...原创 2019-08-01 16:10:04 · 74 阅读 · 0 评论 -
网络流模板
最大流【例题1】这是一道模板题。给定n个点,m条边,给定每条边的容量,求从点s到点t的最大流。输入格式:第一行四个整数n,m,s,t。接下来的m行,每行三个整数u,v,c,表示从u到v,流量为c的一条边。数据保证有1≤n≤100,1≤m≤5000,0≤c≤231−1。输出格式:输出点s到点t的最大流。输入样例:...原创 2019-07-30 10:28:09 · 613 阅读 · 0 评论 -
可持久化线段树 (主席树)模板
1、主席树是以前缀和形式建立的可持久化线段树。2、基于动态开结点的存储形式。3、每次插入一个值时,最多新开O(logn)个结点。4、空间复杂度O(nlogn)。5、单次操作时间复杂度O(iogn)。6、可以查询区间的值域信息。7、相对于线段树套平衡树的优势:代码简单、速度快。8、劣势:离散数据结构,难以修改(可以采取对询问分块等方式弥补)。9、主席树的插入建立运用了...原创 2019-07-29 10:32:59 · 106 阅读 · 0 评论 -
快速幂和快速乘
快速幂模板ll power(ll a, ll b, ll p){ ll ans = 1 % p, base = a; while (b) { if (b & 1) { ans = (ans%p * base%p) % p; } base = base* base%p; b >>= 1; } return ans;}快速乘模板简单模...原创 2019-04-11 20:15:47 · 122 阅读 · 0 评论 -
进制转换
十进制转十六进制#include<iostream>#include<cstdio>#include<algorithm>#include<cmath>using namespace std;int main() { int num; cin>>num; printf("%X\n",num); return 0;...原创 2020-03-04 21:45:05 · 125 阅读 · 0 评论 -
01字串
问题描述对于长度为5位的一个01串,每一位都可能是0或1,一共有32种可能。它们的前几个是:0000000001000100001100100请按从小到大的顺序输出这32种01串。输入格式本试题没有输入。输出格式输出32行,按从小到大的顺序每行一个长度为5的01串。样例输出00000000010001000011<以下部分省略>...原创 2020-03-04 17:21:45 · 101 阅读 · 0 评论 -
序列求和
问题描述求1+2+3+...+n的值。输入格式输入包括一个整数n。输出格式输出一行,包括一个整数,表示1+2+3+...+n的值。样例输入4样例输出10样例输入100说明:有一些试题会给出多组样例输入输出以帮助你更好的做题。一般在提交之前所有这些样例都需要测试通过才行,但这不代表这几组样例数据都正确了你的程序就是完全正确的,潜在的错误可能仍...原创 2020-02-22 21:19:57 · 237 阅读 · 0 评论 -
Fibonacci数列
问题描述Fibonacci数列的递推公式为:Fn=Fn-1+Fn-2,其中F1=F2=1。当n比较大时,Fn也非常大,现在我们想知道,Fn除以10007的余数是多少。输入格式输入包含一个整数n。输出格式输出一行,包含一个整数,表示Fn除以10007的余数。说明:在本题中,答案是要求Fn除以10007的余数,因此我们只要能算出这个余数即可,而不需要先计算出Fn的准确值,再...原创 2020-02-22 21:05:15 · 104 阅读 · 0 评论 -
母牛的故事
题目描述有一头母牛,它每年年初生一头小母牛。每头小母牛从第四个年头开始,每年年初也生一头小母牛。请编程实现在第n年的时候,共有多少头母牛?输入输入数据由多个测试实例组成,每个测试实例占一行,包括一个整数n(0<n<55),n的含义如题目中描述。n=0表示输入数据的结束,不做处理。输出对于每个测试实例,输出在第n年的时候母牛的数量。每个输出占一行。样例输入...原创 2020-02-19 20:04:06 · 100 阅读 · 0 评论 -
字符逆序
题目描述将一个字符串str的内容颠倒过来,并输出。str的长度不超过100个字符。输入输入包括一行。 第一行输入的字符串。输出输出转换好的逆序字符串。样例输入I am a student样例输出tneduts a ma I【代码】#include<iostream>#include<cstdio>#include<...原创 2020-02-18 23:06:16 · 96 阅读 · 0 评论 -
累加和
题目描述1、老师在黑板上写下一个正整数,记为X1。2、删除X1的最后一位数字后,得到的正整数记为X2。3、删除X2的最后一位数字后,得到的正整数记为X3。。。。。进行若干次操作后,剩下的正整数只有1位数字了,记为Xn。令Y = X1 + X2 + X3 + ....+ Xn。例如:老师刚开始在黑板写下的正整数是509,那么: X1 = 509 X2 = 50 ...原创 2019-11-12 19:10:41 · 2295 阅读 · 0 评论 -
Jessica's Reading Problem (尺取)
Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The final exam is coming, yet she has spent little time on it. If she wants to pass it, she has to master all ideas incl...原创 2019-10-29 19:56:19 · 87 阅读 · 0 评论 -
Simplicity string
题目描述For a string of letters, define the Simplicity of the string to be the number of distinct letters in the string. For example, the string string has simplicity 6, and the string l...原创 2019-10-22 20:05:55 · 198 阅读 · 0 评论 -
Carmichael Numbers(素数判断+快速幂)
An important topic nowadays in computer science is cryptography. Some people even think that cryptography is the only important field in computer science, and that life would not matter at all without...原创 2019-10-10 19:52:09 · 216 阅读 · 0 评论 -
How Many Tables(并查集)
Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not all the friends know each other, a...原创 2019-09-24 21:07:18 · 96 阅读 · 0 评论 -
The Suspects(并查集)
Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized as a global threat in mid-March 2003. To minimize transmission to others, the best strategy is to s...原创 2019-09-24 21:06:13 · 147 阅读 · 0 评论 -
The Dole Queue (双向约瑟夫环)
In a serious attempt to downsize (reduce) the dole queue, The New National Green Labour Rhinoceros Party has decided on the following strategy. Every day all dole applicants will be placed in a large ...原创 2019-08-28 15:32:15 · 239 阅读 · 0 评论 -
Hangman Judge (set应用)
In "Hangman Judge,'' you are to write a program that judges a series of Hangman games. For each game, the answer to the puzzle is given as well as the guesses. Rules are the same as the classic game o...原创 2019-08-21 14:35:28 · 106 阅读 · 0 评论 -
set应用
1、介绍:set是STL中一个很有用的容器,用来存储同一种数据类型的数据结构(可以称之为K的模型),基本功能与数组相似。 set与数组不同的是,在set中每个元素的值都是唯一的,一个set集合不能包含重复的元素。 而且set插入数据时,能够根据元素的值自动进行排序。 set中数元素的值并不能直接被改变2、常用方法begin(),返回set容器第一个元素的迭代器end()...原创 2019-08-21 14:16:49 · 127 阅读 · 0 评论 -
计算数列
设表示一个交替两个数字f(a1a2...ap−1ap,b1b2...bq−1bq)的函数,其中a1...ap和b1...bq是以十进制表示法写入的两个整数的数字,不带前导零。换句话说,函数f(x,y)通过将数字x和y从最低位数写入新的数字,从数字y开始,交替地混洗数字x和y。该函数的...原创 2019-08-17 16:51:46 · 187 阅读 · 0 评论 -
String (字符串哈希)
Given a string S and two integers L and M, we consider a substring of S as “recoverable” if and only if(i) It is of length M*L;(ii) It can be constructed by concatenating M “diversified” subst...原创 2019-08-16 10:19:02 · 690 阅读 · 1 评论 -
A Rational Sequence
题目描述An infinite full binary tree labeled by positive rational numbers is defi ned by:• The label of the root is 1/1.• The left child of label p/q is p/(p+q).• The right child ofl abel p/q is (p+q...原创 2019-08-15 10:14:25 · 144 阅读 · 0 评论 -
Popular Cows (强连通分量)
Every cow's dream is to become the most popular cow in the herd. In a herd of N (1 <= N <= 10,000) cows, you are given up to M (1 <= M <= 50,000) ordered pairs of the form (A, B) that tell...原创 2019-08-14 16:19:24 · 172 阅读 · 0 评论 -
MUSICAL CHAIRS (模拟)
题目描述Musical chairs is a game frequently played at children’s parties. Players are seated in a circle facing outwards. When the music starts, the players have to stand up and move clockwise round t...原创 2019-08-13 09:39:25 · 562 阅读 · 0 评论 -
字符串哈希(模板)
寻找长度为n的主串S中的匹配串T(长度为m)出现的位置或次数属于字符串匹配问题。字符串哈希就是将每个字符串转化为一个数值,然后遍历主串,判断在主串起始位置为i长度为m的字符串的哈希值与匹配串的哈希值是否相等即可,每次判断为O(1)的时间。这样就可以转化为O(n)的时间完成判断。若求字符串中第i位到第j位的哈希值(i<j),则这个值为H(j)-H(i-1)*base^(j-i+1)。...原创 2019-08-12 15:46:49 · 204 阅读 · 0 评论 -
过河(动态规划)
有一条河,河中有n块石头,现在从河的一边只能通过走石头到达对岸,每一步可以跨越至多3个石头。但是不幸的是,有一块石头被上一个过河的人踩松后被踩松了,所以为了安全后来的人就不能再踩这一块石头了。若现在有一个人想要到河的对岸去,他有多少种方法?注:若我们将石头从1到n进行编号的话,那么被踩松的石头编号为k。输入格式:多组输入对于每组输入在一行中给出2个整数n和...原创 2019-08-12 09:30:49 · 1241 阅读 · 0 评论 -
Simple Addition expression(组合数学)
题目描述A luxury yacht with 100 passengers on board is sailing on the sea in the twilight. The yacht is ablaze with lights and there comes out laughers and singing from the hall where an evening party ...原创 2019-08-09 11:43:04 · 163 阅读 · 0 评论 -
Super Jumping! Jumping! Jumping! (动态规划)
Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now.The game c...原创 2019-08-08 11:07:51 · 93 阅读 · 0 评论 -
Degree Sequence of Graph G(模拟+Havel定理)
题目描述Wang Haiyang is a strong and optimistic Chinese youngster. Although born and brought up in the northern inland city Harbin, he has deep love and yearns for the boundless oceans. After graduation...原创 2019-08-08 10:35:14 · 480 阅读 · 0 评论 -
Shell Pyramid(二分)
题目描述In the 17th century, with thunderous noise, dense smoke and blazing fire, battles on the sea were just the same as those in the modern times. But at that time, the cannon were extremely simple. ...原创 2019-08-07 15:26:16 · 97 阅读 · 0 评论 -
数字组合(动态规划)
题目描述在N个数中找出其和为M的若干个数。先读入正整数N(1<N<100)和M(1<M<10000), 再读入N个正数(可以有相同的数字,每个数字均在1000以内), 在这N个数中找出若干个数, 使它们的和是M, 把满足条件的数字组合都找出来以统计组合的个数,输出组合的个数(不考虑组合是否相同)。要求你的程序运行时间不超过1秒。输入第一行是两个数字,表示N和M。...原创 2019-08-06 16:55:35 · 1285 阅读 · 3 评论 -
LCIS II(动态规划:最长公共上升子序列)
题目描述熊大妈的奶牛在小沐沐的熏陶下开始研究信息题目。小沐沐先让奶牛研究了最长上升子序列,再让他们研究了最长公共子序列,现在又让他们研究最长公共上升子序列了。小沐沐说,对于两个数列A和B,如果它们都包含一段位置不一定连续的数,且数值是严格递增的,那么称这一段数是两个数列的公共上升子序列,而所有的公共上升子序列中最长的就是最长公共上升子序列了。奶牛半懂不懂,小沐沐要你来告诉奶牛什么是最长公共...原创 2019-08-06 09:42:01 · 298 阅读 · 0 评论 -
最少拦截系统 (动态规划)
某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹.怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统...原创 2019-08-05 09:24:13 · 350 阅读 · 0 评论 -
免费馅饼(动态规划)
都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼。说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁的10米范围内。馅饼如果掉在了地上当然就不能吃了,所以gameboy马上卸下身上的背包去接。但由于小径两侧都不能站人,所以他只能在小径上接。由于gameboy平时老呆在房间里玩游戏,虽然在游戏中是个身手敏捷的高手,但在现实中运动神经特别迟钝...原创 2019-08-05 09:14:29 · 164 阅读 · 0 评论 -
Give Candies
题目描述There are N children in kindergarten. Miss Li bought them N candies。To make the process more interesting, Miss Li comes up with the rule: All the children line up according to their student numb...原创 2019-08-02 15:24:37 · 161 阅读 · 0 评论 -
P1036 选数
题目描述已知nn个整数x1,x2,…,xnx1,x2,…,xn,以及11个整数kk(k<nk<n)。从nn个整数中任选kk个整数相加,可分别得到一系列的和。例如当n=4,k=3n=4,k=3,44个整数分别为3,7,12,193,7,12,19时,可得全部的组合与它们的和为:3+7+12=223+7+12=223+7+19=293+7+19=297+12+1...原创 2019-07-24 10:01:29 · 846 阅读 · 0 评论 -
P1149 火柴棒等式
题目描述给你n根火柴棍,你可以拼出多少个形如“A+B=CA+B=C”的等式?等式中的AA、BB、CC是用火柴棍拼出的整数(若该数非零,则最高位不能是00)。用火柴棍拼数字0−90−9的拼法如图所示:注意: 加号与等号各自需要两根火柴棍 如果A≠BA≠B,则A+B=CA+B=C与B+A=CB+A=C视为不同的等式(A,B,C>=0A,B,C>=0) ...原创 2019-07-24 09:11:06 · 173 阅读 · 0 评论