题解
文章平均质量分 59
沐雨风栉
生活是一面镜子。你对它笑,它就对你笑;你对它哭,它也对你哭。
展开
-
日期差值 (日期问题板题)
日期差值 (日期问题板题)有两个日期,求两个日期之间的天数,如果两个日期是连续的我们规定他们之间的天数为两天输入描述:有多组数据,每组数据有两行,分别表示两个日期,形式为YYYYMMDD输出描述:每组数据输出一行,即日期差值输入2011041220110422输出11#include <iostream>#include <cstdio>using namespace std;// 判断闰年int is_leap(int y){ if (y %原创 2022-05-07 11:35:27 · 319 阅读 · 0 评论 -
任意进制转换
任意进制转换题目描述M和N(2<=M,N<=36)。下面的一行输入一个数X,X是M进制的数,现在要求你将M进制的数X转换成N进制的数输出。样例输入10 211样例输出1011提示注意输入时如有字母,则字母为大写,输出时如有字母,则字母为小写。实现代码#include<stdio.h>#include<string.h> int main(void){ int m,n,s1[110]; char s[110],ans[110]; char原创 2022-05-07 11:32:13 · 177 阅读 · 0 评论 -
M个梨子放N个盘子
M个梨子放N个盘子题目描述Macro非常喜欢吃梨,有一天他得到了ACMICPC组委会送给他的一筐梨子。他比较心疼学生,就打算把梨子分给学生吃。现在他要把M个梨子放到N个盘子里面 (我们允许有的盘子为空) ,你能告诉Macro有多少种分法吗?(请注意,如果有三个盘子,我们将5,1,1和1,1,5,视为同一种分法)输入第一行是一个整数t,代表有t组样例。第二行有两个整数M 和 N 代表有M个梨和N个盘子。输出输出有多少种方法样例输入17 3样例输出8思路m是梨子的个数,n是盘子的个原创 2022-05-07 11:26:58 · 268 阅读 · 0 评论 -
POJ - 1182 食物链(并查集)
动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。现有N个动物,以1-N编号。每个动物都是A,B,C中的一种,但是我们并不知道它到底是哪一种。有人用两种说法对这N个动物所构成的食物链关系进行描述:第一种说法是"1 X Y",表示X和Y是同类。第二种说法是"2 X Y",表示X吃Y。此人对N个动物,用上述两种说法,一句接一句地说出K句话,这K句话有的是真的,有的是假的。当一句话满足下列三条之一时,这句话就是假话,否则就是真话。1) 当前的话与前面的某些真原创 2021-01-24 12:34:41 · 150 阅读 · 0 评论 -
POJ 1598 Excuses, Excuses!
Judge Ito is having a problem with people subpoenaed for jury duty giving rather lame excuses in order to avoid serving. In order to reduce the amount of time required listening to goofy excuses, Judge Ito has asked that you write a program that will searc原创 2021-01-25 02:04:03 · 129 阅读 · 0 评论 -
HDU - 1716 排列2(暴力;next_permutation)
Ray又对数字的列产生了兴趣:现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数。Input每组数据占一行,代表四张卡片上的数字(0<=数字<=9),如果四张卡片都是0,则输入结束。Output对每组卡片按从小到大的顺序输出所有能由这四张卡片组成的4位数,千位数字相同的在同一行,同一行中每个四位数间用空格分隔。每组输出数据间空一行,最后一组数据后面没有空行。Sample Input1 2 3 41 1 2 30 1 2 30 0 0 0原创 2021-01-24 15:46:44 · 162 阅读 · 0 评论 -
HDU-2061 汉诺塔III (简单DP)
约19世纪末,在欧州的商店中出售一种智力玩具,在一块铜板上有三根杆,最左边的杆上自上而下、由小到大顺序串着由64个圆盘构成的塔。目的是将最左边杆上的盘全部移到右边的杆上,条件是一次只能移动一个盘,且不允许大盘放在小盘的上面。现在我们改变游戏的玩法,不允许直接从最左(右)边移到最右(左)边(每次移动一定是移到中间杆或从中间移出),也不允许大盘放到下盘的上面。Daisy已经做过原来的汉诺塔问题和汉诺塔II,但碰到这个问题时,她想了很久都不能解决,现在请你帮助她。现在有N个圆盘,她至少多少次移动才能把这些圆盘原创 2021-10-25 17:11:32 · 228 阅读 · 0 评论 -
POJ - 3278 Catch That Cow(BFS——广度优先搜索)
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,000) on a number line and the cow is at a point K (0 ≤ K ≤ 100,000) on the same number line. Farmer John has two modes o原创 2021-10-26 22:00:54 · 77 阅读 · 0 评论 -
POJ - 2325 Persistent Numbers
The multiplicative persistence of a number is defined by Neil Sloane (Neil J.A. Sloane in The Persistence of a Number published in Journal of Recreational Mathematics 6, 1973, pp. 97-98., 1973) as the number of steps to reach a one-digit number when repeat原创 2021-01-24 18:33:08 · 233 阅读 · 1 评论 -
Pseudoprime numbers(快速幂模板题)
Fermat’s theorem states that for any prime number p and for any integer a > 1, ap = a (mod p). That is, if we raise a to the pth power and divide by p, the remainder is a. Some (but not very many) non-prime values of p, known as base-a pseudoprimes, hav原创 2021-01-18 01:04:03 · 139 阅读 · 0 评论 -
C - 一只小蜜蜂...
有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行。请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数。其中,蜂房的结构如下所示。Input输入数据的第一行是一个整数N,表示测试实例的个数,然后是N 行数据,每行包含两个整数a和b(0<a<b<50)。Output对于每个测试实例,请输出蜜蜂从蜂房a爬到蜂房b的可能路线数,每个实例的输出占一行。Sample Input21 23 6Sample Output13看图可知,由于蜜蜂每次只能从前1个蜂房前2个蜂房过来原创 2021-02-10 21:15:37 · 602 阅读 · 0 评论 -
火星A+B
分析:模拟加法操作。我们拿样例中的 4,2,0 1,2,0来说:个位:0+0=0 该位值ans=0%2=0,进位e=0/2=0;十位:2+2+e=4 该位值ans=4%3=1 进位e=4/3=1;百位:4+1+e=6 该位值ans=6%5=1 进位e=6/5=1;注意到此时进位e不为0,再向高位进e:千位值为e=1/*使用进制转换太过于麻烦,直接用了加法模拟一下就可以了*/#include<bits/stdc++.h>int a[1000],b[1000],s[10原创 2021-01-15 22:16:38 · 197 阅读 · 0 评论 -
HDU - 1312 Red and Black(DFS)
There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can’t move on red tiles, he can move only on black tiles.Wr原创 2021-10-26 21:56:07 · 117 阅读 · 0 评论 -
HDU 1106 排序
555556 //开头有5的1555556 //中间有一堆5的125 //5结尾的55552345891 //不是5结尾的1234 //没有5的12345531232 //不是5结尾的#include<stdio.h>#include<string.h>#include<algorithm>using namespace std; char a[10000];int b[10000];int main(){ while(scanf("%s",原创 2021-09-01 21:27:45 · 69 阅读 · 0 评论 -
POJ - 1190 生日蛋糕(DFS+剪枝)
POJ - 1190 生日蛋糕Description:7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层生日蛋糕,每层都是一个圆柱体。设从下往上数第i(1 <= i <= M)层蛋糕是半径为Ri, 高度为Hi的圆柱。当i < M时,要求Ri > Ri+1且Hi > Hi+1。由于要在蛋糕上抹奶油,为尽可能节约经费,我们希望蛋糕外表面(最下一层的下底面除外)的面积Q最小。令Q = Sπ请编程对给出的N和M,找出蛋糕的制作方案(适当的Ri和Hi的值原创 2020-07-19 14:51:23 · 223 阅读 · 0 评论 -
HDU - 1016 Prime Ring Problem(解题报告 素数环——dfs基础题)
HDU - 1016 Prime Ring Problem(解题报告 素数环——dfs基础题)A ring is compose of n circles as shown in diagram. Put natural number1, 2, …, n into each circle separately, and the sum of numbers in twoadjacent circles should be a prime.Note: the number of first circ原创 2020-09-29 23:07:36 · 182 阅读 · 0 评论 -
POJ - 1562 Oil Deposits(油田——dfs)
Problem DescriptionThe GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. I原创 2020-09-29 23:18:44 · 141 阅读 · 0 评论 -
畅通工程续 HDU - 1874 (Dijkstra)
某省自从实行了很多年的畅通工程计划后,终于修建了很多路。不过路多了也不好,每次要从一个城镇到另一个城镇时,都有许多种道路方案可以选择,而某些方案要比另一些方案行走的距离要短很多。这让行人很困扰。现在,已知起点和终点,请你计算出要从起点到终点,最短需要行走多少距离。Input本题目包含多组数据,请处理到文件结束。每组数据第一行包含两个正整数N和M(0<N<200,0<M<1000),分别代表现有城镇的数目和已修建的道路的数目。城镇分别以0~N-1编号。接下来是M行道路信息。每原创 2020-10-14 16:28:37 · 157 阅读 · 0 评论 -
POJ - 3253 Fence Repair(哈夫曼树,优先队列)
题目:Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needs N (1 ≤ N ≤20,000) planks of wood, each having some integer length Li (1 ≤ Li ≤ 50,000) units. He then purchases a single long boar原创 2021-07-25 18:06:57 · 114 阅读 · 2 评论 -
HDU - 2553 N皇后问题(经典问题DFS)
在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上。你的任务是,对于给定的N,求出有多少种合法的放置方法。Input共有若干行,每行一个正整数N≤10,表示棋盘和皇后的数量;如果N=0,表示结束。Output共有若干行,每行一个正整数,表示对应输入行的皇后的不同放置数量。185019210。原创 2021-10-25 17:36:30 · 117 阅读 · 0 评论 -
HDU - 1200 To and Fro
Mo and Larry have devised a way of encrypting messages. They first decide secretly on the number of columns and write the message (letters only) down the columns, padding with extra random letters so as to make a rectangular array of letters. For example,原创 2021-01-24 15:55:52 · 115 阅读 · 0 评论 -
POJ - 1837 Balance (DP——背包问题)
Gigel has a strange “balance” and he wants to poise it. Actually, the device is different from any other ordinary balance.It orders two arms of negligible weight and each arm’s length is 15. Some hooks are attached to these arms and Gigel wants to hang up原创 2021-10-25 17:45:52 · 156 阅读 · 0 评论 -
POJ - 3259 Wormholes
While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time that is BEFORE you entered the wormhole! Each of FJ’s farms co原创 2021-10-26 22:16:24 · 102 阅读 · 0 评论 -
HDU - 1020 Encoding
Given a string containing only ‘A’ - ‘Z’, we could encode it using the following method:Each sub-string containing k same characters should be encoded to “kX” where “X” is the only character in this sub-string.If the length of the sub-string is 1, ‘1原创 2021-01-24 19:26:34 · 148 阅读 · 0 评论 -
POJ 1302 Blue Gene, Jr.(递归实现)
Inspired by IBM's Blue Gene project, the CEO of Universal Biological Machinery (UBM), has called on you, UBM's top software engineer, to develop a program that will calculate the mutation of the Areopagus-virus, a virus discovered on Mars by your company's原创 2020-07-26 18:54:27 · 207 阅读 · 1 评论 -
POJ 1251 Jungle Roads (最小生成树 prime )
POJ 1251 Jungle Roads The 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 network is too原创 2020-07-19 15:40:39 · 120 阅读 · 1 评论 -
计蒜客 - T1145 输出最高分数的学生姓名 (结构体排序)
输入学生的人数,然后再输入每位学生的分数和姓名,求获得最高分数的学生的姓名。输入格式第一行输入一个正整数N(N≤100),表示学生人数。接着输入N行,每行格式如下:分数 姓名分数是一个非负整数,且小于等于100;姓名为一个连续的字符串,中间没有空格,长度不超过20。数据保证最高分只有一位同学。输出格式获得最高分数同学的姓名。Sample Input587 lilei99 hanmeimei97 lily96 lucy77 jimSample Outp原创 2021-10-25 17:24:17 · 308 阅读 · 0 评论 -
最短路 HDU - 2544 (Dijkstra)
在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt。但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店到赛场的路线,你可以帮助他们吗?Input输入包括多组数据。每组数据第一行是两个整数N、M(N<=100,M<=10000),N表示成都的大街上有几个路口,标号为1的路口是商店所在地,标号为N的路口是赛场所在地,M则表示在成都有几条路。N=M=0表示输入结束。接下来M行,每行包括3个整数A,B,C(1<=A,B&原创 2020-10-14 16:32:10 · 195 阅读 · 0 评论 -
POJ 3259 Wormholes(最短路——Bellman-ford)
A - WormholesWhile exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time that is BEFORE you entered the wormhole! Each of原创 2020-08-02 23:36:18 · 207 阅读 · 0 评论 -
N - Crossing River
A group of N people wishes to go across a river with only one boat, which can at most carry two persons. Therefore some sort of shuttle arrangement must be arranged in order to row the boat back and forth so that all people may cross. Each person has a dif原创 2021-01-18 00:44:06 · 107 阅读 · 0 评论 -
POJ - 1129 Channel Allocation(染色问题)
When a radio station is broadcasting over a very large area, repeaters are used to retransmit the signal so that every receiver has a strong signal. However, the channels used by each repeater must be carefully chosen so that nearby repeaters do not interf原创 2021-10-26 22:06:58 · 94 阅读 · 0 评论 -
HDU - 1715 大菲波数(大数)
Fibonacci数列,定义如下:f(1)=f(2)=1f(n)=f(n-1)+f(n-2) n>=3。计算第n项Fibonacci数值。Input输入第一行为一个整数N,接下来N行为整数Pi(1<=Pi<=1000)。Output输出为N行,每行为对应的f(Pi)。Sample Input512345Sample Output11235解题报告:#include<stdio.h>int f[1005][605]; int ma原创 2021-01-24 19:43:23 · 130 阅读 · 0 评论 -
POJ - 2531 Network Saboteur
A university network is composed of N computers. System administrators gathered information on the traffic between nodes, and carefully divided the network into two subnetworks in order to minimize traffic between parts.A disgruntled computer science stud原创 2021-10-26 21:51:56 · 106 阅读 · 0 评论 -
HDU - 1002 A + B Problem II
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 number of test cases. Then T lines follow, each line consis原创 2021-01-24 18:59:19 · 128 阅读 · 0 评论 -
HDU - 2100 Lovekey
XYZ-26进制数是一个每位都是大写字母的数字。 A、B、C、…、X、Y、Z 分别依次代表一个0 ~ 25 的数字,一个 n 位的26进制数转化成是10进制的规则如下A0A1A2A3…An-1 的每一位代表的数字为a0a1a2a3…an-1 ,则该XYZ-26进制数的10进制值就为m = a0 * 26^(n-1) + a1 * 26^(n-2) + … + an-3* 26^2 + an-2*26 + an-1一天vivi忽然玩起了浪漫,要躲在学校的一个教室,让枫冰叶子去找,当然,她也知道枫冰叶子可原创 2021-01-24 18:05:39 · 118 阅读 · 0 评论 -
HDU - 3789 奥运排序问题(暴力)
按要求,给国家进行排名。Input有多组数据。第一行给出国家数N,要求排名的国家数M,国家号从0到N-1。第二行开始的N行给定国家或地区的奥运金牌数,奖牌数,人口数(百万)。接下来一行给出M个国家号。Output排序有4种方式: 金牌总数 奖牌总数 金牌人口比例 奖牌人口比例对每个国家给出最佳排名排名方式 和 最终排名格式为: 排名:排名方式如果有相同的最终排名,则输出排名方式最小的那种排名,对于排名方式,金牌总数 < 奖牌总数 < 金牌人口比例 < 奖牌人口比例如果原创 2021-10-25 17:12:40 · 82 阅读 · 0 评论 -
HDU - 1753 大明A+B(高精度大数运算)
话说,经过了漫长的一个多月,小明已经成长了许多,所以他改了一个名字叫“大明”。这时他已经不是那个只会做100以内加法的那个“小明”了,现在他甚至会任意长度的正小数的加法。现在,给你两个正的小数A和B,你的任务是代表大明计算出A+B的值。Input本题目包含多组测试数据,请处理到文件结束。每一组测试数据在一行里面包含两个长度不大于400的正小数A和B。Output请在一行里面输出输出A+B的值,请输出最简形式。详细要求请见Sample Output。Sample Input1.1 2.91原创 2021-01-24 12:50:02 · 181 阅读 · 0 评论 -
B - 骨牌铺方格
在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数.例如n=3时,为2× 3方格,骨牌的铺放方案有三种,如下图:Input输入数据由多行组成,每行包含一个整数n,表示该测试实例的长方形方格的规格是2×n (0<n<=50)。Output对于每个测试实例,请输出铺放方案的总数,每个实例的输出占一行。Sample Input132Sample Output132#include<stdio.h> long long in原创 2021-02-10 21:17:43 · 118 阅读 · 0 评论 -
51Nod - 2000 四边形分割平面(简单DP)
用N个四边方形最多可以把平面分成几个区域?Input第一行输入一个整数T,表示数据组数(1<=T<=10000); 第二行输入一个正整数n(1<=n<=1000);Output对于每组数据,请输出结果。Sample Input212Sample Output210通项公式为an=4n2-4n+2;#include<stdio.h> long long int dp[55];int main(){ long long int i,n,m,a原创 2021-10-25 17:30:27 · 129 阅读 · 0 评论 -
Tree Recovery(已知先序和中序求后序遍历二叉树)
题目Little Valentine liked playing with binary trees very much. Her favorite game was constructing randomly looking binary trees with capital letters in the nodes.This is an example of one of her creations: D原创 2021-01-15 17:30:14 · 181 阅读 · 0 评论