![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
刷题
Tw_light
这个作者很懒,什么都没留下…
展开
-
POJ 3087 Shuffle‘m Up
题目:http://poj.org/problem?id=3087两堆牌s1,s2,每堆牌都有c张,现按一张s2最底下的牌,一张s1最底下的牌交叉堆叠,问堆叠好后是否能得到想要的顺序,若能得到,输出堆叠的次数,若不能,将堆好的牌下半部分c张当作s1,上半部分当作s2,重新堆叠,若无法得到想要的顺序,输出“-1”。#include<iostream>#include<algorithm>#include<cstring>#include<string&g原创 2020-07-20 08:44:41 · 125 阅读 · 0 评论 -
P1030 求先序排列
题目:https://www.luogu.com.cn/problem/P1030给出一颗二叉树的中序和后序,输出它的先序(结点用不同的大写字母表示,长度<=8)前序遍历:[根 [左子树先序遍历结果] [右子树先序遍历结果]]中序遍历:[[左子树中序遍历结果] 根 [右子树中序遍历结果]]后序遍历:[[左子树后序遍历结果] [右子树后序遍历结果] 根]首先确定根结点:在后序遍历中,最后一个是根结点,在中序遍历中找到根结点,建立左子树,建立右子树,至于如何建立左子树和右子树?请重新再读原创 2020-05-22 16:49:31 · 141 阅读 · 0 评论 -
POJ 3468【线段树,懒惰标记】
题目:http://poj.org/problem?id=3468给出N个整数,进行M次询问,C a b c 表示给区间[a, b]中的每一个数加上c, Q a b 表示询问区间[a, b] 的和#include<iostream>#include<algorithm>#include<cstring>#include<string>#include<cstdio>#define ll long long intusing na原创 2020-05-18 09:09:30 · 182 阅读 · 0 评论 -
HDU1166敌兵布阵【线段树】
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1166#include<iostream>#include<algorithm>#include<cstring>#include<string>#include<cstdio>using namespace std;const int INF = 0x3f3f3f3f;const int MAXN = 1e5 + 7;int T, n;原创 2020-05-13 11:08:35 · 122 阅读 · 0 评论 -
Elections (枚举)
题目:http://codeforces.com/problemset/problem/1020/Cn个人,m支队伍,每个人给一支队伍投票,使这个人改变主意需要花费val元,问为使1号队伍获胜,最少需要花费多少元?枚举1号队获胜所需的票数#include<iostream>#include<algorithm>#include<cstring>...原创 2020-05-01 10:33:18 · 239 阅读 · 0 评论 -
数组中的逆序对 leetcode
题目:https://leetcode-cn.com/problems/shu-zu-zhong-de-ni-xu-dui-lcof/归并排序求逆序对AC代码class Solution {private: int ans = 0;public: void merge_sort(int l, int r, vector<int>& nums, ve...原创 2020-04-24 19:48:05 · 232 阅读 · 0 评论 -
HDU Today HDU2112 (dijkstra, 优先队列)
题目:HDU Today#include<iostream>#include<algorithm>#include<cstring>#include<string>#include<cstdio>#include<map>#include<queue>using namespace std;con...原创 2020-04-20 20:19:44 · 126 阅读 · 0 评论 -
Wormholes POJ3259 (spfa)
题目:http://poj.org/problem?id=3259题目大意:F组数据, 输入n, m, w,表示n块田地, m个田与田之间的关系,w个虫洞,从一块田到达另一块田需要花一定时间, 穿过虫洞时时间会倒流,问是否能够回到出发前的时间解题思路:判断是否存在负环,若存在则一定能够回去。#include<cstdio>#include<cstring>#inc...原创 2020-04-17 10:44:07 · 127 阅读 · 0 评论 -
P1316 丢瓶盖(二分)
题目:https://www.luogu.com.cn/problem/P1316A个点再一条直线上,从中挑选B个,使得距离最近的2个距离最大,问距离最大可以是多少?Solve: 二分答案#include<bits/stdc++.h>using namespace std;const int INF = 0x3f3f3f3f;const int MAXN = 1e5 +...原创 2020-01-28 17:42:17 · 193 阅读 · 0 评论 -
P1182 数列分段 Section II(二分)
题目:https://www.luogu.com.cn/problem/P1182对于给定的一个长度为N的正整数数列 A1∼NA_{1\sim N}A1∼N ,现要将其分成 M(M ≤ N)段,并要求每段连续,且每段和的最大值最小。Solve:显然的最大值最小化问题,用二分。枚举答案,枚举的范围:只要从数组中最大的那个数枚举到所有数的和就行了。#include<bits/std...原创 2020-01-28 17:02:34 · 195 阅读 · 0 评论 -
P1135 奇怪的电梯(dfs/bfs)
题目:https://www.luogu.com.cn/problem/P1135solve1:dfs#include<bits/stdc++.h>using namespace std;const int INF = 0x3f3f3f3f;const int MAXN = 210;int N, A, B;int k[MAXN];int ans = INF;int b...原创 2020-01-28 11:27:47 · 589 阅读 · 0 评论 -
P1025 数的划分(dfs/dp)
题目:https://www.luogu.com.cn/problem/P1025题目描述:将整数n分成k份,且每份不能为空,任意两个方案不相同(不考虑顺序)。例如:n=7,k=3,下面三种分法被认为是相同的。1,1,5;1,5,1;5,1,1;问有多少种不同的分法。 (6 < n <= 200, 2 <= k <= 6)solve1: dfs要把n...原创 2020-01-27 12:15:22 · 382 阅读 · 1 评论 -
P1908 逆序对 (归并排序,树状数组)
题目:https://www.luogu.com.cn/problem/P1908solve1:归并排序归并排序就是递归将原来的序列不断二分,分到不能再分,然后将左右子区间排序合并(合并时左右区间各自都已经有序了)得到逆序对的关键代码:ans += mid - i + 1;归并排序将左右区间合并时,左右区间已经是有序了的,所以只需要统计右区间中每一个数与左区间会产生多少逆序对就好了。...原创 2020-01-24 15:24:01 · 337 阅读 · 0 评论 -
P1071 潜伏者 (字符串)
题目:https://www.luogu.com.cn/problem/P1071错题笔记: 原代码下面样例没过ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYAABCD正确答案:Failed错误答案:ABCD这是因为第二个字符串中A对应了两次,题目要求每个字母只对应一个唯一的“密字”,不同的字母对应不同的“密字”。“密字”...原创 2020-01-19 11:45:53 · 229 阅读 · 0 评论 -
Making Money(完全背包)
题目:https://ac.nowcoder.com/acm/contest/3186/D描述:有n种物品(1 <= n <= 100),每种物品个数不限,给出每一种物品的进价和售价。现在有m元钱,用这些钱去进货并卖出货物(m元进货时可以不全部花完),问最后总共能有多少钱?(每种物品的利润 = (该物售价 - 该物进价)* 该物卖出的数量)code:#include<...原创 2019-12-16 10:55:21 · 156 阅读 · 0 评论 -
HDU1757 A Simple Math Problem (矩阵快速幂)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1757题目描述:函数f(x)满足如下条件:x<10时,f(x)=x;x < 10时,f(x)=x;x<10时,f(x)=x;x>=10时,f(x)=a0∗f(x−1)+a1∗f(x−2)+...+a9∗f(x−10)x >= 10时, f(x)=a_0*f(x-1)+ a...原创 2020-01-18 16:31:55 · 121 阅读 · 0 评论 -
HDU1575 Tr A(矩阵快速幂)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1575题目描述:A为一个方阵,则Tr A表示A的迹(就是主对角线上各项的和),现要求Tr(A^k)%9973。解题方法:矩阵快速幂code:#include<iostream>#include<algorithm>#include<cstring>#incl...原创 2020-01-18 16:14:59 · 154 阅读 · 0 评论 -
poj3070 - Fibonacci(矩阵快速幂)
题目:http://poj.org/problem?id=3070题目大意:输入n,求矩阵(1110)n输入n,求矩阵\begin{pmatrix}1 & 1 \\1 & 0 \end{pmatrix} ^n输入n,求矩阵(1110)ncode:#include<iostream>#include<algorithm>#inc...原创 2020-01-18 16:06:46 · 145 阅读 · 0 评论