码迷,mamicode.com
首页 >  
搜索关键字:循环 if for while case    ( 74454个结果
质因数的求法
质因数分解 /* 求质因数 */ #include #include int main() { int n,a=2; printf("please input n:"); scanf("%d",&n); if(n<=1) { printf("input error!\n"); return -1; } while(a*a < n) { while(n%a==0) ...
分类:其他好文   时间:2014-05-26 05:50:40    阅读次数:279
uva 1350 - Pinary(dp+计数)
题目链接:uva 1350 - Pinary 题目大意:给出n,输出第n给Pinary Number,Pinary Number为二进制数,并且没有连续两个1相连。 解题思路:dp[i]表示到第i位有dp[i]种,于是给定n,一层循环判断dp[i]≤n的话,就输出1,并且n减掉dp[i],注意输出0的时候,不能输出前导0. #include #include typedef l...
分类:其他好文   时间:2014-05-26 04:38:12    阅读次数:212
LeetCode: Pow(x, n) [049]
【题目】 Implement pow(x, n). 【题意】 实现pow(x, n) 【思路】 最直接的思路是用一个循环,乘n次的x。 当n的值较小的时候还好,当n非常大时,时间成本就非常高。加入n=INT_MAX, 也就是21亿多次循环,你可以试想一下。 在这种情况下,我们需要快速的乘完n个x,采用尝试贪心的方法,即滚雪球方式的翻倍相乘 注意:几种特殊情况 1. n=0; 2. n<0;...
分类:其他好文   时间:2014-05-26 04:37:31    阅读次数:212
2014 BNU 邀请赛B题(枚举)
Beautiful Garden 题意:x轴上放了一些树,现在要移动一些树使得所有树都等间距,问最少要移动多少棵 思路:枚举,枚举第一棵树,和另一棵树,以及中间有多少树,这样就能知道等差数列的首项和公差,然后再循环一边计算出答案,保存最小值 代码: #include #include #include #include using namespace std; #define...
分类:其他好文   时间:2014-05-26 04:28:52    阅读次数:233
51系列小型操作系统精髓 简单实现12 C语言版再优化
CRTOS 实时可剥夺型内核 1.任务不用预加载,不用预定义。任务调用时加载,可删除(退出死循环即可) 2.单位轮转查询时间由晶振和定时器初始化决定。在这里为10ms 3.定时时间为【 time*单位轮转查询时间 】 ,其中time为 rtos_wait(time)中time. 4.可运行多个任务【自定义】 5.任务从rtos_wait()处切换,在定时时间到后从定时中断中切换回来,任务执行后,回到中断,再从中断回到主程序。...
分类:编程语言   时间:2014-05-26 03:59:52    阅读次数:323
【LeetCode】Climbing Stairs
题目 You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? 解答...
分类:其他好文   时间:2014-05-25 00:37:34    阅读次数:284
【练习题】编写打印出一个单链表的所有元素的程序【链表】
只是实现了链表ADT的部分功能。 /*---编写打印出一个单链表的所有元素的程序---*/ #include #include struct Node{ int val; struct Node *next; }; Node *findEnd(Node *list){ while(list->next) list = list->next; return list; } v...
分类:其他好文   时间:2014-05-24 22:30:37    阅读次数:232
Accelerated C++学习笔记7—<使用顺序容器并分析字符串>
第6章  使用库算法 本章中主要教我们如何使用几个库算法来解决与处理字符串和学生成绩相关的问题。 1、分析字符串 使用一个循环来连接两幅字符图案 for(vector::const_iterator it = bottom.begin(); it != bottom.end(); ++it) ret.push_back(*it); 等价于 ret.insert(ret.end(...
分类:编程语言   时间:2014-05-24 20:24:10    阅读次数:365
LeetCode: Anagrams [048]
【题目】 Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be in lower-case. For example: Input:  ["tea","and","ate","eat","den"] Output: ["tea","ate","eat"] 【题意】 anagrams指的是颠倒字母顺序构成的单词,以tea为例,则与它an...
分类:其他好文   时间:2014-05-24 18:36:01    阅读次数:317
【练习】P62页3.2题
/*---给你一个链表L和另一个链表P,它们包含以升序排列的整数。操作PrintLots(L,P) 将打印L中那些由P所指定位置上的元素。---*/ #include #include struct Node{ int val; struct Node *next; }; Node *findEnd(Node *list){ while(list->next) list = l...
分类:其他好文   时间:2014-05-24 14:27:42    阅读次数:224
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!