摘要:
#include #include using namespace std; struct race { double p,h,c,flag; }; race r[101]; bool cmp(race a,race b) { //if() return a.flag... 阅读全文
posted @ 2014-12-11 17:51
__夜风
阅读(294)
评论(0)
推荐(0)
摘要:
#include #include using namespace std; struct p { int endd,start; }; p p1[1000]; bool cmp(p p1,p p2) { return p1.endd>t&&t) { ... 阅读全文
posted @ 2014-12-11 17:50
__夜风
阅读(190)
评论(0)
推荐(0)
摘要:
选择排序、快速排序、希尔排序、堆排序不是稳定的排序算法, 冒泡排序、插入排序、归并排序和基数排序是稳定的排序算法。 冒泡法: 这是最原始,也是众所周知的最慢的算法了。他的名字的由来因为它的工作看来象是冒泡: 复杂度为O(n*n)。当数据为正序,将不会有交换。复杂度为O(0)。 直接插入... 阅读全文
posted @ 2014-12-11 17:48
__夜风
阅读(137)
评论(0)
推荐(0)
摘要:
#include #include using namespace std; int main() { double a,b,c,d,e,f,t; while(cin>>t){ if(t==0) break; else { while... 阅读全文
posted @ 2014-12-11 17:45
__夜风
阅读(167)
评论(0)
推荐(0)
摘要:
#include using namespace std; int main() { int i,t,n; int a[101]; cin>>t; while(t--) { cin>>n; if(n==1) cout<<... 阅读全文
posted @ 2014-12-11 17:44
__夜风
阅读(100)
评论(0)
推荐(0)
摘要:
#include #include #include using namespace std; int cmp(int a,int b) { return a>b; } int main() { int i,t,a[10010]; cin>>t; for(i... 阅读全文
posted @ 2014-12-11 17:41
__夜风
阅读(110)
评论(0)
推荐(0)
摘要:
#include #define N 10010 using namespace std; int a[N],b[N]; int prime(int a) { int i; for(i=2;i*i>t>>x){ h=t;g=x; int ... 阅读全文
posted @ 2014-12-11 17:40
__夜风
阅读(205)
评论(0)
推荐(0)
摘要:
#include #include #include #define LL __int64 using namespace std; bool ss(LL a) { LL i; for(i=2;i*i>m; s=(LL)sqrt(m+0.5); ... 阅读全文
posted @ 2014-12-11 17:40
__夜风
阅读(84)
评论(0)
推荐(0)
摘要:
#include using namespace std; int prime(int a) { int i; for(i=2;i*i>t&&t){ m=n=t; if(prime(t)==0) cout<<"0"<<endl; ... 阅读全文
posted @ 2014-12-11 17:38
__夜风
阅读(85)
评论(0)
推荐(0)
摘要:
#include #include #include #include using namespace std; char a[10001]; int main() { int i,t,flag,n; cin>>t; getchar(); stack s;... 阅读全文
posted @ 2014-12-11 17:37
__夜风
阅读(111)
评论(0)
推荐(0)
摘要:
#include #include #define INF 9999999 //#define INF 0x3f3f3f3 using namespace std; int vis[200],dis[200],Map[200][200]; int dijkstra(int n,int x) ... 阅读全文
posted @ 2014-12-11 17:36
__夜风
阅读(166)
评论(0)
推荐(0)
摘要:
#include #include using namespace std; const int INF=0x3f3f3f3f; int dis[110][110]; int main() { int i,j,k,n,m,p,q,s; while(scanf("%d%d",&... 阅读全文
posted @ 2014-12-11 17:34
__夜风
阅读(156)
评论(0)
推荐(0)
摘要:
#include using namespace std; int M[101][101]; int main() { int i,j,m,n,a,b,k; int flag; while(cin>>n>>m){ //flag=1; fo... 阅读全文
posted @ 2014-12-11 17:34
__夜风
阅读(80)
评论(0)
推荐(0)
摘要:
#include #include #include using namespace std; int main() { int sum,m,len,t,i,k,s; char a[1001]; while(cin>>t) { sum=0; ... 阅读全文
posted @ 2014-12-11 17:30
__夜风
阅读(149)
评论(0)
推荐(0)
摘要:
#include #include using namespace std; struct money { int s; int v; }; bool cmp(money a,money b) { return a.s>b.s; } int main() { money M[101]... 阅读全文
posted @ 2014-12-11 17:28
__夜风
阅读(168)
评论(0)
推荐(0)
摘要:
#include #include #include #include using namespace std; int f[1000]; int digree[1000]; int find(int x) { while(x!=f[x]) x=find(f[x]); ret... 阅读全文
posted @ 2014-12-11 17:27
__夜风
阅读(191)
评论(0)
推荐(0)
摘要:
#include #include #include using namespace std;int Map[1001][1001],vis[1001][1001];int stx,sty,enx,eny,n,m,flag;int xx,yy,turn,k,i,j;int dx[]={1,0... 阅读全文
posted @ 2014-12-11 15:08
__夜风
阅读(215)
评论(0)
推荐(0)
摘要:
#include #include #include using namespace std;int M[101][101],flag[101][101];int n,m;int cnt;void pool(int x,int y){ flag[x][y]=1; M[x][y]=cn... 阅读全文
posted @ 2014-12-11 15:05
__夜风
阅读(162)
评论(0)
推荐(0)
摘要:
#include #include using namespace std;int main(){ int n,i; int a[4]={1,2,3,4}; //cin>>n; while(next_permutation(a,a+4)){ for(i=0;iusi... 阅读全文
posted @ 2014-12-11 15:04
__夜风
阅读(193)
评论(0)
推荐(0)
摘要:
#include using namespace std;int main(){ int a[51][51],b[51][51],c[51][51],i,j,k,l,m,n; while(cin>>m>>n>>k,m+n+k>0) { for(i=1;i>a[i]... 阅读全文
posted @ 2014-12-11 15:03
__夜风
阅读(98)
评论(0)
推荐(0)
摘要:
//hdu2190 水题 题意是给一个n*3的教室,用1*1,2*2的砖去铺满,有多少种铺法,一开始没发现这个规律,想了一下,应该是递归。 #include using namespace std;int main(){ int i,t,a[31],n; a[1]=1;a[2]... 阅读全文
posted @ 2014-12-11 14:55
__夜风
阅读(169)
评论(0)
推荐(0)
摘要:
//hdu2189 题意大概就是给n个人,分成多组,要求每组人数都是素数,求有多少种。。。 解法就是先把150以内的素数全部存入一个数组,然后利用a[j+b[i]]+=a[j];这道题一开始没理解这步 后面把i做完一次循环的结果输出,然后对比下i全部做完循环的结果,原来这个也是隐藏的递归,解... 阅读全文
posted @ 2014-12-11 14:54
__夜风
阅读(187)
评论(0)
推荐(0)
摘要:
hdu 1087 这道题是用dp做出来的,也算是很巧妙的方法。。。。 思路:首先第一个for遍历1-n,这个时候先设一个flag=0 然后在遍历从1到i,因为题目求得是单调最长序列的和 所以j每次都要在i前面,然后在满足啊a[i]>a[j]的情况下 用flag记下j前面序列和的最大值,在遍历完j... 阅读全文
posted @ 2014-12-11 14:54
__夜风
阅读(147)
评论(0)
推荐(0)
摘要:
这个是暴力枚举求解的 //hdu1003 这一题的代码我也不愿意整理了,乱就乱吧 这一道题已经写了至少五遍了,也没什么好说的了,核心代码就是第二个for那里 自己在纸上写写就清楚了,后面一个for找最大,然后依据这个最大的 可以推出是从哪里开始的,根据就是每次往回加一个 然后判断和是否等于最... 阅读全文
posted @ 2014-12-11 14:38
__夜风
阅读(182)
评论(0)
推荐(0)
摘要:
//这一题是 nyoj 36 是一道求最长公共子序列的题,也是用dp做出来的 核心代码也就是一句,题目大概思路是先找到两组字符串里面相同的字母 在二维数组里面更新每次比较过后dp的值,空想很难理解,自己在纸上画画就知道了 实在不行就把那段代码记下来。。。 还有我一直都不明白为什么我把dp数组... 阅读全文
posted @ 2014-12-11 14:38
__夜风
阅读(142)
评论(0)
推荐(0)
摘要:
//nyoj 214 这个题目和字符串的问题类似,都是给出一组数据,寻找最长的单调递增字符 这一题一开始我用dp做,发现超时,看了下时间,n*n的复杂度,换过一种思路 用类似于栈的方式,来存储每次更新过后的单调序列,里面二分查找很容易理解 就是数组作用开始比较难理解,大致思路是先把输入数组的第一... 阅读全文
posted @ 2014-12-11 14:38
__夜风
阅读(143)
评论(0)
推荐(0)
摘要:
// nyoj 17 代码如上,用的是dp,总的来说就是对一个字符串 从末尾开始比较,设定一个数组,存放每个单调字串的最大长度,最后比较。。。 //要注意的就是里面if语句对于每次字符比较后,更新数组,自己在纸上画画就清楚了。。。 #include #include usin... 阅读全文
posted @ 2014-12-11 14:37
__夜风
阅读(142)
评论(0)
推荐(0)
摘要:
#include using namespace std;struct race{ int p; int w;};race r[1010];int cmp(race &x,race &y){ return x.p>t; while(t--) { dou... 阅读全文
posted @ 2014-12-11 13:15
__夜风
阅读(134)
评论(0)
推荐(0)
摘要:
#include #include using namespace std;struct p{ int endd,start;};p p1[1000];bool cmp(p p1,p p2){ return p1.endd>t&&t) { for(i=0;i>p1... 阅读全文
posted @ 2014-12-11 13:15
__夜风
阅读(150)
评论(0)
推荐(0)
摘要:
// hdu1022 这题算是我做的第一道栈的题目,之前看过栈的一些内容,做这道题的时候,可以模拟出过程,但是具体的代码不会写。。。所以决定练习一些栈和队列的问题,大概思路就是有三个数组和一个栈,先把第一个数组的第一个元素放进栈里,每次判断第二个数组和栈顶元素是否相等,如果相等就弹出,如果不相等... 阅读全文
posted @ 2014-12-11 13:08
__夜风
阅读(116)
评论(0)
推荐(0)
摘要:
hdu 2689 超级大水题。。。。两种代码都过了,开始以为n^2会tle,后来竟然过了。。。汗 注意下cin写在while里面,就可以了 #include using namespace std;int main(){ int n,i,j,a[1010]; while(ci... 阅读全文
posted @ 2014-12-11 13:07
__夜风
阅读(151)
评论(0)
推荐(0)
摘要:
//这两道题的代码是关于二叉树的。。。题意:给一个树的深度和小球个数,这棵树按从上到小,左到右依次编好号。。每次小球从根节点下落,相应的根节点状态改变,如果为闭合状态,则小球向左下落,如果是开启状态,那么小球向右下落,求最后一个小球的落得节点序号。。。。 这道题目说明的树节点存在父节点为k,那么... 阅读全文
posted @ 2014-12-11 13:03
__夜风
阅读(163)
评论(0)
推荐(0)
摘要:
//nyoj 44 //和上面一题一样,求子串和,但是代码非常简洁。。。。。 时间复杂度为n #include using namespace std;int main(){ int i,t,n,first,later; cin>>t; while(t--) ... 阅读全文
posted @ 2014-12-11 12:52
__夜风
阅读(147)
评论(0)
推荐(0)
摘要:
// 再一次复习 最长单调递增子序列dp求法 // 以前有过一次专门的总结,现在有点忘了,拿出来看看 // 目前为止,我做过的这类题目就1.最长子序列和 2.字母和数字单调最长序列。。。后面继续总结 #include #include #include #include using n... 阅读全文
posted @ 2014-12-11 12:46
__夜风
阅读(181)
评论(0)
推荐(0)
摘要:
//这一次补上链表的注释,代码是空闲的时候敲出来的,如果有错,希望帮忙纠正 //部分给出了详细说明,这里只选取了基本操作,因为更复杂的链表操作太繁琐,这里就不写了 //如果有什么不懂的地方,可以随时询问 #include using namespace std;typedef int Ele... 阅读全文
posted @ 2014-12-11 12:44
__夜风
阅读(152)
评论(0)
推荐(0)
摘要:
#include int a[1005000]; int main() { int t; scanf("%d",&t); while(t--) { long long sum=0; int Max=0,i,n; scanf("%d",&n); for(i=1;iMax)... 阅读全文
posted @ 2014-12-11 12:44
__夜风
阅读(172)
评论(0)
推荐(0)
摘要:
这段代码对一些读入的非法数据判断存在错误 比如像出现 a++b 就无法判断了 另外需要注意的是我觉得栈里面存储的是char型的,但是在操作数值的时候,会很不方便 还有一点在主函数里面如果想用while来多次读入数据的话,那么你要考虑上一次输入数据失败后,那后面的字符该怎么操作 上面出现的问题大家... 阅读全文
posted @ 2014-12-11 12:42
__夜风
阅读(281)
评论(0)
推荐(0)
摘要:
//hdu 1728 //这个是一道很经典的迷宫题了,思路感觉。。。取起点和终点,判断连线是否超过n个弯, //先是从起点出发,上下左右四个方向搜索,找到一条路,把那条路的第一个点压入队列 //然后沿着那个方向一直搜下去,直到不符合条件(4个方向都动不了),就从队列里面去首元素 //然后不断循环... 阅读全文
posted @ 2014-12-11 12:39
__夜风
阅读(219)
评论(0)
推荐(0)
摘要:
//题目是求N!的问题,思路:设定一个整形数组来存放每次计算过后的值 有两个for循环,第一个for循环每次加进一个数 然后在第二个for循环里面计算出此时的阶乘,比如9999,先给出i=2 在第二个for循环里面计算出2的阶乘,保存在数组里,然后i=3,在计算3的阶乘,后面以此类推。。。 #i... 阅读全文
posted @ 2014-12-11 12:38
__夜风
阅读(148)
评论(0)
推荐(0)
摘要:
//nyoj 37 代码有点乱,和最长公共子序列很像,只是多加了一个数组,之前调用函数, 一直超时,可是我看了下,为什么用一个整形数组存放倒置字符串 竟然可以AC,我测试了下数据,打印出来的是一串地址,为什么为什么为什么啊。。。。 #include #include #define Max... 阅读全文
posted @ 2014-12-11 12:35
__夜风
阅读(182)
评论(0)
推荐(0)

浙公网安备 33010602011771号