扩展欧几里得
#include
int exgcd(int a, int b, int &x, int &y)
{
int d,tmp;
if (b==0)
{
x = 1;
y = 0;
return a;
}
d = exgcd(b,a%b,x,y);
tmp = x;
x = y;
y = tmp - a/b * y;
return ...
分类:
其他好文 时间:
2014-08-12 09:04:23
阅读次数:
216
题意:有n个数,m个询问(l,r,k),问在区间[l,r] 有多少个数小于等于k。
划分树——查找区间第k大的数。。。。
利用划分树的性质,二分查找在区间[l,r]小于等于k的个数。
如果在区间第 i 大的数tmp>k,则往下找,如果tmp
#include
#include
#include
#include
#include
#include
#inc...
分类:
其他好文 时间:
2014-08-12 00:46:53
阅读次数:
518
#include#include#include#includeusing namespace std;int main(int argc,char *argv[]){ ifstream input(argv[1]); vector vec; string tmp; whil...
分类:
其他好文 时间:
2014-08-12 00:21:53
阅读次数:
493
function quick_sort(list, head, tail) if tail > head then i = head j = tail tmp = list[i] --取第一个元素用于比较 同时腾出第一个位置 while i i do if list[j] tmp then li.....
分类:
其他好文 时间:
2014-08-11 20:59:12
阅读次数:
274
[root@test]# /usr/local/mysql/bin/mysql -urootERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)[root@test]#...
分类:
数据库 时间:
2014-08-11 20:29:02
阅读次数:
248
直接插入排序的时间复杂度的O(N^2),空间复杂度是O(1)。
下面是代码:
public class InsertionSort {
public void insertionSort(int[] in) {
int length = in.length;
int i, j;
for (i = 1; i < length; i++) {
int tmp = in[i];...
分类:
其他好文 时间:
2014-08-11 12:04:12
阅读次数:
194
http://acm.hdu.edu.cn/showproblem.php?pid=4821
昨晚卡了很久,开始TLE,然后优化了之后,因为几个地方变量写混,一直狂WA,搞得我昨晚都失眠了,,,
这几次hash军写错的变量--tmp=(j==m-1)?ah[j]:(ah[j]-ah[j-m]*base[m]); 外层循环变量是i,我写的字符串hash的几题都写成tmp=(i==0)?ah[j...
分类:
其他好文 时间:
2014-08-11 10:10:42
阅读次数:
245
最近没啥可写的 这里写下做的STL小练习 作为记录去除指定字符串中的空格获取文件名并根据名字创建临时文件,以TMP后缀结尾,已经为TMP后缀结尾文件则创建以XXX后缀结尾文件读取一行输入内容 并将单词翻转打印// 1111.cpp : 定义控制台应用程序的入口点。//#include "stdafx...
分类:
其他好文 时间:
2014-08-10 15:21:10
阅读次数:
212
首先,归并排序,分治,递归解决小的范围,再合并两个有序的小范围数组,便得到整个有序的数组。
这是很适合用递归来写的,至于非递归,便是从小到大,各个击破,从而使得整个数组有序。代码如下:
void merge(vector &A, int left, int mid, int right)
{
int i=left,j=mid+1;
vector tmp(right-left+1,0);...
分类:
其他好文 时间:
2014-08-10 13:08:00
阅读次数:
235
//只列举了部分常用的
char *strcpy(char *dest, const char *src)
{
char *tmp = dest;
while ((*dest++ = *src++) != '\0')
/* nothing */;
return tmp;
}
char *strncpy(char *dest, const char *src, size_t coun...
分类:
系统相关 时间:
2014-08-09 23:21:59
阅读次数:
524