摘要: 带进度条显示的按钮, 其效果如下所示:其由三部分动画组成: 初始状态->圆环状态->完成状态.0. 实现从初始到圆环的简单实现:继承自button 类, 设置其背景public class CircleButton extends Button implements View.OnClickListener { private StateListDrawable mIdleStateDraw... 阅读全文
posted @ 2015-01-09 10:51 旅行的蜗牛 阅读(593) 评论(0) 推荐(0) 编辑
摘要: 开发环境:Android studio 1.0.2ndkandroid-ndk-r10d-windows-x86_64------------------------------------#1. 创建工程.在MainActivity下添加native 方法#2. 编译得到头文件, 在main/jni 目录下#3. 实现头文件中的方法#4. 在 local.properties 中添加本地ndk... 阅读全文
posted @ 2015-01-07 13:34 旅行的蜗牛 阅读(278) 评论(1) 推荐(0) 编辑
摘要: Scroller 滑动之后滑动器子标签里面的控件,其自身是不动的.这里点在下面的进阶会体现出来.1. 继承LinearLayout, 相对布局也可以.public class MyLinearLayout extends LinearLayout { private Scroller scroller; public MyLinearLayout(Context context, At... 阅读全文
posted @ 2014-08-20 14:25 旅行的蜗牛 阅读(194) 评论(0) 推荐(0) 编辑
摘要: 1.Service 服务 (是一个没有用户界面的在后台运行执行耗时操作的应用组件)第一种方式: (startService 未绑定, 当程序退出,若没有停止服务则会继续在后台运行)//继承ServicepublicclassMyServiceextendsService{privateStringtag="MyService";@OverridepublicIBinderonBind(Intent... 阅读全文
posted @ 2014-06-04 00:44 旅行的蜗牛 阅读(174) 评论(0) 推荐(0) 编辑
摘要: 目录:#1.BroadcastReceiver 广播接收者#2.SharedPreferences (存储在应用程序data/data/包/shared_prefs/目录下,以xml格式保存)#3. 数据库使用(存储在应用程序data/data/包/databases/目录下)#4. URL 网络文件下载#4. URL 网络文件下载#5. 安装apk#6. ContentProvider 内容提供... 阅读全文
posted @ 2014-06-04 00:43 旅行的蜗牛 阅读(218) 评论(0) 推荐(0) 编辑
摘要: 1. 参照例子写, 运行总崩溃, 多半是导库问题...2. 既然这样不行, 只好将源码全部拷贝到工程中了. 然后修错误, (将需要的res 文件复制过来.主要是value中的几个文件)3. 在MainActivity中添加代码:publicclassMainActivityextendsActivity{privateMenuDrawermMenuDrawer;@Overrideprotected... 阅读全文
posted @ 2014-05-12 22:52 旅行的蜗牛 阅读(267) 评论(0) 推荐(0) 编辑
摘要: 来自为知笔记(Wiz) 阅读全文
posted @ 2014-04-30 22:06 旅行的蜗牛 阅读(677) 评论(0) 推荐(0) 编辑
摘要: 1. ReferenceTable overflow (max=512) 内存泄露,程序运行一段时间就挂掉了.在利用反射调用java中的函数需要释放掉查找到的类voidpublishJavaProgress(JNIEnv*env,jobjectobj,jintprogress){jclassclazz=(*env)->FindClass(env,"com/itcast/lame/LameActiv... 阅读全文
posted @ 2014-04-29 01:37 旅行的蜗牛 阅读(170) 评论(0) 推荐(0) 编辑
摘要: 创建android工程 -> 添加native 函数 添加库之后:1. 用javah 生成c语言.h头文件时, 在cmd 窗口中cd 到bin/classes 目录下执行下代码无效:javah cn.luv.monitor.DemoActivity需要cd 到src 目录下:D:\android\workspace\Monitor\src>javah cn.luv.monitor.DemoActi... 阅读全文
posted @ 2014-04-28 16:40 旅行的蜗牛 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 1. 在源文件中添加头文件#include #define LOG_TAG "System.out.c"#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_... 阅读全文
posted @ 2014-04-28 16:39 旅行的蜗牛 阅读(527) 评论(0) 推荐(0) 编辑
摘要: 1. Linux环境模拟,下载sygwin 安装,选择devl 和shell -> installsygwin 中的配置ndk环境,进入安装目录c:/cygwin64etc/profile文件配置ndk的环境//37行 PATH="/usr/local/bin:/usr/bin:/cygdrive/d/android-ndk-r9d-windows-x86_64/android-ndk-r9d${... 阅读全文
posted @ 2014-04-27 15:25 旅行的蜗牛 阅读(185) 评论(0) 推荐(0) 编辑
摘要: 1. singletop 模式:避免同一个界面重复开启。当栈顶已经存在这个Activity,再去开启此Activity时,则不再创建新的Activity,而是复用栈顶已经存在的Activity(图2所示),不会出现图1的情况。如Email,sms2. singletask模式:任务栈只存在一个这样的实例,若02是singtask 当任务栈如图1所示,再次打开02时,则02以上的Activity会全... 阅读全文
posted @ 2014-04-24 15:38 旅行的蜗牛 阅读(159) 评论(0) 推荐(0) 编辑
摘要: 1. 分为动态注册和静态注册, 静态注册在清单文件里配置即可.动态创建为代码手动添加. 在锁屏广播中, 使用静态创建消息接受不成功, 原因未知. 动态即可. 代码如下:2. 创建类, 继承与BroadcastReceiverpublicclassLockScreenReceiverextendsBroadcastReceiver{ //....}3. 清单文件, 添加锁屏action,静态创建.... 阅读全文
posted @ 2014-04-21 13:57 旅行的蜗牛 阅读(195) 评论(0) 推荐(0) 编辑
摘要: 1. 在ListView 中, 创建一个app_item.xml 布局文件在布局文件中有如下的代码: 而当在Activity中想去监听listview 点击消息发现没有响应, 原因在于CheckBox获取了焦点,导致ListView获取不到消息, 需要加上android:focusable="false"lv.setOnItemClickListener(newOnItemClickListen... 阅读全文
posted @ 2014-04-21 13:40 旅行的蜗牛 阅读(247) 评论(0) 推荐(0) 编辑
摘要: 1. 动画:颤动1.1 anim/shake.xml1.2 anim/cycle_71.3 实现颤动效果TextView tv = findViewById(R.id.tv);Animationshake=AnimationUtils.loadAnimation(this,R.anim.shake);tv.startAnimation(shake);2. 界面之间 Activity 切换动画效果:... 阅读全文
posted @ 2014-04-19 23:11 旅行的蜗牛 阅读(156) 评论(0) 推荐(0) 编辑
摘要: JAVA 版本为jdk-7u25-windows-x64Java 下载地址为: http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html电脑系统为Win7 64位的(版本位数需要注意对应)。1、JAVA_HOMED:\Java\jdk1.7.0_252、CLASSPATH.;%JAVA_H... 阅读全文
posted @ 2014-04-19 23:10 旅行的蜗牛 阅读(110) 评论(0) 推荐(0) 编辑
摘要: 初学Python, 对列表和字典的嵌套使用. 1 phoneBook = [] #列表 list 2 peopleInfo = {} #字典 dict 3 i=0 4 while i phone :%s'%(i, peopleInfo['name'], peopleInfo['phone']))12 i += 1来源http://www.cnblogs.com/taowen/articles/11239.aspx 阅读全文
posted @ 2013-08-22 00:41 旅行的蜗牛 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 题意:输入n, 和c 统计1 - n 有多少个素数为cnt若 2*c > cnt 则将素数全部输出否则分支判断:若cnt 为偶数,则从中心开始输出2*c 个若cnt 为奇数,则从中心开始输出2*c-1个 1 /* 2 题意:输入n, 和c 3 统计1 - n 有多少个素数为cnt 4 若 2*c > cnt 则将素数全部输出 5 否则分支判断: 6 若cnt 为偶数,则从中心开始输出2*c 个 7 若cnt 为奇数,则从中心开始输出2*c-1个 8 */ 9 #include 10 using namespace std;11 ... 阅读全文
posted @ 2013-07-23 15:25 旅行的蜗牛 阅读(210) 评论(0) 推荐(0) 编辑
摘要: 中文题深搜许久没写鸟,卡在输入问题上... 1 #include 2 #include 3 using namespace std; 4 bool flg; 5 int n; 6 char str[5000][2]; 7 bool used[5000]; 8 void dfs(int p) 9 {10 int i;11 if (p >=n || flg) return;12 if (str[p][1] == 'm') 13 {14 flg = true;15 return;16 }17 for (i=0;... 阅读全文
posted @ 2013-07-18 15:36 旅行的蜗牛 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 题意:给定一个序列,询问区间中最大数减去最小数的结果和2104差不多, 代码贴过来就OK了 1 #include 2 #include 3 using namespace std; 4 const int M = 100005; 5 int toLeft[20][M], tree[20][M], sorted[M]; 6 7 void build(int level, int left, int right) 8 { 9 if (left == right) return;10 int i, mid = (left + right) >>1;11 int supp... 阅读全文
posted @ 2013-06-28 18:41 旅行的蜗牛 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 题意:给定一个数列,求一个区间的第K大数模板题, 其中的newl, newr 有点不明白. 1 #include 2 #include 3 using namespace std; 4 const int M = 100005; 5 int toLeft[20][M], tree[20][M], sorted[M]; 6 7 void build(int level, int left, int right) 8 { 9 if (left == right) return;10 int i, mid = (left + right) >>1;11 int supp... 阅读全文
posted @ 2013-06-28 18:36 旅行的蜗牛 阅读(139) 评论(0) 推荐(0) 编辑
摘要: BFS 几天的超时...A*算法不会,哪天再看去了. 1 /* 2 倒搜超时, 3 改成顺序搜超时 4 然后把记录路径改成只记录当前点的操作,把上次的位置记录下AC..不完整的人生啊 5 */ 6 7 #include 8 #include 9 #include 10 #include 11 #include 12 using namespace std; 13 14 const int MAXX_SIZE = 362885; 15 16 int fac[] = {1,1,2,6,24,120,720,5040,40320}; 17 b... 阅读全文
posted @ 2013-06-28 17:02 旅行的蜗牛 阅读(221) 评论(0) 推荐(0) 编辑
摘要: 题意: M行N列矩阵, 'Y'表示开始位置, 'T'表示目标位置, 从开始位置到目标位置至少需要走多少步,其中, 'S', 'R'表示不能走, 'B' 花费为2, 'E'花费为1.思路:纯 BFS.很久没写BFS, 刚写居然不知道从何下手... 1 #include <iostream> 2 #include <queue> 3 using namespace std; 4 5 struct postion 6 { 7 int i, j; 8 postion operator 阅读全文
posted @ 2013-06-21 14:43 旅行的蜗牛 阅读(170) 评论(0) 推荐(0) 编辑
摘要: 题意:一个数不是质数,其质因子的每位加起来等于该数的每位加起来. 1 /* 2 题意:一个数的所有质因子的每位相加起来等于该数的每位相加起来且该数不能是质数,那么就是史密斯数 3 tip:对于分解质因子,只需要判断到i*i <= n(百度), 否则超时. 4 */ 5 #include <iostream> 6 using namespace std; 7 8 int GetSum(int n) 9 {10 int s=0;11 while (n)12 {13 s += n %10;14 n /= 10;15 }... 阅读全文
posted @ 2013-06-20 15:42 旅行的蜗牛 阅读(178) 评论(0) 推荐(0) 编辑
摘要: 题意:一个数的质因子能是2, 3, 5, 那么这个数是丑数.思路: 打表或者递推.打表:若该数为丑数,那么一定能被2 或者3, 或者5 整除, 除完之后则为1. 1 #include <iostream> 2 #include <fstream> 3 using namespace std; 4 5 int ar[]={0,1,2,3,4,5,6,8,9,10,12,15,16,18,20,24,25,27,30,32,36,40,45,48,50,54,60,64,72,75,80,81,90,96,100,108,120,125,128,135,144,150,16 阅读全文
posted @ 2013-06-20 15:40 旅行的蜗牛 阅读(306) 评论(0) 推荐(0) 编辑
摘要: 题意:欧拉函数前n项和.思路:欧拉函数欧拉函数:φ函数的值 通式:φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)…..(1-1/pn) ,其中p1, p2……pn为x的所有质因数 1 #include <iostream> 2 using namespace std; 3 const int N = 1e6+5; 4 long long phi[N]; 5 6 void Init() 7 { 8 int i, j; 9 for (i=1; i<N; i++)10 phi[i] = i;11 for (i=2; i<N; i... 阅读全文
posted @ 2013-06-15 15:59 旅行的蜗牛 阅读(190) 评论(0) 推荐(0) 编辑
摘要: 中文题思路: 扩展欧几里得扩展欧几里得给定整数a 和 b, 且满足 a*x1 + b*y1 = gcd(a, b), 求解x, y.当 b == 0 的时候, gcd(a, b) = a. 此时x= 1, y = 0.当a*b != 0的时候, 推理: 根据欧几里得可知, gcd(a, b) = gcd(b, a%b). 那么 a*x1 + b*y1 = b*x2 + a%b*y2 化解上式得到 b*x2 + (a - (a/b)*b)*y2 = a*y2 + b*x2 - (a/b)*b*y2. 而根据恒等定理可知: x1 = y2, y1 = x2 - a/b*y2 ,由此我们可以... 阅读全文
posted @ 2013-06-14 16:37 旅行的蜗牛 阅读(160) 评论(0) 推荐(0) 编辑
摘要: 参考:http://blog.csdn.net/lyy289065406/article/details/6648551有中文翻译.思路:中国剩余定理.中国剩余定理:在《孙子算经》中有这样一个问题:“今有物不知其数,三三数之剩二(除以3余2),五五数之剩三(除以5余3),七七数之剩二(除以7余2),问物几何?”这个问题称为“孙子问题”,该问题的一般解法国际上称为“中国剩余定理”。求解思路:求出除3余1的a3, 且满足a3 / 5 == 0 && a3 / 7 == 0.很显然满足条件的a3 可以是: a3 = 5 * 3 * k, 求出 k 即可.然后依次求得满足除5余1的a5 阅读全文
posted @ 2013-06-13 21:08 旅行的蜗牛 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 都说是用KMP,粗人,我就暴力一点过了吧 1 #include <iostream> 2 using namespace std; 3 char str[100000005]; 4 int main() 5 { 6 int i, k, p, len; 7 while (scanf("%s", str) != EOF && str[0] != '.') 8 { 9 len = strlen(str);10 p = k = 1;11 for (i=0; i<len; i++)12 {13 ... 阅读全文
posted @ 2013-05-13 11:00 旅行的蜗牛 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 动态规划的一个计算两个序列的最长公共子序列的方法如下:以两个序列 X、Y 为例子:设有二维数组f[i,j] 表示 X 的 i 位和 Y 的 j 位之前的最长公共子序列的长度,则有:f[1][1] = same(1,1);f[i,j] = max{f[i-1][j -1] + same(i,j),f[i-1,j],f[i,j-1]}其中,same(a,b)当 X 的第 a 位与 Y 的第 b 位相同时为“1”,否则为“0”。此时,二维数组中最大的数便是 X 和 Y 的最长公共子序列的长度,依据该数组回溯,便可找出最长公共子序列。该算法的空间、时间复杂度均为O(n^2),经过优化后,空间复杂度可为 阅读全文
posted @ 2013-05-11 17:39 旅行的蜗牛 阅读(220) 评论(0) 推荐(0) 编辑
摘要: 好吧, 这道题绕了好久,之前用int, 用 double, 最后才发现是long long 啊 而且string.h 头文件也没加 。。。。。//http://acmore.net/problem.php?cid=1015&pid=3#include <iostream>#include <stdio.h>#include <string>#include <string.h>#include <stack>using namespace std;stack<long long> stk;stack<char 阅读全文
posted @ 2013-04-29 11:05 旅行的蜗牛 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 好吧,水了有点要注意了,用ges(..)超时, scanf(...)就A掉了。。。#include <iostream>#include <stdio.h>#include <string>#include <set>using namespace std;int main (){ set<string> st; pair< set<string>::iterator, bool > pr; char str[25]; int n, m; while (scanf("%d%d", & 阅读全文
posted @ 2013-04-29 10:28 旅行的蜗牛 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 好吧,貌似每次比赛都会有个STL看样子不能水了,得好好系统看下咯。 阅读全文
posted @ 2013-04-28 11:55 旅行的蜗牛 阅读(91) 评论(0) 推荐(0) 编辑
摘要: 题意:给定一个三角数组,从top(顶) 往下走走到base(脚)求一个路线,把这些路线的数字加起来和最大。可以走左下和右下。思路:说是动态规划,但是我第一个想到的是逐点累加法,在triangle[i][j] 下一步只能是走triangle[i][j] 或者是triangle[i][j+1]。那么我们可以逆向走,即从底部往上走,那么这样就很明显的知道在第k层的 i 点,选择下一步的点当然是Maxx([k+1][i], [k+1][i+1]),因为是求最大值。 1 #include <iostream> 2 using namespace std; 3 4 const int N = 阅读全文
posted @ 2013-04-26 21:35 旅行的蜗牛 阅读(179) 评论(0) 推荐(0) 编辑
摘要: 线段树View Code 1 /* 2 poj3468 3 */ 4 #include <iostream> 5 using namespace std; 6 const int N = 100005; 7 8 struct node 9 { 10 int left, right; 11 long long num, add; 12 }tree[4*N]; 13 14 int L(int n) 15 { 16 return n<<1; 17 } 18 int R (int n) 19 { 20 return (n<<1) | 1... 阅读全文
posted @ 2013-04-24 18:51 旅行的蜗牛 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 线段树资料:http://dongxicheng.org/structure/segment-tree/PS: 以HDU1166为例线段树的使用一般分如下几个操作建树插入查询建树 建树的操作类似与构建一个二叉树,是一个递归的过程void build(int l, int r, int step) { tree[step].left = l; tree[step].right = r; tree[step].add = 0; if (l == r) //到达叶子节点了 { tree[step].num = a[l]; ... 阅读全文
posted @ 2013-04-24 10:07 旅行的蜗牛 阅读(243) 评论(0) 推荐(0) 编辑
摘要: 原文:http://www.cppblog.com/mythit/archive/2009/04/21/80633.html感谢极限定理的详细解答,对于AC自动机终于算是弄明白了。下面的是自己的一些理解。(依旧是以HDU2222为例,插图也是极限定理的,思路是极限定理的,代码可是自己敲的)在AC自动机主要有下面几步:构建字母树,即trie 树。构造失败指针查找详细步骤:构建trie树构建一个根节点1 node *root = new node;插入单词 1 void insert(char *str, node *root) 2 { 3 node *p = root; 4 ... 阅读全文
posted @ 2013-04-22 13:56 旅行的蜗牛 阅读(254) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1874中文题,纯单源最短路径。题目有点小坑,就是在输入权值时,要判断下,如:之前输入了g[1][4] = 100, 但是可能后面还有输入g[1][4] = 200View Code /** * DIJKSTRA(简单版) 单源最短路径算法(不允许存在负边) * 输入:(1)图g; // 有向图或者无向图 * (2)源点s。 * 输出:(1)源点s到各点的最短路径长dist; * (2)源点s到各点的最短路径prev。 * 结构: 图g用邻接矩阵表示,最短路径长dis... 阅读全文
posted @ 2013-04-13 18:25 旅行的蜗牛 阅读(190) 评论(0) 推荐(0) 编辑
摘要: 线段树覆盖+离散化View Code 1 /* POJ2528 2 本题: 线段树+离散化 3 http://blog.csdn.net/tsaid/article/details/6665764 4 http://blog.csdn.net/lyy289065406/article/details/6799170 5 但是这题单纯用线段树去求解一样不会AC,原因是建立一棵[1,1QW]的线段树,其根系是非常庞大的,TLE和MLE是铁定的了。所以必须离散化。 6 通俗点说,离散化就是压缩区间,使原有的长区间映射到新的短区间,但是区间压缩前后的覆盖关系不变。举个例子: 7 ... 阅读全文
posted @ 2013-04-13 14:51 旅行的蜗牛 阅读(197) 评论(0) 推荐(0) 编辑
摘要: 题意:首先给定一些字符串(字典),然后再输入一个字符串,然后在字典里面查找看是否有,有则输出没有则需要你纠正,纠正的原则是替换一个字符插入一个字符删除一个字符View Code 1 /* 2 poj1035 3 题意:给定一些字典里面的字符串,以#表示结束,然后再给定一个字符串str 4 若在字典里面能够找得到则输出:cout<<str<<" is correct"<<endl; 5 若没有,则按如下规则: 6 删除一个字母在字典里是否有 7 ... 阅读全文
posted @ 2013-04-12 12:53 旅行的蜗牛 阅读(285) 评论(0) 推荐(0) 编辑