- 博客(298)
- 资源 (2)
- 收藏
- 关注
原创 AP-Week6 Binomial Showdown
题目链接:Fudan Algorithm Practice (2) - Virtual JudgeIn how many ways can you choose k elements out of n elements, not taking order into account?Write a program to compute this number.InputThe input will contain one or more test cases.Each test case
2021-11-05 19:42:30 153
原创 AP-Week8 ID Codes
题目链接:Fudan Algorithm Practice (2) - Virtual Judge//https://vjudge.net/contest/466331#problem/A//2021-11-05 17:40-19.18#include <cstdio>#include <iostream>#include <algorithm>#include <cmath>#include <cstring>using
2021-11-05 19:22:36 150
原创 AP-Week5 The Hardest Problom Ever
题目链接:1298 -- The Hardest Problem EverThe Hardest Problem EverTime Limit: 1000MS Memory Limit: 10000K Total Submissions: 29440 Accepted: 15593 DescriptionJulius Caesar lived in a time of danger and intrigue. The hardest situation Cae
2021-10-26 14:51:23 107
原创 AP-Week1 Matches Game
题目链接:2234 -- Matches GameMatches GameTime Limit: 1000MS Memory Limit: 65536K Total Submissions: 14167 Accepted: 8189 DescriptionHere is a simple game. In this game, there are several piles of matches and two players. The two player
2021-10-06 10:14:12 119
原创 AP-Week1 Ants
题目链接:ZOJAntsTime Limit: 2000 msMemory Limit: 65536 KBAn army of ants walk on a horizontal pole of length l cm, each with a constant speed of 1 cm/s. When a walking ant reaches an end of the pole, it immediatelly falls off it. When two ants meet they
2021-10-06 09:27:53 126
原创 AP-Week1 Bridge
题目链接:ZOJBridgeTime Limit: 2000 msMemory Limit: 65536 KBn people wish to cross a bridge at night. A group of at most two people may cross at any time, and each group must have a flashlight. Only one flashlight is available among the n people, so some
2021-10-03 19:33:36 90
原创 AP-Week1 Factstone Benchmark
题目链接:ZOJFactstone BenchmarkTime Limit: 5000 msMemory Limit: 32768 KBAmtel has announced that it will release a 128-bit computer chip by 2010, a 256-bit computer by 2020, and so on, continuing its strategy of doubling the word-size every ten years..
2021-10-03 16:52:14 93
原创 递归实现全排列
问题 A: 【递归入门】全排列[命题人 : 外部导入]时间限制 : 1.000 sec内存限制 : 128 MB题目描述 排列与组合是常用的数学方法。先给一个正整数 ( 1 < = n < = 10 )例如n=3,所有组合,并且按字典序输出:1 2 31 3 22 1 32 3 13 1 23 2 1输入输入一个整数n( 1<=n<=10)输出输出所有全排列每个全排列一行,相邻两个数用空格隔开(最后一个数后面没有...
2021-03-26 22:51:57 120
原创 dp---放苹果
题目描述把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法。输入描述:每行均包含二个整数M和N,以空格分开。1<=M,N<=10。输出描述:对输入的每组数据M和N,用一行输出相应的K。示例1输入复制7 3输出复制8#include<cstdio>#pragma warning (disable:4996)using namespace
2021-03-25 21:31:30 106
原创 分数的四则运算和化简---1088 Rational Arithmetic (20 分)
1088 Rational Arithmetic (20 分)For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate their sum, difference, product and quotient.Input Specification:Each input file contains one test case, which gives in one
2021-03-23 08:58:29 105
原创 不用高大上的规律,暴力就可以---1021 Deepest Root (25 分)
1021 Deepest Root (25 分)A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a highest tree. Such a root is called the deepest root.I
2021-03-21 23:11:47 109
原创 dp---选物品凑成体积为40---递归或dp打表
题目描述有一个神奇的口袋,总的容积是40,用这个口袋可以变出一些物品,这些物品的总体积必须是40。John现在有n个想要得到的物品,每个物品的体积分别是a1,a2……an。John可以从这些物品中选择一些,如果选出的物体的总体积是40,那么利用这个神奇的口袋,John就可以得到这些物品。现在的问题是,John有多少种不同的选择物品的方式。输入描述:输入的第一行是正整数n (1 <= n <= 20),表示不同的物品的数目。接下来的n行,每行有一个1到40之间的正整数,分别给出a1,
2021-03-21 21:22:50 120
原创 bfs---最少交换次数
题目描述玛雅人有一种密码,如果字符串中出现连续的2012四个数字就能解开密码。给一个长度为N的字符串,(2=<N<=13)该字符串中只含有0,1,2三种数字,问这个字符串要移位几次才能解开密码,每次只能移动相邻的两个数字。例如02120经过一次移位,可以得到20120,01220,02210,02102,其中20120符合要求,因此输出为1.如果无论移位多少次都解不开密码,输出-1。输入描述:输入包含多组测试数据,每组测试数据由两行组成。第一行为一个整数N,代表字符串的长度(2&
2021-03-21 15:37:34 401
原创 dp---最大子矩阵---辅助数组用来保存任意连续行每列的和,然后对辅助数组任意两行相减后,求每行的连续最大字段和
题目描述已知矩阵的大小定义为矩阵中所有元素的和。给定一个矩阵,你的任务是找到最大的非空(大小至少是1 * 1)子矩阵。比如,如下4 * 4的矩阵0 -2 -7 09 2 -6 2-4 1 -4 1-1 8 0 -2的最大子矩阵是9 2-4 1-1 8这个子矩阵的大小是15。输入输入是一个N * N的矩阵。输入的第一行给出N (0 < N <= 100)。再后面的若干行中,依次(首先从左到右给出第一行的N个整数,再从左到右给出第二行的N个整数……)给出矩阵中的N2
2021-03-20 20:18:44 88
原创 dp---从前往后求最长递增+从后往前求最大递增。注意后者和从前往后求最大递减不一样
http://codeup.cn/problem.php?cid=100000632&pid=2题目描述N位同学站成一排,音乐老师要请其中的(N-K)位同学出列,使得剩下的K位同学不交换位置就能排成合唱队形。合唱队形是指这样的一种队形:设K位同学从左到右依次编号为1, 2, …, K,他们的身高分别为T1, T2, …, TK,则他们的身高满足T1 < T2 < … < Ti , Ti > Ti+1 > … > TK (1 <= i <=
2021-03-20 18:50:53 134
原创 dfs或dp---选最小邮票数凑成目标和
题目描述 有若干张邮票,要求从中选取最少的邮票张数凑成一个给定的总值。 如,有1分,3分,3分,3分,4分五张邮票,要求凑成10分,则使用3张邮票:3分、3分、4分即可。输入描述: 有多组数据,对于每组数据,首先是要求凑成的邮票总值M,M<100。然后是一个数N,N〈20,表示有N张邮票。接下来是N个正整数,分别表示这N张邮票的面值,且以升序排列。输出描述: 对于每组数据,能够凑成总值M的最少邮票张数。若无解,输出0。示例1输入复制...
2021-03-20 17:42:32 103
原创 dfs---选这个数or不选这个数两条路径
一个数组中有若干正整数,将此数组划分为两个子数组,使得两个子数组各元素之和a,b的差最小,对于非法输入应该输出ERROR。输入描述:数组中的元素输出描述:降序输出两个子数组的元素和示例1输入复制10 20 30 10 1010 20 abc 10 10输出复制40 40ERRORAC代码:#include<cstdio>#include<stdlib.h>#include<iostream>#incl
2021-03-20 10:29:56 133
原创 dp---最长不上升子序列
http://codeup.cn/problem.php?cid=100000632&pid=1#include<cstdio>#include<stdlib.h>#include<iostream>#include<algorithm>#include<cmath>#include<cstring>#pragma warning(disable:4996)using namespace std;#inc.
2021-03-20 10:11:41 182
原创 dp---前i天和后i天的利润最大和---4121:股票买卖
总时间限制:1000ms内存限制:65536kB描述最近越来越多的人都投身股市,阿福也有点心动了。谨记着“股市有风险,入市需谨慎”,阿福决定先来研究一下简化版的股票买卖问题。假设阿福已经准确预测出了某只股票在未来 N 天的价格,他希望买卖两次,使得获得的利润最高。为了计算简单起见,利润的计算方式为卖出的价格减去买入的价格。同一天可以进行多次买卖。但是在第一次买入之后,必须要先卖出,然后才可以第二次买入。现在,阿福想知道他最多可以获得多少利润。输入输入的第一行是一个整数
2021-03-17 09:22:33 184
原创 并查集---0 0 空树也是树--poj1308:Is It A Tree?
1308:Is It A Tree?查看 提交 统计 提示 提问总时间限制:1000ms内存限制:65536kB描述A tree is a well-known data structure that is either empty (null, void, nothing) or is a set of one or more nodes connected by directed edges between nodes satisfying the following
2021-03-16 22:00:54 75
原创 dp---完全背包---有几种加法方式
题目描述一个整数总可以拆分为2的幂的和,例如: 7=1+2+4 7=1+2+2+2 7=1+1+1+4 7=1+1+1+2+2 7=1+1+1+1+1+2 7=1+1+1+1+1+1+1 总共有六种不同的拆分方式。 再比如:4可以拆分成:4 = 4,4 = 1 + 1 + 1 + 1,4 = 2 + 2,4=1+1+2。 用f(n)表示n的不同拆分的种数,例如f(7)=6. 要求编写程序,读入n(不超过1000000),输出f(n)%1000000000。输入描述:每组输入包括一个整数:N(1
2021-03-16 19:18:36 117
原创 list的用法---约瑟王问题
n个猴子围圈报数,报道m的猴子退出剩下的重新报数。#include<cstdio>#include<stdlib.h>#include<iostream>#include<algorithm>#include<cmath>#include<cstring>#pragma warning(disable:4996)using namespace std;#include<string>#include&
2021-03-16 10:31:19 89
原创 贪心----Stall Reservations
Stall ReservationsTime Limit: 1000MS Memory Limit: 65536K Total Submissions: 18736 Accepted: 6502 Special Judge DescriptionOh those picky N (1 <= N <= 50,000) cows! They are so picky that each one will only be milked o...
2021-03-16 09:49:15 114
原创 区间贪心
#include<cstdio>#include<stdlib.h>#include<iostream>#include<algorithm>#include<cmath>#include<cstring>#pragma warning(disable:4996)using namespace std;#include<string>#include<vector>#include<m.
2021-03-15 16:25:25 90
原创 dp---1088:滑雪
总时间限制:1000ms内存限制:65536kB描述Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个区域中最长的滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子 1 2 3 4 516 17 18 19 615 24 25 20 714 23 22 21 813 12 11 10 9一个人可以从某个点滑向上
2021-03-14 20:07:05 74
原创 dp-n个物品装入容量为m的背包2755:神奇的口袋
总时间限制:10000ms内存限制:65536kB描述有一个神奇的口袋,总的容积是40,用这个口袋可以变出一些物品,这些物品的总体积必须是40。John现在有n个想要得到的物品,每个物品的体积分别是a1,a2……an。John可以从这些物品中选择一些,如果选出的物体的总体积是40,那么利用这个神奇的口袋,John就可以得到这些物品。现在的问题是,John有多少种不同的选择物品的方式。输入输入的第一行是正整数n (1 <= n <= 20),表示不同的物品的数目。接下来
2021-03-14 18:49:14 232
原创 dp-01背包---n个物品装入容量为m的背包,求最大价值。4131:Charm Bracelet
4131:Charm Bracelet查看 提交 统计 提示 提问总时间限制:1000ms内存限制:65536kB描述Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best charms possible from the N(1 ≤ N≤ 3,402) available charms. Ea
2021-03-14 18:30:40 204
原创 dp跳板,若为7ffffff则相加时会越界,然后WA!!需要复习poj-1661:帮助 Jimmy
总时间限制:1000ms内存限制:65536kB描述"Help Jimmy" 是在下图所示的场景上完成的游戏。场景中包括多个长度和高度各不相同的平台。地面是最低的平台,高度为零,长度无限。Jimmy老鼠在时刻0从高于所有平台的某处开始下落,它的下落速度始终为1米/秒。当Jimmy落到某个平台上时,游戏者选择让它向左还是向右跑,它跑动的速度也是1米/秒。当Jimmy跑到平台的边缘时,开始继续下落。Jimmy每次下落的高度不能超过MAX米,不然就会摔死,游戏也会结束。设计一个程
2021-03-14 12:48:23 104
原创 哈希表平方法探测,是在初始欲插入的位置上每次加某数平方,而不是每个新位置!---1078 Hashing (25 分)
另外还需要注意,平方探测msize次后若还没找到位置,才真的没有合适的位置。1078 Hashing (25 分)The task of this problem is simple: insert a sequence of distinct positive integers into a hash table, and output the positions of the input numbers. The hash function is defined to be H(key)=key
2021-03-03 19:12:23 177 1
原创 贪心+复杂模拟---1033 To Fill or Not to Fill (25 分)
1033 To Fill or Not to Fill (25 分)With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way from time to time. Different gas station may give d
2021-03-01 19:13:55 97
原创 螺旋矩阵填充最简单的方法--1105 Spiral Matrix (25 分)
矩阵 螺旋填充可以提前规定好上下左右四个方向,然后根据所在的位置是否越界或者是否已经被 填充过相应地改变方向。比如 dx=[1,0,-1,0], dy=[0,1,0,-1],设置初试方向 dir=0,每次移动的 时候只要当前位置加上对应的 dx 和 dy,要改变方向的时候就 dir=(dir+1)%4 就可以了,是否 填充满可以直接用填充数量判断。1105 Spiral Matrix (25 分)This time your job is to fill a sequence of N positi
2021-03-01 10:35:03 516
原创 string ans;想让ans后加数字,可以写成:ans+=char(a+‘0‘)--1136 A Delayed Palindrome (20 分)
1136 A Delayed Palindrome (20 分)Consider a positive integer N written in standard notation with k+1 digits ai as ak⋯a1a0 with 0≤ai<10 for all i and ak>0. Then N is palindromic if and only if ai=ak−i for all i. Zero is writte
2021-02-25 11:40:36 709
原创 【不太容易想】给出二叉树前序和中序,不建树的情况下求后序的第一个结点--1138 Postorder Traversal (25 分)
1138 Postorder Traversal (25 分)Suppose that all the keys in a binary tree are distinct positive integers. Given the preorder and inorder traversal sequences, you are supposed to output the first number of the postorder traversal sequence of the correspon
2021-02-25 09:34:27 134
原创 stirng不能直接scanf!!!!要么用cin,要么:string s; char tmp[20]; scanf(“%s“,tmp); s=string(tmp);但后者在这个题里会超时。
1153 Decode Registration Card of PAT (25 分)A registration card number of PAT consists of 4 parts:the 1st letter represents the test level, namely, T for the top level, A for advance and B for basic; the 2nd - 4th digits are the test site number, range
2021-02-24 12:38:15 109
原创 完全二叉树dfs打印路径--1155 Heap Paths (30 分)
1155 Heap Paths (30 分)In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (in a max heap) or less than or eq
2021-02-21 22:57:52 133
原创 kruskal算法模板---G - Jungle Roads
https://vjudge.net/problem/HDU-1301The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentlessly, so the large road
2021-02-19 19:57:05 112
原创 连通块个数---E - Lake Counting
Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains either water ('W') or dry land ('.'). Farmer John would li
2021-02-19 19:56:00 111
原创 线段树模板---D - Balanced Lineup
https://vjudge.net/problem/POJ-3264For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer John decides to organize a game of Ultimate Frisbee with some of the cows. To keep things simple, he will tak
2021-02-19 19:55:07 118
原创 螺旋填数问题,重点复习!题目有坑,空格是00000--B - Encoding
https://vjudge.net/problem/OpenJ_Bailian-3421Chip and Dale have devised an encryption method to hide their (written) text messages. They first agree secretly on two numbers that will be used as the number of rows (R) and columns (C) in a matrix. The send
2021-02-19 19:53:55 188
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人