
模板
文章平均质量分 74
henuzxy
已经成为刷题过千的男人,即将成为cf 1900分的男人。
展开
-
归并排序,树状数组,求逆序数 (openjudge 7662)
题目链接描述 在Internet上的搜索引擎经常需要对信息进行比较,比如可以通过某个人对一些事物的排名来估计他(或她)对各种不同信息的兴趣,从而实现个性化的服务。对于不同的排名结果可以用逆序来评价它们之间的差异。考虑1,2,…,n的排列i1,i2,…,in,如果其中存在j,k,满足 j < k 且 ij > ik, 那么就称(ij,ik)是这个排列的一个逆序。一个排列含有逆序的个数称为这个排列的逆原创 2017-08-08 23:29:37 · 896 阅读 · 0 评论 -
3224: Tyvj 1728 普通平衡树 (Splay)
Description您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作:插入x数删除x数(若有多个相同的数,因只删除一个)查询x数的排名(若有多个相同的数,因输出最小的排名)查询排名为x的数求x的前驱(前驱定义为小于x,且最大的数)求x的后继(后继定义为大于x,且最小的数)Input第一行为n,表示操作的个数,下面n行每行有两个数opt和x,opt表...原创 2018-09-30 17:33:43 · 217 阅读 · 0 评论 -
HDU 3549 Flow Problem(网络流之最大流模板题)
传送门Problem Description Network flow is a well-known difficult problem for ACMers. Given a graph, your task is to find out the maximum flow for the weighted directed graph.Input The first line of inpu原创 2017-09-12 22:28:12 · 397 阅读 · 0 评论 -
牛客网暑期ACM多校训练营(第五场)E room 带权二部图匹配问题(费用流解决)
链接:https://www.nowcoder.com/acm/contest/143/E 来源:牛客网时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 Nowcoder University has 4n students and n dormitories ( Four ...原创 2018-08-03 14:14:38 · 229 阅读 · 0 评论 -
POJ - 1151 Atlantis 扫描线求重叠面积
There are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts even include maps of parts of the island. But unfortunately, these maps describe diff...原创 2018-08-07 18:40:53 · 226 阅读 · 0 评论 -
POJ 2987 Firing (网路流之最大权闭合图)
You’ve finally got mad at “the world’s most stupid” employees of yours and decided to do some firings. You’re now simply too mad to give response to questions like “Don’t you think it is an even more ...原创 2018-08-14 16:39:39 · 283 阅读 · 0 评论 -
CodeForces - 558E A Simple Task (计数排序 线段树)
This task is very simple. Given a string S of length n and q queries each query is on the format i j k which means sort the substring consisting of the characters from i to j in non-decreasing order i...原创 2018-08-03 16:51:24 · 457 阅读 · 0 评论 -
堆排序的实现
**堆排序是一种时间复杂度也为nlogn的一种排序,和快排的时间复杂度一样,但他在面对一些问题时能够用他的特殊性,更好的解决问题。 简单堆排的代码如下:#include#include#include#include#include#include#include#define MAX 100using namespace std;int h[MAX],n;void原创 2017-03-20 23:09:55 · 464 阅读 · 0 评论 -
快速幂的两种算法
快速幂是一种在O(logN)的时间复杂度下求出幂的一种方法。 第一种算方法就是对于一个X^N我们可以把N转化成2进制的形式,如X^22 = X^16+X^4+X^2;因为22(二进制:10110) = 16 + 4 + 2; 所以我们可以推到出来这种算法,完整代码如下:typedef long long ll;ll mod_pow(ll x,ll n,ll mod){ ll ...原创 2017-04-20 12:25:23 · 577 阅读 · 0 评论 -
一些数学几何知识和小技巧
发现自己几何sb,还是总结一下已知三点求圆心,但三点不能共线Point Getcir(Point A,Point B,Point C){//给予三个点,求圆心。 double a = 2*(B.x - A.x); double b = 2*(B.y - A.y); double c = (B.x*B.x+B.y*B.y) - (A.x*A.x+A.y*A.y);...原创 2017-11-12 14:40:29 · 559 阅读 · 0 评论 -
HDU 6214 Smallest Minimum Cut (最小割最小割边)(两种算法的分析)
Problem Description Consider a network G=(V,E) with source s and sink t. An s-t cut is a partition of nodes set V into two parts such that s and t belong to different parts. The cut set is the subset原创 2017-09-17 20:29:14 · 1683 阅读 · 5 评论 -
重载的可加减乘的点(向量)模板
#include<cstdio>#include<cmath>#include<iostream>#include<cstring>#include<string>#include<vector>#include<algorithm>typedef long long ll;using namespace std;class point{public: int x,y;原创 2017-09-10 19:46:26 · 518 阅读 · 0 评论 -
快速排序和归并排序的实现
归并排序:#include<stdio.h>#include<time.h>#include<stdlib.h>void Merge(int a[],int l,int m,int r,int b[]){ int pos,p1,p2; pos = 0,p1 = l,p2 = m+1; while(p1 <= m && p2 <= r){ if(a[p1]原创 2017-08-08 20:24:14 · 311 阅读 · 0 评论 -
扩展欧几里得模板
#include<iostream>#include<algorithm>using namespace std;typedef long long ll;ll extgcd(ll a,ll b,ll &x,ll &y){ ll d = a; if(b != 0){ d = extgcd(b,a%b,y,x); y -= (a/b)*x;原创 2017-04-16 22:55:19 · 404 阅读 · 0 评论 -
hpu 1413: StarFarming(图论,有向图反向存边)
传送门 题目描述 星农(StarFarming)公司计划要给员工发路费津贴,发放的规则是这样的:1到n-1代表各个员工家的序号,n代表公司。路费津贴只发给上班的最短路与回家的最短路的总路程最长的人。该市的路建造的有些奇怪,修路只修单行道,即只允许往某一个方向通行。现在给你城市的有向图的地图,TLG请你帮忙计算谁能得到津贴,以及他上班和回家的总路程是多少。输入 有多组测试数据。每组第一行输入两个原创 2017-08-12 11:56:33 · 808 阅读 · 0 评论 -
链表的归并排序 & leetcode 148. 排序链表
发现链表的归并排序要注意的点还真挺多。对元素的划分,即要把链表从中间断开,这个可以利用一个快指针每次走两步,一个慢指针一次走一步的做法来实现,并记录前半部分链表的最后一个节点。对链表的合并,这个我是利用递归,很容易理解与实现。代码实现如下:/** * Definition for singly-linked list. * struct ListNode { * int ...原创 2019-09-18 23:49:01 · 402 阅读 · 0 评论