自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

xlc2845的专栏

You will never know if you don't live it.

  • 博客(241)
  • 资源 (1)
  • 收藏
  • 关注

原创 观察者模式在电话中的应用

定义:观察者模式就是监听一个对象的变化,当一个对象发生变化时,所有监听其变化的对象都会收到通知,Android中非常多的东西都是观察者模式的实现。1.InCallStateListenerincallui,是一个mvp的经典实现,所有的presenter都会监听这个listener1.1定义/** * Interface implemented by classes that need t

2017-09-17 17:51:47 497

原创 getStringForUser原理和线程安全

在电话中有很多的设置项,因为电话的设置项有些需要在全局使用,所以通过Settings.System.putStringForUser 和 Settings.System.getStringForUser,来写入和读取一些设置项。1.问题描述getStringForUser有时候拿到了错误的值。通过一些log,我们发现:出现问题时都是在多个线程同时读写的时候。所以它肯定涉及到了线程安全的问题。2.Se

2017-09-03 15:48:03 4847 1

原创 模板模式的应用

1.《Java与模式》描述:模板方法模式是类的行为模式。准备一个抽象类,将部分逻辑以具体方法以及具体构造函数的形式实现,然后声明一些抽象方法来迫使子类实现剩余的逻辑。不同的子类可以以不同的方式实现这些抽象方法,从而对剩余的逻辑有不同的实现。这就是模板方法模式的用意。 顾名思义,模板模式就是给你一个模板(声明的抽象方法),由你实现的子类来填充这些方法,然后执行start,这个类就会按照固定的套路执行

2017-08-20 14:45:07 466

原创 电话中工厂模式和源码分析

工厂模式PhoneFactory http://blog.csdn.net/jason0539/article/details/23020989 工厂模式是最常用的实例化模式之一,就是定义了一些接口,让子类决定实例化哪个类。 在telephony中,其实使用了大量的工厂模式,这里主要了解PhoneFactory /frameworks/opt/telephony

2017-08-07 20:45:13 657

原创 AsyncTask 原理

AsyncTask是Android提供的一个工具,可以用来处理轻量级的异步任务,AsyncTask是一个非常经典的模板模式的实现,模板模式:大概就是说,执行一次exeute,可以依次执行一些可以被你重写的方法。就像AsyncTask,每次执行exeute,都会依次执行onPreExecute,doInBackground,onPostExecute,这三个方法只有doInBackground会在异步

2017-03-03 10:56:53 531

原创 StateMachine 状态机原理

The state machine defined here is a hierarchical state machine which processes messages and can have states arranged hierarchically. 这里通过CallAudioRouteStateMachine 为线索来看状态机的原理。State状态机首先要知道的肯定就是状

2017-03-01 15:22:59 4606

原创 Android N Telecom对Audio的管理

Android N Telecom对Audio的管理Android N,对通话时Audio的管理与M相比发生了比较大的变化,主要是引入了状态机。Android N Telecom对Audio的管理CallAudioManageronCallAddedupdateForegroundCallonCallEnteringStateCall call int stateonCallStat

2017-02-26 15:17:14 3208

转载 vim 配置

" All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just" /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime" you can find below. If you wish to change any

2015-05-14 16:13:02 497

原创 socket

#include #include #include #include #include #include #include #include int main() {    int sockfd, len, result;    struct sockaddr_in address;    char ch[2];    //sockfd = s

2015-03-23 12:43:17 449

转载 linux grep命令

linux grep命令1.作用Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来。grep全称是Global Regular Expression Print,表示全局正则表达式版本,它的使用权限是所有用户。2.格式grep [options]3.主要参数[options]主要参数:-c:只输出匹配行的计数

2015-02-28 19:28:56 507

转载 static的作用

static的作用   在C语言中,static的字面意思很容易把我们导入歧途,其实它的作用有三条。(1)先来介绍它的第一条也是最重要的一条:隐藏。当我们同时编译多个文件时,所有未加static前缀的全局变量和函数都具有全局可见性。为理解这句话,我举例来说明。我们要同时编译两个源文件,一个是a.c,另一个是main.c。下面是a.c的内容char a = 'A'; //

2015-02-27 15:18:20 393

转载 linux 磁盘挂载

1. 添加磁盘,查看磁盘状况    [root@db1 /]# fdisk -lDisk /dev/sda: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes   D

2015-02-12 19:28:58 525

原创 codeforces 507C

满二叉树,可以递归求解因为总是将一棵子树走完之后再到另外一棵判断出口在左子树还是右子树,再加上走到这棵子树的步数。#include #include #include #include #include #include #include #include #include #include #include #include #include #includ

2015-02-10 11:08:39 626

原创 shell 数值计算

expr 数值1 操作符 数值2$[数值1 操作符 数值2]乘号需要转义let 变量名++ / +=2 / += 3 ...变量自加let 变量名-- / -= 2 / -= 3 ...变量自减RANDOM 生成随机数$RANDOM限定范围$[RANDOM%100]seq 生成序列 seq 首 末seq 首 增 末

2015-02-09 14:56:59 499

转载 linux gcc常用命令集合

gcc和g++的编译选项通常情况下是一样的.格式(选项 && 解释 )linux gcc常用命令集合:-o FILE    && 指定输出文件名,在编译为目标代码时,这一选项不是必须的.如果FILE没有指定,缺省文件名是a.out.-c     &&  只编译生成目标文件,不链接-m486    &&  针对 486 进行代码优化.-O0     &&  不进行优化处理

2015-02-07 16:41:47 580

原创 gprof 程序剖析

使用gprof使用命令编译 需参数 -pgg++/gcc -pg name1.c -o name2执行程序 添加参数file.txt 生成gmon.out./name2 file.txt调用gprof 分析gmon.out中数据gprof name2可看到程序各个部分运行时间

2015-02-07 16:40:13 648

转载 Linux后台管理命令

Linux后台管理命令  &     将命令在后台执行CTRL + Z  将当前任务暂停jobs            查看当前在后台运行的任务fg        将编号为n的任务拉回前台bg       将编号为n的任务后台运行man command                    查看命令详细信息info command

2015-02-05 20:57:31 569

原创 linux 常用命令

. 当前目录.. 上级目录/ 根目录~ 用户pwd 显示当前位置关机 shutdown -r 重启-h 关机shutdown -h nowshutdown -h +10 十分钟shutdown -h 23:30date 时间时间格式化 +%Y-%m-%dcat 文件名  查看内容more 文件名  向下le

2015-02-05 10:57:15 525

转载 汇编指令

GAS中每个操作都是有一个字符的后缀,表明操作数的大小。C声明GAS后缀大小(字节)charb1shortw2(unsigned) int / long / char*l4floats

2015-02-01 21:18:21 635

转载 汇编 leave popl

最近在看c程序的编译出来的汇编文件,发现涉及到函数调用的地方,在返回时有的时候使用的leave,有的时候直接使用的是popl %ebp。在AT&T汇编中,leave等效于以下汇编指令:movl %ebp, %esppopl %ebp注意:此为32bits 操作系统,若为64bits 将使用rbp和rsp 寄存器!为什么有的时候会使用leave,有的时候直接使用popl

2015-01-03 20:49:16 1667

原创 Codeforces goodbye 2014

D题 对每条边考虑边的两侧分别有x,y个节点,所以经过改变的种数为x*y*(n-2) (n-2) 为第三个点选取的位置接下来就是乘乘减减了 #include #include #include #include #include #include #include #include #include #include #include #include

2014-12-31 03:33:05 555

原创 判断溢出

判断两个int型变量的和是否会溢出int tadd_ok(int x, int y) { if(x >= 0 && y >= 0 && x+y < 0) return 0; if(x = 0) return 0; return 1;}

2014-12-23 16:53:51 735

转载 在C语言中写TMin

本文为CSAPP2e的webaside资料,随意翻译,无版权。原文 1.情景 在CSAPP的图示和问题中,我们很小心的把32(TMin32)位有符号最小值写作-2147483647-1,为什么我们不直接写成-2147483648或0x80000000呢?不妨先打开limits.h头文件看看吧,你会发现它们也是用类似的诡异形式 ISO90: Decimal:         

2014-12-22 15:19:39 2346

原创 字节顺序

#include #include typedef unsigned char *byte_pointer;void show_bytes(byte_pointer start, int len) { int i; for(i = 0; i < len; ++ i) { printf("%.2x", start[i]); } puts(""

2014-12-21 13:53:37 505

原创 Codeforces 496E

贪心 二分查找 因为要不断地删除 用set容器#include #include #include #include #include #include #include #include #include #include using namespace std;const int N=100005;struct node{ int d,k,id; bool o

2014-12-18 17:00:34 733

原创 Codeforces 496D

类似于模拟,记录下标或者二分进行优化#include #include #include #include #include using namespace std;struct node { int u, v; bool operator < (const node& rhy) const { if(u != rhy.u) return u < rh

2014-12-18 04:05:20 656

原创 操作系统 生产者消费者问题

/*输入要求 numb nump numc 分别为缓冲区数量 生产者数量 消费者数量nump个数 表示每个生产者需要生产的产品数numc个数 表示每个消费者需要消费的产品数4 2 23 33 3*/#include#include#include#include#include//定义一些常量;//本程序允许的最大临界区数;#define MAX_BUFFER_

