- 博客(359)
- 收藏
- 关注
原创 主席树简单入门
主席树在每次更新的叶子节点时,记录从根节点开始一路到叶子节点的更改节点信息。每个节点值更新后,还可以通过该节点更新前的根节点查询之前的信息。如下图所示:入门题目:给定n个数,q个询问,每次回答某个区间内不相同的元素个数。n, q(1 <= n, q <= 100000),n个正整数a_1, a_2, a_3, …, a_n(对于任意的1 <= i <= n,都有...
2019-08-07 16:10:58 205
原创 nowcoder 失衡天平
失衡天平时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 262144K,其他语言524288K64bit IO Format: %lld题目描述终于Alice走出了大魔王的陷阱,可是现在傻傻的她忘了带武器了,这可如何是好???这个时候,一个神秘老人走到她面前答应无偿给她武器,但老人有个条件,需要将所选武器分别放在天平的两端,若天平平衡则可以将天平上的所有武器拿走,还好...
2018-09-16 17:32:48 514
原创 字符串最小表示法(LeetCode 899. Orderly Queue )
A string S of lowercase letters is given. Then, we may make any number of moves.In each move, we choose one of the first K letters (starting from the left), remove it, and place it at the end of th...
2018-09-02 17:00:27 680
原创 根据节点数目构建满二叉树
894. All Possible Full Binary TreeA full binary tree is a binary tree where each node has exactly 0 or 2 children.Return a list of all possible full binary trees with N nodes. Each element of the...
2018-08-26 14:46:00 1152
原创 字典树 (网易互娱2018笔试题目第4题)
网易互娱笔试第4题,给定一些手机号以及对应的归属地,查询手机号的归属地。231357xxxxxxx GuangZhou0113680xxxxxx GuangZhou0113799xxxxxx HangZhou02313579246810136802468101379999999953333xxxxxxx nowhere3334xxxxxxx somewhere3335...
2018-08-10 10:46:20 890
原创 重建二叉树(根据前序遍历和中序遍历构建二叉树)
题目描述输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6},则重建二叉树并返回。思路:1.前序遍历的第一个节点一定是根结点。前序遍历的一个节点要么是相邻前一个节点的左子树、右子树或者更靠近前面节点的右子树。如何确定前后相邻两...
2018-08-08 13:07:05 4389
原创 vim设置大括号自动补全并换行对齐
首先用vim 打开配置配件vimrc;1.在设置中,需要添加这4条作为前提条件;set smartindentset tabstop=4set shiftwidth=4set expandtab2.在一些博客中看到的配置内容是: imap { {}<ESC>i<CR><ESC>V<O, 然而我的vim这样设置始终右括号不能对齐。然后,发...
2018-07-26 16:05:26 6143 2
原创 二叉树的非递归遍历 (leetcode 104.二叉树的最大深度)
二叉树前序遍历:先访问根结点,然后右子树入栈,最后左子树入栈;#define mp make_pairclass Solution {public: int maxDepth(TreeNode* root){ stack<pair<TreeNode*,int> >s; s.push(mp(root,1)); ...
2018-07-25 20:46:43 969
原创 函数指针
首先定义一个函数指针pf,包括参数列表和返回值,完整形式为:int (*pf) (int,int) ,参数为两个整型变量,返回值为整型。在主函数中将指针指向同类型函数地址,即可以指向原函数调用入口;接着用typedef声明一个函数My_add,用My_add声明的add2函数名接口实现函数的定义。运行输出结果如下:#include<stdlib.h>#in...
2018-07-24 10:04:51 2901 1
原创 G. Xor-MST (分治+Trie树)
G. Xor-MSTtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a complete undirected graph with n vertices. A number ai is assigned to ea...
2018-07-10 19:09:12 724
原创 E. Maximum Subsequence (meet-in-the-middle)
E. Maximum Subsequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a consisting of n integers, and additionally an intege...
2018-07-10 09:17:47 619
原创 C. 阿里巴巴的手机代理商 (字典树)
8.81% 3000ms 524288K阿里巴巴的手机代理商正在研究 infra 输入法的新功能。他们需要分析单词频率以改进用户输入法的体验。于是需要你在系统内核里面写一个 API。 API 有如下功能:添加操作添加操作格式为insert barty 8 ,意思为插入barty这个单词,这个单词词频为 88 次。注意如果再次添加insert barty 8操作时,就会将词频增加为 1616 次。(...
2018-05-15 16:09:01 172
原创 hdu 1392 (凸包模板)
Surround the TreesTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12620 Accepted Submission(s): 4895Problem DescriptionThere are a lot of tre...
2018-05-14 15:15:53 167
原创 hdu 2476 (区间动态规划)
String painterTime Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5530 Accepted Submission(s): 2629Problem DescriptionThere are two strings A and...
2018-05-10 21:56:34 376
原创 hdu 4283 (区间动态规划)
You Are the OneTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5204 Accepted Submission(s): 2499Problem Description The TV shows such as You...
2018-05-10 16:09:22 265
原创 hdu 4745 (区间动态规划)
Two RabbitsTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 2230 Accepted Submission(s): 1156Problem DescriptionLong long ago, there lived tw...
2018-05-10 14:20:40 175
原创 01背包记录所装物品
D. Tankstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPetya sometimes has to water his field. To water t
2018-03-07 15:33:08 682
原创 ifstream&&ofstream的.csv文件读写
从.csv文件中读取文件,并提取出整数或者浮点数,最后在写入另一个.csv文件中。#include #include #include #include #includeusing namespace std;vector >a; //二维数组存储读入变量vectorb;inline void file_to_string(vector &record, cons
2017-08-18 10:24:55 1835
原创 Codeforces Round #424 (Div. 1, rated, based on VK Cup Finals)
C. Bamboo Partitiontime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputVladimir wants to modernize partitions
2017-08-04 12:18:22 354
原创 AtCoder Grand Contest 018--D题
D - Tree and Hamilton PathTime limit : 2sec / Memory limit : 256MBScore : 1100 pointsProblem StatementThere is a tree with N vertices, numbered 1 through N. The i-th edge in th
2017-07-27 17:07:40 436
原创 背包问题(分组背包)
D. Arpa's weak amphitheater and Mehrdad's valuable Hosestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputJus
2016-12-13 16:04:52 5620
原创 CF 377 D. Exams
D. Examstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasiliy has an exam period which will continue for
2016-10-31 20:22:15 1904
原创 CF 361 E. Mike and Geometry Problem (排列组合+乘法逆元)
E. Mike and Geometry Problemtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMike wants to prepare for IMO
2016-08-02 16:17:55 673
原创 CF 361 D. Friends and Subsequences (RMQ+二分查找)
D. Friends and Subsequencestime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputMike and !Mike are old childhoo
2016-08-02 10:44:04 421
原创 poj 3368 Frequent values (RMQ或线段树)
Frequent valuesTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 16959 Accepted: 6125DescriptionYou are given a sequence of n integers a1 , a2 , ... , a
2016-08-01 10:15:10 1641
原创 Fenwick tree (CF Educational Codeforces Round 10)
D. Nested Segmentstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n segments on a line. Ther
2016-04-26 16:58:12 333
原创 hdu 1576 A/B (求乘法逆元——扩展欧几里得)
A/BTime Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3745 Accepted Submission(s): 2869Problem Description要求(A/B)%9973,但由于A很大,我们
2016-04-23 11:57:45 476
转载 卡特兰数
卡塔兰数卡塔兰数是组合数学中一个常出现在各种计数问题中出现的数列。由以比利时的数学家欧仁·查理·卡塔兰 (1814–1894)命名。卡塔兰数的一般项公式为 另类递归式: h(n)=((4*n-2)/(n+1))*h(n-1);前几项为 (OEIS中的数列A000108): 1, 1, 2, 5, 14, 42, 132, 429
2016-04-23 09:20:17 1299
原创 Codeforces Round #320 (Div. 2) [Bayan Thanks-Round]
E. Weakness and Poornesstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence of n inte
2016-04-19 17:31:58 415
原创 hdu 5222 Exploration
ExplorationTime Limit: 30000/15000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1385 Accepted Submission(s): 378Problem Description Miceren likes exploratio
2016-01-28 15:58:13 382
原创 Codeforces Round #294 (Div. 2)
D. A and B and Interesting Substrings time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output A and B are preparing themselves for programming con
2016-01-17 17:47:34 399
原创 Codeforces Round #339 (Div. 2)D. Skills
D. Skills time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Lesha plays the recently published new version of the legendary game hacknet. In
2016-01-16 12:20:27 759
原创 D. Longest k-Good Segment
D. Longest k-Good Segmenttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe array a with n integers is g
2016-01-12 17:36:54 754
原创 C. Vanya and Scales (进制转换)
C. Vanya and Scalestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVanya has a scales for weighing loads an
2016-01-07 10:06:37 463
原创 hdu 5256 序列变换 (LIS变形)
序列变换Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 519 Accepted Submission(s): 245Problem Description我们有一个数列A1,A2...An,你现在要求
2015-06-05 23:01:06 1007 2
原创 poj 3186 Treats for the Cows(区间dp)
Treats for the CowsTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 4375 Accepted: 2226DescriptionFJ has purchased N (1 The treats are interesting
2015-05-06 19:55:21 897
原创 poj 3666 Making the Grade (动态规划)
Making the GradeTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 4647 Accepted: 2202DescriptionA straight dirt road connects two fields on FJ's farm, b
2015-05-05 22:01:32 817
原创 poj 1655 Balancing Act(树的重心)
Balancing ActTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 9913 Accepted: 4069DescriptionConsider a tree T with N (1 <= N <= 20,000) nodes numbered
2015-04-30 17:03:26 605
原创 poj 3140 Contestants Division (树形dp)
Contestants DivisionTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 8544 Accepted: 2439DescriptionIn the new ACM-ICPC Regional Contest, a special mo
2015-04-30 15:53:17 697 2
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人