ICode9

精准搜索请尝试: 精确搜索
  • Leetcode之深度优先搜索(DFS)专题-559. N叉树的最大深度(Maximum Depth of N-ary Tree)2019-08-16 17:08:06

    Leetcode之深度优先搜索(DFS)专题-559. N叉树的最大深度(Maximum Depth of N-ary Tree) 深度优先搜索的解题详细介绍,点击 给定一个 N 叉树,找到其最大深度。 最大深度是指从根节点到最远叶子节点的最长路径上的节点总数。 例如,给定一个 3叉树 :     我们应返回其最大深度,3。 说明

  • 【NOI2014】魔法森林2019-08-15 09:52:38

    Description 给定一张无向图,边有a,b两种边权,求一条1~n的路径,使得路径上a最大值与b最大值之和尽可能小 Solution LCT维护生成树 将边按照a从小到大排序,然后顺序考虑每一条边 如果当前这条边的两个端点没有联通,那么直接在LCT上连边即可 如果当前这条边的两个端点已经连通,那么在LCT上找

  • 牛客练习赛 4 A-Laptop (线段树,思维)2019-08-07 14:04:41

    链接:https://ac.nowcoder.com/acm/contest/16/A?&headNav=www 来源:牛客网 题目描述 FST是一名可怜的小朋友,他很强,但是经常fst,所以rating一直低迷。 但是重点在于,他非常适合ACM!并在最近的区域赛中获得了不错的成绩。 拿到奖金后FST决定买一台新笔记本,但是FST发现,在价格能承

  • 题解 P3431 洛谷【[POI2005]AUT-The Bus】2019-08-06 12:01:22

    题面: Byte City 的街道形成了一个标准的棋盘网络 – 他们要么是北南走向要么就是西东走向. 北南走向的路口从 1 到 n编号, 西东走向的路从1 到 m编号. 每个路口用两个数(i, j) 表示(1 <= i <= n, 1 <= j <= m). Byte City里有一条公交线, 在某一些路口设置了公交站点. 公交车从 (1,

  • 题解 洛谷P4644 【[Usaco2005 Dec]Cleaning Shifts 清理牛棚】2019-08-06 12:00:35

    这道题本身只是一道比较水的dp,但是……它会卡O(n^2)的算法!!! 所以,我们可以用数据结构优化!我用的线段树(单修区查多好写呀) 要注意几点:1.dp数组在起点要清零2.循环取最小值时是从t[i].l-1到t[i].r3.线段树minn要取最大4.区间排序按右端点排 先上70分代码(我先得了100分为了题解再亲测

  • P3567 [POI2014]KUR-Couriers 主席树2019-08-02 21:03:24

    给一个数列,每次询问一个区间内有没有一个数出现次数超过一半   主席树水题 // luogu-judger-enable-o2#include<bits/stdc++.h>using namespace std;//input by bxd#define rep(i,a,b) for(int i=(a);i<=(b);i++)#define repp(i,a,b) for(int i=(a);i>=(b);--i)#define ll long

  • LeetCode 53. 最大子序和 (java)2019-08-01 22:50:59

    动态规划类题目,定义了两个变量a和maxx,a用来记录每个数及之前的数相加的最大值,既dp[i],如果dp[i-1]>0,那么dp[i]+dp[i-1]一定大于dp[i],反之小于,所以只需要每次判断a是否大于0,更新a的值,并判断a与maxx大小,更新maxx。   class Solution { public int maxSubArray(int[] nums) {

  • poj2392多重背包2019-07-30 13:37:03

    #include <iostream> #include <algorithm> #include <cstdio> #include <string.h> using namespace std; const int INF = 99999999; struct node{ int x; int y; int z; }; node a[4005]; int dp[400000]; int Count[400005]; bool cm

  • 线段树专题2019-07-29 17:05:08

    先来一个通用的模板 typedef long long ll; const int maxn = 2e5 + 10; struct node { ll x,minn,maxx,sum,f; }tree[4 * maxn]; //结构体开4倍空间 ll n,a[maxn],m; ll x,y,s,op; void build(int x,int l,int r) //建树 build(1,1,n); { if(l == r) {

  • Luogu4085 [USACO17DEC]Haybale Feast (线段树,单调队列)2019-07-27 09:00:08

    \(10^18\)是要long long的。 \(nlogn\)单调队列上维护\(logn\)线段树。 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define R(a,b,c) for(register int a = (b); a <= (c); ++ a) #define n

  • splay区间操作(bzoj1500)2019-07-24 19:54:19

    传送门 其实这道题思路还是满简单的,只是代码量和debug让人感到痛苦,但还是蛮锻炼能力的 还是说说各个操作 插入 不同普通题的是,插入是插入一段。如果一个一个插的话会很慢,我们可以先把要插入的一段建成一个平衡树,再一起插入。 删除 删除也是删除一段区间[L,R],我们可以把L-1旋转到根,R

  • HDU-1423-Greatest Common Increasing Subsequence-最长公共上升子序列【模版】2019-07-24 09:00:43

    This is a problem from ZOJ 2432.To make it easyer,you just need output the length of the subsequence. InputEach sequence is described with M - its length (1 <= M <= 500) and M integer numbers Ai (-2^31 <= Ai < 2^31) - the sequence itself.Outpu

  • 单调队列——POJ - 28232019-07-21 19:06:27

    题目含义 给出一个区间的长度,要你在一堆数中移动这个区间(保持区间长度不变),找出对应的最大最小值  题目解析 这个区间在向右移动,那么时时刻刻有数离开这个区间,有数加入这个区间,这样的话可以考虑单调队列 把这些数按从大到小的顺序放入一个数组,并且从大到小判断这个数是否满足在这个

  • Linq查找最大值max最小值min效率比较2019-07-18 14:51:51

    对linq查找极值的几种方法做一个效率上的比较 // 首先创建了一个10_000_000大小的PointF列表 var rdn = new Random(); var points = Enumerable .Range(0, 10_000_000) .Select(t => new PointF((float)rdn.NextDouble() * 200, (float)rdn.NextDouble() * 200))

  • 奇袭2019-07-17 11:55:45

    https://blog.csdn.net/sadnohappy/article/details/52199051 https://www.cnblogs.com/12mango/p/7465667.html 耐心看完这两篇博客相信你已经大概理解了。 以下是我自己的一些理解, 首先 $n^3$算法   无脑维护前缀和 MLE+TLE 1 #include<bits/stdc++.h> 2 #define ll long lon

  • 动态数组建树2019-07-15 10:43:21

    Tree Problem Description wls 有三棵树,树上每个节点都有一个值 ai,现在有 2 种操作: 将一条链上的所有节点的值开根号向下取整; 求一条链上值的和; 链的定义是两点之间的最短路。 Input 第一行两个数 n, q 分别代表树上点的数量和操作数量。 第二行 n 个整数,第 i 个数代表第

  • HDU 1856 More is better2019-07-06 18:54:14

    题目: Problem Description Mr Wang wants some boys to help him with a project. Because the project is rather complex, the more boys come, the better it will be. Of course there are certain requirements.Mr Wang selected a room big enough to hold the boys. The

  • Educational Codeforces Round 2 E. Lomsat gelral(dsu)2019-07-03 16:44:01

    题目链接 题意:给你一棵以1为根n个点的树,问你以i为根的子树的众数和是多少 思路:dsu是一种优化暴力的手段 首先进行轻重链剖分 然后只记录重链的信息 轻链的信息就直接暴力查找 经过证明这样复杂度可以是nlogn。 #include<bits/stdc++.h>#define ll long long intusing namesp

  • C++ | 函数模板2019-07-02 19:54:07

      1 #include<iostream> 2 using namespace std; 3 template<class T> 4 T maxx(T x, T y) { 5 return x > y ? x : y; 6 } 7 8 9 int main() {10 int a = 1, b = 2;11 double c = 3.0, d = 4.0;12 cout << max(a,b)<< endl;1

  • 2019 计蒜之道 复赛2019-06-22 20:02:22

    A题:外教 Michale 变身大熊猫 题目链接:https://nanti.jisuanke.com/t/39611 题解: #include<bits/stdc++.h>using namespace std;typedef long long LL;const int maxx = 5e5+10;const int mod = 998244353;struct node{LL len,num;}tree[maxx];int a[maxx],s[maxx];LL len1[maxx

  • 期望dp+高斯消元——bzoj31432019-06-20 12:39:35

    比较经典的题,题解看网上的。。https://www.cnblogs.com/GXZlegend/p/7054536.html 自己sort弄错了。。还以为是高斯消元写歪了。。 #include<bits/stdc++.h>using namespace std;const int maxn = 505;const double esp = 1e-10;struct Edge{int u,v;double E;}e[maxn*maxn];int m

  • Leetcode 695.岛屿的最大面积2019-06-15 12:47:50

    给定一个包含了一些 0 和 1的非空二维数组 grid , 一个 岛屿 是由四个方向 (水平或垂直) 的 1 (代表土地) 构成的组合。你可以假设二维矩阵的四个边缘都被水包围着。 找到给定的二维数组中最大的岛屿面积。(如果没有岛屿,则返回面积为0。) 示例 1: [[0,0,1,0,0,0,0,1,0,0,0,0

  • 一本通 1280:【例9.24】滑雪2019-06-14 22:03:45

    滑雪 记忆化搜索 Code: #include <iostream> #include <cstdio> #include <cstring> using namespace std; //Mystery_Sky // #define M 500 #define INF 0x3f3f3f3f int f[M][M]; int r, c, map[M][M], ans; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}

  • cf1182E Complete Mirror2019-06-12 11:50:52

    可以得到一个结论, 可行的点要么是直径端点, 要么是直径中点, 要么是直径中点引出的链中最短的端点 #include<cstdio> #include<algorithm> #include<iostream> #include<cstring> #include<queue> #define mmp make_pair #define ll long long #define M 100010 using namespace st

  • 【POJ3784】Running Median2019-06-02 10:38:55

    动态维护中位数的题目。 我们采用对顶堆做法,建立一个大根堆存储前半段序列(排序后),小根堆存储后半段序列,通过维护两个堆使得他们元素个数之差不大于1 ,这样这个序列的中位数就是大根堆的堆顶。 关于如何维护对顶堆:如果两个堆元素个数差大于1,我们就把大根堆的堆顶放到小根堆当中(或是把

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有