2014-11-22 20:23:40 1163

转载 位计算的函数

int __builtin_ffs (unsigned int x)返回x的最后一位1的是从后向前第几位,比如7368(1110011001000)返回4。int __builtin_clz (unsigned int x)返回前导的0的个数。int __builtin_ctz (unsigned int x)返回后面的0个个数,和__builtin_clz相对。int _

2014-11-22 20:21:05 799

原创 ZOJ 3791

dpdp[j]表示与目标状态有j位不同的方法shu

2014-11-22 20:19:10 523

原创 zoj 3790

排序 尺取法#include #include #include #include #include #include #include #include #include #include #include using namespace std;const int maxn = 100100;struct node{ int head, tail;

2014-11-22 20:14:48 596

原创 ZOJ 3802

状态压缩的DP压缩的状态是一个递减序列 如果序列f

2014-11-15 19:21:24 670 1

原创 poj 3581

后缀数组  bei'zen#include #include #include #include #include #include #define maxn 200010using namespace std;int k, n;int _rank[maxn*2], tem[maxn*2];int sa[maxn*2];int N, A[maxn*2];int re

2014-11-14 21:15:43 577

转载 树链剖分

文地址:树链剖分作者:starszys    “在一棵树上进行路径的修改、求极值、求和”乍一看只要线段树就能轻松解决,实际上,仅凭线段树是不能搞定它的。我们需要用到一种貌似高级的复杂算法——树链剖分。    树链,就是树上的路径。剖分,就是把路径分类为重链和轻链。    记siz[v]表示以v为根的子树的节点数,dep[v]表示v的深度(根深度为1),top[v]表示v所在的链

