03 2012 档案
摘要:Linux大致把进程分类三类1.Interctive process与用户交互比较多的进程,一时开始,必需控制其响应时间。如shell,文本编辑,图像处理等进程。2.Batch process与用户交互不多,但需要大量计算,占用CPU的进程。如编译器,数据库。3.Real-time process对响应时间要求更为严格,一旦提交,必需马上处理。如视频播放,机器控制等进程。显然,这三类进程,在调度时...
阅读全文
摘要:昨天写了一下interrupt和exception的不同,在弄清以后,可以来研究linux kernel中的各种同步机制,各种锁了。先写一下Spin Lock,其余的有时间再写。Spin Locks这个是很常见的,好多地方翻译成“自旋锁”,在临界区只允许一个进程进入(且该进程不允许休眠,例如中断处理程序)时经常使用。spin lock使用spinlock_t结构体来实现,其定义在/include/...
阅读全文
摘要:由于阅读内核时经常遇到各种各样的锁,以前没去太在意它们,终于忍不住了,决心把内核中的锁搞清楚。为了使并发程度达到最大,不同的情况下需要使用不同的锁,在了解各种锁之前,需要先搞清两个很容易混淆的概念,国内很多书籍对这两个概念是不区分的,其实,在内核中,对它们的处理是有不同的,其中很大一个不同就是运行所对应的handler时中断是否关闭,所以,又由此引出了不同锁的使用。废话不说,上原文,配合自己写的理...
阅读全文
摘要:折腾了大半天,算是搬家成功了吧。其实很早就有一个想法,自己去买个虚拟主机,建个博客,写些字记录一下自己。QQ空间不适合记录技术,cnblogs不适合记录生活。一个偶然的机会,进了一个网友的百度空间,看到说RED_HAT推出有免费云服务,可以自己建立应用,包括php。便拿来试手了,折腾了大半天,总算是有些模样了,还有感谢某网友开发的cnblogs导出到wordpress plugin。唯一的不足是我...
阅读全文
摘要:http://pat.zju.edu.cn/contests/pat-practise/1028 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <algorithm> 5 using namespace std; 6 struct Stu{ 7 char ID[7]; 8 char name[9]; 9 int score;10 }student[100002];11 int meth;12 bool cmp(struct Stu a,str
阅读全文
摘要:不想调程序,来学下LaTeX,毕竟以后肯定会用到。写这些也参考了tsinghua某老师的LaTeX学习笔记,只为加深自己的印象,还有以后用到时方便查询。首先,LaTeX文档主要分三部分,文档类声明,序言,正文。文档类声明即1 \documentclass{}其中,括号内可填 article , report , book,其实,就是说,LaTeX针对这几种不同的文档类型提供了不同的默认设置,比如字体大小等。序言部分可以引入额外的宏包,比如开源社区ftp上就有西电的毕业论文宏包(明年毕业时直接拿来用了~)如果是article的话,肯定要有标题,作者,写作日期等标识信息,这些通过如下命令实现1 \
阅读全文
摘要:http://pat.zju.edu.cn/contests/pat-practise/1029一招鲜也有不好使的时候,sort和qsort均不好使,超时。只好自己写,其实就是merge sort,唯一担心的就是内存了,还好不超。 1 #include <stdio.h> 2 int num1[1000002]; 3 int num2[1000002]; 4 int num_fin[2000002]; 5 int main() 6 { 7 int len1,len2; 8 scanf("%d",&len1); 9 int i;10 for(i=0;i&l
阅读全文
摘要:http://ac.jobdu.com/problem.php?id=1420其实就是0-1背包,要求两集合之差绝对值最小,不妨求“当背包容量为所有数之和一半时,能放入背包的总重量",求出这个来,结果就出来了动态分配的内存,因为有的数据比较大,怕超内存。还有,就是内存在使用之前一定要初始化,malloc是不会自动初始化的。 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 int max(int a,int b) 5 { 6 return a>b?a:b; 7
阅读全文
摘要:http://ac.jobdu.com/problem.php?id=1416 1 #include <stdio.h> 2 #include <algorithm> 3 #include <string.h> 4 using namespace std; 5 int n,m; 6 struct Monkey{ 7 char name[101]; 8 int stronger_level; 9 int food_to_eat;10 int need;11 }monkey[10005];12 bool cmp(struct Monkey a,struct Mo
阅读全文
摘要:http://ac.jobdu.com/problem.php?id=1419 1 #include <stdio.h> 2 #include <string.h> 3 #include <algorithm> 4 using namespace std; 5 struct Record{ 6 char orig_name[201]; 7 char trans_name[201]; 8 }record[201]; 9 void trans(int n)10 {11 int i;12 for(i=0;i<=strlen((record[n].orig_n
阅读全文
摘要:算出位置公式,然后直接模拟就可以,代码写的比较不整齐,好久不写的原因 analysis里面居然给出了打表的方式,USACO不是禁止这样么 1 /* ID:linyvxi1 2 PROB:runround 3 LANG:C++ 4 */ 5 #include <stdio.h> 6 int div_num[33]; 7 bool visited[33]={false}; 8 int len=0; 9 bool trans(int n)10 {11 int j=0;12 int div_cpy[33];13 bool num[10]={false};14 ...
阅读全文
摘要:http://ac.jobdu.com/problem.php?id=1398静下来分析就行了,不过这题的描述有漏洞,说的是两两交换,没有说必需是相邻的两个才能交换啊还有,注意最大值最小值不唯一的情况 1 #include <stdio.h> 2 int main() 3 { 4 int num[202]; 5 int n; 6 while(scanf("%d",&n)!=EOF){ 7 int i; 8 int max_num=-1; 9 int min_num=500;10 int max_pos=-1...
阅读全文
摘要:http://ac.jobdu.com/problem.php?id=1399显然是贪心,不过忘了jewellery[i].w,jewellery[i].v中全是整数,做除法要乘以1.0,WA了N次。。看来这东西一旦放下手就不热了。。 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <algorithm> 4 using namespace std; 5 6 struct Jewe{ 7 int v,w; 8 }jewellery[100010]; 9 bool cmp(struct Jewe a,
阅读全文
摘要:在这之前做过九度的题,题目只要求判断能否构成那样的划分,没有让求不同划分的个数,所以dfs就能过,这题dfs到36时超时,各种剪枝都无效。。后来看的题解,原来是DP。。。学习了先贴DP代码,再贴DFS的超时代码 1 /* ID:linyvxi1 2 PROB:subset 3 LANG:C++ 4 */ 5 #include <stdio.h> 6 int main() 7 { 8 freopen("subset.in","r",stdin); 9 freopen("subset.out","w",st
阅读全文
摘要:暴力 1 /* ID:linyvxi1 2 PROB:hamming 3 LANG:C++ 4 */ 5 #include <stdio.h> 6 #include <math.h> 7 #include <stdlib.h> 8 int N,B,D; 9 int max_search_num;10 int final_result[130];11 int num_found;12 13 bool check(int next)14 {15 int s=0;16 for(;s<num_found;s++){17 int temp;18 temp=ne.
阅读全文

浙公网安备 33010602011771号