ACM与算法
Mr_Hello_World
菜鸟的进阶之路
展开
-
LeetCode 2. 两数相加
2. 两数相加难度中等5413收藏分享切换为英文接收动态反馈给出两个非空的链表用来表示两个非负的整数。其中,它们各自的位数是按照逆序的方式存储的,并且它们的每个节点只能存储一位数字。如果,我们将这两个数相加起来,则会返回一个新的链表来表示它们的和。您可以假设除了数字 0 之外,这两个数都不会以 0开头。示例:输入:(2 -> 4 -> 3) + (5 -> 6 -> 4)输出:7 -> 0 -> 8原因:342 + 465 = ...原创 2020-12-23 00:29:12 · 240 阅读 · 0 评论 -
已知二叉树的先序遍历序列和中序遍历序列,输出该二叉树的后序遍历序列
题目描述输入二叉树的先序遍历序列和中序遍历序列,输出该二叉树的后序遍历序列。输入第一行输入二叉树的先序遍历序列;第二行输入二叉树的中序遍历序列。输出输出该二叉树的后序遍历序列。示例输入ABDCEFBDAECF示例输出 DBEFCA 关键是要找到左子树先序遍历和中序遍历所分别对应的下标,和他们的长度表达式。 #include <iostream>#...转载 2017-02-19 18:36:14 · 1676 阅读 · 0 评论 -
树的遍历 有后序遍历和中序遍历建立二叉树,并输出层次遍历
树的遍历 (25分)给定一棵二叉树的后序遍历和中序遍历,请你输出其层序遍历的序列。这里假设键值都是互不相等的正整数。输入格式:输入第一行给出一个正整数NN(\le 30≤30),是二叉树中结点的个数。第二行给出其后序遍历序列。第三行给出其中序遍历序列。数字间以空格分隔。输出格式:在一行中输出该树的层序遍历的序列。数字间以1个空格分隔,行首尾不得有多余空格。输入样例:...原创 2017-02-19 19:09:10 · 2306 阅读 · 0 评论 -
最长对称子串
最长对称子串 (25分)对给定的字符串,本题要求你输出最长对称子串的长度。例如,给定Is PAT&TAP symmetric?,最长对称子串为s PAT&TAP s,于是你应该输出11。输入格式:输入在一行中给出长度不超过1000的非空字符串。输出格式:在一行中输出最长对称子串的长度。输入样例:Is PAT&TAP symmetric?...原创 2017-02-19 21:34:19 · 3406 阅读 · 0 评论 -
肿瘤诊断(三维BFS)
题目地址:https://www.patest.cn/contests/gplt/L3-004肿瘤诊断 在诊断肿瘤疾病时,计算肿瘤体积是很重要的一环。给定病灶扫描切片中标注出的疑似肿瘤区域,请你计算肿瘤的体积。输入格式:输入第一行给出4个正整数:MM、NN、LL、TT,其中MM和NN是每张切片的尺寸(即每张切片是一个M\times NM×N的像素矩阵。最大分辨率是1286\tim...原创 2017-02-20 20:04:53 · 617 阅读 · 0 评论 -
大笨钟
大笨钟 微博上有个自称“大笨钟V”的家伙,每天敲钟催促码农们爱惜身体早点睡觉。不过由于笨钟自己作息也不是很规律,所以敲钟并不定时。一般敲钟的点数是根据敲钟时间而定的,如果正好在某个整点敲,那么“当”数就等于那个整点数;如果过了整点,就敲下一个整点数。另外,虽然一天有24小时,钟却是只在后半天敲1~12下。例如在23:00敲钟,就是“当当当当当当当当当当当”,而到了23:01就会是“当当当当...原创 2017-02-21 10:38:07 · 2389 阅读 · 0 评论 -
谁先倒(模拟)
谁先倒 划拳是古老中国酒文化的一个有趣的组成部分。酒桌上两人划拳的方法为:每人口中喊出一个数字,同时用手比划出一个数字。如果谁比划出的数字正好等于两人喊出的数字之和,谁就输了,输家罚一杯酒。两人同赢或两人同输则继续下一轮,直到唯一的赢家出现。下面给出甲、乙两人的酒量(最多能喝多少杯不倒)和划拳记录,请你判断两个人谁先倒。输入格式:输入第一行先后给出甲、乙两人的酒量(不超过100的...原创 2017-02-21 10:49:15 · 412 阅读 · 0 评论 -
抢红包
抢红包 没有人没抢过红包吧…… 这里给出NN个人之间互相发红包、抢红包的记录,请你统计一下他们抢红包的收获。输入格式:输入第一行给出一个正整数NN(\le 10^4≤104),即参与发红包和抢红包的总人数,则这些人从1到NN编号。随后NN行,第ii行给出编号为ii的人发红包的记录,格式如下:K\quad N_1\quad P_1\quad \cdots\quad N_K\q...原创 2017-02-21 19:02:03 · 1627 阅读 · 0 评论 -
正整数A+B
正整数A+B 题的目标很简单,就是求两个正整数A和B的和,其中A和B都在区间[1,1000]。稍微有点麻烦的是,输入并不保证是两个正整数。输入格式:输入在一行给出A和B,其间以空格分开。问题是A和B不一定是满足要求的正整数,有时候可能是超出范围的数字、负数、带小数点的实数、甚至是一堆乱码。注意:我们把输入中出现的第1个空格认为是A和B的分隔。题目保证至少存在一个空格,并且B不是一个...原创 2017-02-23 19:06:08 · 3422 阅读 · 1 评论 -
判断素数(Miller_Rabin算法)
判断素数 时间限制:400ms 内存限制:64MB 代码长度限制:16kB 判题程序:系统默认 作者:陈越 单位:浙江大学 本题的目标很简单,就是判断一个给定的正整数是否素数。 输入格式: 输入在第一行给出一个正整数N(\le≤ 10),随后N行,每行给出一个小于2^{31}231的需要判断的正整数。 输出格式: 对每个需要判断的正整数,如...原创 2017-02-23 19:35:30 · 2116 阅读 · 0 评论 -
一帮一(天梯赛)
一帮一 “一帮一学习小组”是中小学中常见的学习组织方式,老师把学习成绩靠前的学生跟学习成绩靠后的学生排在一组。本题就请你编写程序帮助老师自动完成这个分配工作,即在得到全班学生的排名后,在当前尚未分组的学生中,将名次最靠前的学生与名次最靠后的异性学生分为一组。输入格式:输入第一行给出正偶数N(\le≤50),即全班学生的人数。此后N行,按照名次从高到低的顺序给出每个学生的性别(0代表女...原创 2017-02-23 19:50:32 · 1988 阅读 · 0 评论 -
Can you find it? (二分)
Give you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate if you can find the three numbers Ai, Bj, Ck, which satisfy the formula Ai+Bj+Ck = X. InputThere...原创 2017-03-03 17:16:00 · 1917 阅读 · 0 评论 -
Boxes AtCoder - 2303
Problem Statement There are N boxes arranged in a circle. The i-th box contains Ai stones.Determine whether it is possible to remove all the stones from the boxes by repeatedly performing the fo...原创 2017-03-04 11:11:47 · 286 阅读 · 0 评论 -
GCD Again HDU - 1787 (欧拉函数 or 容斥原理)
Do you have spent some time to think and try to solve those unsolved problem after one ACM contest? No? Oh, you must do this when you want to become a "Big Cattle". Now you will find that this probl...原创 2017-03-05 21:41:25 · 250 阅读 · 0 评论 -
天梯赛--集合相似度
集合相似度 (25分)给定两个整数集合,它们的相似度定义为:N_c / N_t \times 100\%Nc/Nt×100%。其中N_cNc是两个集合都有的不相等整数的个数,N_tNt是两个集合一共有的不相等整数的个数。你的任务就是计算任意一对给定集合的相似度。输入格式:输入第一行给出一个正整数NN(\le 50≤50),是集合的个数。随后NN行,每行对应一...原创 2017-02-19 17:58:50 · 403 阅读 · 0 评论 -
N个数求和
5-1 N个数求和 (20分)本题的要求很简单,就是求N个数字的和。麻烦的是,这些数字是以有理数分子/分母的形式给出的,你输出的和也必须是有理数的形式。输入格式:输入第一行给出一个正整数N(\le≤100)。随后一行按格式a1/b1 a2/b2 ...给出N个有理数。题目保证所有分子和分母都在长整型范围内。另外,负数的符号一定出现在分子前面。输出格式:输出上述数字和的最简形...原创 2017-02-18 13:07:38 · 7086 阅读 · 0 评论 -
HOJ Leftmost Digit
http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2&sectionid=1&problemid=11 Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth...原创 2017-02-15 17:19:37 · 254 阅读 · 0 评论 -
POJ 3348 Cows 凸包
CowsTime Limit:2000MS Memory Limit:65536K Total Submissions:12101 Accepted:5243 DescriptionYour friend to the south is interested in building fences and turning plowshares ...原创 2019-07-11 16:47:42 · 624 阅读 · 0 评论 -
3. Longest Substring Without Repeating Characters --------- LeetCode
Given a string, find the length of the longest substring without repeating characters.Example 1:Input: "abcabcbb"Output: 3 Explanation: The answer is "abc", with the length of 3. Example 2:...原创 2019-02-26 22:05:32 · 119 阅读 · 0 评论 -
LeetCode 2. Add Two Numbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return i...原创 2019-02-26 20:43:08 · 105 阅读 · 0 评论 -
1001 A+B Format(20 分)
1001 A+B Format(20 分)Calculate a+b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).Input Spec...原创 2018-09-10 21:25:46 · 251 阅读 · 0 评论 -
1002 A+B for Polynomials(25 分) PAT 甲级
1002 A+B for Polynomials(25 分)This time, you are supposed to find A+B where A and B are two polynomials.Input Specification:Each input file contains one test case. Each case occupies 2 lines, an...原创 2018-09-10 22:10:27 · 215 阅读 · 0 评论 -
NOJ 1590 大整数阶乘
NOJ 1590 大整数阶乘#include <iostream>#include <cstdio>using namespace std;int a[50000];int main(){ int n; scanf("%d",&n); int i,j,digit; int tmp,carry; a[1]=1; d原创 2016-04-13 23:11:50 · 437 阅读 · 0 评论 -
NOJ 1010 记忆化搜索
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int dp[1005];int dfs(int cur){ if(dp[cur]>=0) return dp[cur]; int res=0; for(int i=0;2*i<=cur;i++) {原创 2016-04-21 14:45:41 · 378 阅读 · 0 评论 -
NOJ 1093 阶乘之和
NOJ 1093 阶乘之和原创 2016-11-26 00:23:07 · 567 阅读 · 0 评论 -
NOJ 1037模运算
快速幂取模原创 2016-11-26 00:37:38 · 320 阅读 · 0 评论 -
Renting Bikes CodeForces - 363D (二分算法+贪心)
A group of n schoolboys decided to ride bikes. As nobody of them has a bike, the boys need to rent them.The renting site offered them m bikes. The renting price is different for different b...原创 2017-03-02 15:48:43 · 415 阅读 · 0 评论 -
POJ 2965
POJ 2965原创 2016-12-04 12:20:51 · 395 阅读 · 0 评论 -
筛选法求素数表,并标记素数位置和合数最大质数位置 HOJ 2136
参考文章 http://www.cnblogs.com/Su-Blog/archive/2012/08/24/2654759.html素数筛选法可以标记出素数和非素数素数筛选法:1. const int size=10000000;int a[size+5];int main(){ int m=int(sqrt(size+0.5)); for(int...原创 2017-02-13 17:56:45 · 356 阅读 · 0 评论 -
HOJ 又见GCD 2.1.5
又见GCD Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3737 Accepted Submission(s): 1819 Problem Description 有三个正整数a,b...原创 2017-02-13 19:20:08 · 232 阅读 · 0 评论 -
HOJ 整数对
http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2&sectionid=1&problemid=9 整数对 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total...转载 2017-02-14 11:55:58 · 396 阅读 · 0 评论 -
disney (map模拟)
A new machine was introduced into disney world. Every day, there is a long queue because of its function. Everyone can input their score or update their score. If you want to know the maximum or the a...原创 2017-03-07 09:29:31 · 314 阅读 · 0 评论 -
数列求和-加强版
5-38 数列求和-加强版 (20分)给定某数字AA(1\le A\le 91≤A≤9)以及非负整数NN(0\le N\le 1000000≤N≤100000),求数列之和S = A + AA + AAA + \cdots + AA\cdots AS=A+AA+AAA+⋯+AA⋯A(NN个AA)。例如A=1A=1, N=3N=3时,S = 1 + 11 + 111 = 123S=1+11+...原创 2017-03-08 11:05:36 · 1016 阅读 · 0 评论 -
HDU - 1503 (DP)
The company "21st Century Fruits" has specialized in creating new sorts of fruits by transferring genes from one fruit into the genome of another one. Most times this method doesn't work, but sometime...原创 2017-03-10 16:39:33 · 283 阅读 · 0 评论 -
L3-010. 是否完全二叉搜索树
L3-010. 是否完全二叉搜索树时间限制400 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者陈越将一系列给定数字顺序插入一个初始为空的二叉搜索树(定义为左子树键值大,右子树键值小),你需要判断最后的树是否一棵完全二叉树,并且给出其层序遍历的结果。输入格式:输入第一行给出一个不超过20的正整数N;第二行给出N个...原创 2018-03-08 20:25:19 · 229 阅读 · 0 评论 -
PTA 重排链表
L2-022. 重排链表时间限制500 ms内存限制65536 kB代码长度限制8000 B判题程序Standard作者陈越给定一个单链表 L1→L2→...→Ln-1→Ln,请编写程序将链表重新排列为 Ln→L1→Ln-1→L2→...。例如:给定L为1→2→3→4→5→6,则输出应该为6→1→5→2→4→3。输入格式:每个输入包含1个测试用例...原创 2018-03-09 15:05:52 · 1481 阅读 · 1 评论 -
Dungeon Master POJ - 2251
Dungeon MasterTime Limit: 1000MS Memory Limit: 65536K Total Submissions: 45231 Accepted: 17070 DescriptionYou are trapped in a 3D dungeon and need to find the quickest way out!...原创 2018-05-24 16:08:35 · 162 阅读 · 0 评论 -
Catch That Cow POJ - 3278 BFS搜索
Catch That CowTime Limit: 2000MS Memory Limit: 65536K Total Submissions: 112355 Accepted: 35099 DescriptionFarmer John has been informed of the location of a fugitive cow and w...原创 2018-05-24 16:46:03 · 149 阅读 · 0 评论 -
Til the Cows Come Home (dijstra单源最短路)
Til the Cows Come HomeTime Limit: 1000MS Memory Limit: 65536K Total Submissions: 68738 Accepted: 23048 DescriptionBessie is out in the field and wants to get back to the barn t...原创 2018-05-24 19:48:56 · 166 阅读 · 0 评论 -
Frogger POJ - 2253 (二分搜索+图的连通性判断)
FroggerTime Limit: 1000MS Memory Limit: 65536K Total Submissions: 56014 Accepted: 17624 DescriptionFreddy Frog is sitting on a stone in the middle of a lake. Suddenly he notice...原创 2018-05-24 20:32:42 · 404 阅读 · 0 评论