2014-11-14 16:50:21 429

原创 hdu 4971

不会最大流  记忆话搜索过的

2014-10-02 15:24:10 481

转载 树链剖分

树链剖分  模板  kuangbin大神呐 co

2014-10-02 15:21:14 401

原创 spoj 375

树链剖分  此题是修改边的权值 shu'lian#include #include #include #include #include #include #include #include #include #include #include #include #include #define FFI freopen("in.txt", "r", stdin)

2014-10-02 12:42:33 530

原创 线段树模板 区间加减 区间修改

#include #include #include using namespace std;const int maxn = 1000010;struct node{ int l; int r; int max_val; int min_val; int sum; int addv; int setv;};node a[ma

2014-05-22 22:21:25 834

原创 hdu 1698 线段树 区间修改

#include #include #include #include #include #include #include #include #include #include #include #include #include #define maxn 200010#define INF 0x7fffffff#define inf 10000000#defin

2014-05-22 20:39:00 582

原创 sublime text3 插件安装

先打开安装代码的命令行 按 ctrl+~或者 view  -> show console 将下面的代码

2014-05-19 18:33:52 943

转载 sublime 配置C++

之前说了SublimeText下C编译环境的设置,C++的设置也大体相同。其设置方法如下  1. 安装C语言编译器MinGW,并把MinGW安装目录下的bin目录添加到环境变量PATH里。详细方法参照MinGW安装和使用  2. 因为SublimeText原本的编译环境不支持非英语系统,所以要先修改SublimeText。把SublimeText安装目录下的Data\Package

2014-05-19 18:11:03 673

飞机大战mfc

vs 2013 实现飞机大战小游戏 mfc 语言C++

2015-02-07

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除