/images/avatar.png

^_^

hduoj2089(数位dp + 记忆化搜索)

Problem Description

杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer)。 杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍,更安全地服务大众。 不吉利的数字为所有含有4或62的号码。例如: 62315 73418 88914 都属于不吉利号码。但是,61152虽然含有6和2,但不是62连号,所以不属于不吉利数字之列。 你的任务是,对于每次给出的一个牌照区间号,推断出交管局今次又要实际上给多少辆新的士车上牌照了。

Segment Tree

线段树是把区间分割,然后把数据按树存储的数据结构。线段树是一颗完美二叉树

用一个例子来介绍线段树

RMQ(range minimum query)

实现功能 对于一个数列 1.给定s,t求[s,t)区间的最小值(最大值) 2.给定i和x,把ai改成x

Graph Theory

图的存储:邻接表、邻接矩阵、前向星、链式前向星等

链式前向星存图

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
struct edge{
	int to , w , next;
}e[maxn];
int tot,head[maxn];

void add_edge(int u,int v,int w){
	e[tot].to = v;
	e[tot].w = w;
	e[tot].next = head[u];
	head[u] = tot++;
}

for(int i=head[u];~i;i=e[i].next){
	int v = e[i].to;
	int w = e[i].w;
}

//init
memset(head , -1 , sizeof(head));

二分图判定

通过着色来判定,整个图只染两种颜色,如果相邻点颜色不同就是二分图

poj

线段相交

1127

题意

判断两条线段是否相交,对于N条线段,间接相交也算相交。对于每次询问,判 断给定的两条线段是否相交

题解

这个题目分成两部分,一部分是基础的判断两条线段是否相交,用一个bool数组来存储信息。另一部分是判断间接相交,可以用floyd-warshall(比较巧妙)或者并查集.第一部分就是套模板。

abc152-D

题目链接 题意:找正整数对(A,B),A、B都不大于N,满足A的第一个数字是B的最后一个数

字,B的第一个数字是A的最后一个数字,个位数也算,输出满足条件的正整数对的个数

CP笔记

记录的东西十分零散,适用于速查,不适合系统学习

由于记录的时候所掌握的知识很浅,所以可能存在错误

快速排序

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

void quicksort(int s[], int l, int r) {
    if (l < r) {
        int i = l, j = r, x = s[l];
        while (i < j) {
            while (i < j && s[j] >= x)
                j--;
            if (i < j)
                s[i++] = s[j];
            while (i < j && s[i] < x)
                i++;
            if (i < j)
                s[j--] = s[i];
        }
        s[i] = x;
        quicksort(s, l, i - 1);
        quicksort(s, i + 1, r);
    }
}

int main() {

    int a[10] = {3, 5, 1, 8, 9, 4, 2, 6, 0, 1};
    int i;
    quicksort(a, 1, 9);
    for (i = 0; i < 10; i++)
        cout << a[i] << ' ';
    

    return 0;
}

//3 0 1 1 2 4 5 6 8 9

产生随机数

古老的生成随机数的方法

c++交集、并集、差、对称差函数

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<iostream>
#include<set>
//#include<map>
//#include<string>
#include<algorithm>
#include<iterator>
using namespace std;
int main()
{
	int a[]={3,2,1};
	int b[]={3,4,5,6};
	set<int> s1(a,a+3);
	set<int> s2(b,b+4);
	set<int> s3;
	set_union(s1.begin(),s1.end(),s2.begin(),s2.end(),inserter(s3,s3.begin()));
	for(set<int>::iterator it=s3.begin();it!=s3.end();it++)
		cout<<*it<<" ";
	cout<<endl;
	set_union(s1.begin(),s1.end(),s2.begin(),s2.end(),ostream_iterator<int>(cout,"*"));
	cout<<endl;
	set_intersection(s1.begin(),s1.end(),s2.begin(),s2.end(),ostream_iterator<int>(cout," "));
	cout<<endl;
	set_difference(s1.begin(),s1.end(),s2.begin(),s2.end(),ostream_iterator<int>(cout," "));
	cout<<endl;
	set_symmetric_difference(s1.begin(),s1.end(),s2.begin(),s2.end(),ostream_iterator<int>(cout," "));
	return 0;
}

