`
zqynux
  • 浏览: 35593 次
  • 性别: Icon_minigender_1
  • 来自: 湖南
社区版块
存档分类
最新评论
文章列表
  今天才了解volatile的功能, 以前只知道它修饰变量的, 让变量每次操作时都要从内存中读取, 而不使用寄存器来临时存储. 今天才知道还有这么一个超级好的功能!   能够修饰无返回值的函数, 如: void have(void); void volatile abc(void) { //do something have(); } int main(void) { abc(); return 0; }   比如上面这个函数, 如果abc没有volatile修饰的话, 那么程序调用的过程是,  main->abc->have 当have执行完了之后再 ...
  学<<数据结构与算法分析>>真的过瘾啊, 书写得好, 一个例子一个例子的讲解, 废话也不多,, 在这里批评一下严蔚敏同志,, 书写的确实没外国的教材好~!   这本书的例子都很简单, 但简单里面各个都透着大道理,, 现在看链表, 提到了程序的移植,, 以前一直以为程序的移植不是什么大事,, 但是在看来, 应该叫做算法的移植, 程序真的只是工具, 算法才是灵魂, 一个程序快, 不能够说是写这个程序的语言有多么多么的厉害(要说也有关系, 曾经看到一本书, Unix系统用C写比用汇编写慢20%以上~!), 主要是这个程序员有多么多么的厉害, 他拥有多么强大的算法~!   ...
  狂抓,,, 这么简单的一个算法,, 写了我好久好久``!!!   日啊~!~!~! void insertsort(int *a, int len) { int i, j, t; for(i = 1; i < len; i++){ if(a[i] < a[i - 1]){ t = a[i]; for(j = i - 1; j >= 0 && t < a[j]; j--){ a[j + 1] = a[j]; } a[j + 1] = t; } } }
/* LANG: C ID: zqynux11 PROG: beads */ #include <stdio.h> #include <string.h> char ball[701]; int main(void) { int max = 0; int a = 0, b = 0, w = 0; /* */ int i, n; char ch = '\0'; freopen("beads.in", "r", stdin); freopen("beads.out" ...
  解释什么的就算了吧,, /* LANG: C ID: zqynux11 PROG: friday */ #include <stdio.h> #include <string.h> int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int week[7]; int main(void) { int today = 0; int n, i, j; freopen("friday.in", "r", stdin) ...
  这题的话, 我用的是个结构体, 记录各个人.. 我错了的地方我注释了` /* LANG: C ID: zqynux11 PROG: gift1 */ #include <stdio.h> #include <string.h> struct people{ char name[15]; int given, got; }pep[10]; int np; int find(char *str) { int i; for(i = 0; i < np; i++){ if(strcmp(str, pep[i].name ...
  不解释了.. /* LANG: C ID: zqynux11 PROG: ride */ #include <stdio.h> #define loop(i, j)\ p = i;\ while(*p != '\0'){\ j *= *p - 'A' + 1;\ p++;\ }/* 之前将p++掉了.. */ int main(void) { char ufo[7], name[7]; char *p; int a = 1, b = 1; freopen("ride.in", "r", ...
  这题二话不说, 用map[i][j]表示坐标为i, j的点是什么颜色的.. 很快就写出来了, 但是内存超过了,, 内存最多16MB.   没办法, 只好另辟思路, 但是在数据压缩方面我又很弱, 就看标程也花了两三天的时间, 今天终于是看懂了..   用rect记录所有矩形的坐标以及相应的颜色.   程序具体的步骤如下:   输入A, B, N. 记录第一个矩形: (0, 0) (A, B), 颜色为1   接着读入其余的矩形, 设当前是第i个   对i之前所有的矩形迭代, 此时迭代到的是第j个.   判断i是否完全包含j, 即: i.x1 >= j.x1 && i.x ...
  这是一种和二分比较相似的查找的算法, 不过不同的是, 对于分布比较均匀的较大的数组, 插值查找有时能够一次就搜索到位..   为什么能够这么快呢`? 看网上没有什么关于这种算法的描述, 我就来描述一下吧.   首先要知道一点, 这种搜索方式只能够针对顺序表进行,, 再一个要理解顺序表中的一个特点, 在顺序表中查找是否存在一个值, 此时我可以对顺序表中的任意一个元素进行比较, 如果我要在A中寻找值为t的元素是否存在, 那么我用a[i]和t进行比较, (a[i]可以是顺序表中任意一个元素..), 如果a[i]==t的话, i就是t所在的位置, 如果a[i] > t,  那么说明t一定不在在 ...

折半搜索

  折半搜索的思想很简单, 就是假设有一个集合S={a1, a2, a3, a4...an}, 其中满足(a[i-1] < a[i]).. 折半的就先和中间的比较, 如果比中间值的大, 如果t在集合里面的话, 那么就一定只会在后半段了, 不会在前半段.. 以此类推吧`` int search(int *a, int size, int t) { int low, high, mid; low = 0; high = size - 1; while(low <= high){ mid = (low + high) / 2; if(t == a[mid]){ ...
  从这一题开始,, 以后题目我就不贴上来了... 自己去看吧..   这一题开始肯本看不懂,, 后来是反反复复看标程看懂了..   首先要理解这么一个式子吧(算是式子吧``)   已经求出了j-1个丑数,, 现在求第j个丑数   对于每一个素数p乘以一个最小的丑数, 能使积大于第j-1个丑数     在这些乘积中寻找最小的一个即位第j个丑数.   用pindex[i]表示对于第i个素数乘以的最小丑数是多少.. /* LANG: C ID: zqy11001 PROG: humble */ #include <stdio.h> #include <string.h ...
Score Inflation The more points students score in our contests, the happier we here at the USACO are. We try to design our contests so that people can score as many points as possible, and would like your assistance. We have several categories from which problems can be chosen, where a "categ ...
Agri-Net Russ Cox Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He needs your help, of course. Farmer John ordered a high speed connection for his farm and is going to share his connectivity with the other ...
Fractions to Decimals Write a program that will accept a fraction of the form N/D, where N is the numerator and D is the denominator and print the decimal representation. If the decimal representation has a repeating sequence of digits, indicate the sequence by enclosing it in brackets. For example, ...
Bessie Come Home Kolstad & Burch It's dinner time, and the cows are out in their separate pastures. Farmer John rings the bell so they will start walking to the barn. Your job is to figure out which one cow gets to the barn first (the supplied test data will always have exactly one fastest cow). ...
Global site tag (gtag.js) - Google Analytics