c++每种类型的值域

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<iostream>
#include<string>
#include <limits>
using namespace std;
 
int main()
{
    cout << "type: \t\t" << "************size**************"<< endl;
    cout << "bool: \t\t" << "所占字节数:" << sizeof(bool);
    cout << "\t最大值:" << (numeric_limits<bool>::max)();
    cout << "\t\t最小值:" << (numeric_limits<bool>::min)() << endl;
    cout << "char: \t\t" << "所占字节数:" << sizeof(char);
    cout << "\t最大值:" << (numeric_limits<char>::max)();
    cout << "\t\t最小值:" << (numeric_limits<char>::min)() << endl;
    cout << "signed char: \t" << "所占字节数:" << sizeof(signed char);
    cout << "\t最大值:" << (numeric_limits<signed char>::max)();
    cout << "\t\t最小值:" << (numeric_limits<signed char>::min)() << endl;
    cout << "unsigned char: \t" << "所占字节数:" << sizeof(unsigned char);
    cout << "\t最大值:" << (numeric_limits<unsigned char>::max)();
    cout << "\t\t最小值:" << (numeric_limits<unsigned char>::min)() << endl;
    cout << "wchar_t: \t" << "所占字节数:" << sizeof(wchar_t);
    cout << "\t最大值:" << (numeric_limits<wchar_t>::max)();
    cout << "\t\t最小值:" << (numeric_limits<wchar_t>::min)() << endl;
    cout << "short: \t\t" << "所占字节数:" << sizeof(short);
    cout << "\t最大值:" << (numeric_limits<short>::max)();
    cout << "\t\t最小值:" << (numeric_limits<short>::min)() << endl;
    cout << "int: \t\t" << "所占字节数:" << sizeof(int);
    cout << "\t最大值:" << (numeric_limits<int>::max)();
    cout << "\t最小值:" << (numeric_limits<int>::min)() << endl;
    cout << "unsigned: \t" << "所占字节数:" << sizeof(unsigned);
    cout << "\t最大值:" << (numeric_limits<unsigned>::max)();
    cout << "\t最小值:" << (numeric_limits<unsigned>::min)() << endl;
    cout << "long: \t\t" << "所占字节数:" << sizeof(long);
    cout << "\t最大值:" << (numeric_limits<long>::max)();
    cout << "\t最小值:" << (numeric_limits<long>::min)() << endl;
    cout << "unsigned long: \t" << "所占字节数:" << sizeof(unsigned long);
    cout << "\t最大值:" << (numeric_limits<unsigned long>::max)();
    cout << "\t最小值:" << (numeric_limits<unsigned long>::min)() << endl;
    cout << "double: \t" << "所占字节数:" << sizeof(double);
    cout << "\t最大值:" << (numeric_limits<double>::max)();
    cout << "\t最小值:" << (numeric_limits<double>::min)() << endl;
    cout << "long double: \t" << "所占字节数:" << sizeof(long double);
    cout << "\t最大值:" << (numeric_limits<long double>::max)();
    cout << "\t最小值:" << (numeric_limits<long double>::min)() << endl;
    cout << "float: \t\t" << "所占字节数:" << sizeof(float);
    cout << "\t最大值:" << (numeric_limits<float>::max)();
    cout << "\t最小值:" << (numeric_limits<float>::min)() << endl;
    cout << "size_t: \t" << "所占字节数:" << sizeof(size_t);
    cout << "\t最大值:" << (numeric_limits<size_t>::max)();
    cout << "\t最小值:" << (numeric_limits<size_t>::min)() << endl;
    cout << "string: \t" << "所占字节数:" << sizeof(string) << endl;
    // << "\t最大值:" << (numeric_limits<string>::max)() << "\t最小值:" << (numeric_limits<string>::min)() << endl;
    cout << "type: \t\t" << "************size**************"<< endl;
    return 0;
}