上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 28 下一页

2012年8月13日

使用STL的next_permutation函数生成全排列(C++)

摘要: 下午研究了一下全排列算法,然后发现C++的STL有一个函数可以方便地生成全排列,这就是next_permutation在C++ Reference中查看了一下next_permutation的函数声明:#include <algorithm>bool next_permutation( iterator start, iterator end );Thenext_permutation() function attempts to transform the given range of elements [start,end) into the next lexicographi 阅读全文

posted @ 2012-08-13 10:16 mycapple 阅读(400) 评论(0) 推荐(0) 编辑

NYOJ 469 擅长排列的小明 II

摘要: 地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=469题目大意:给你一个正整数n,序列1,2,3,4,5......n满足以下情况的排列:1、第一个数必须是12、相邻两个数之差不大于2你的任务是给出排列的种数。题目分析:由于第一个只能是1,则第二个数只能是2,3当第二个数是2时,则相当于是对2-n的排列,相当于对1-(n-1)的排列,即s[n-1];当第二个数是3时,第三个数只能是2,4,5此时,当第三个数为2时,则是对3-n的排列,相当于对1-(n-3)的排列,即s[n-3] 当第三个数为4时,此时,第四个数只能是2,除了n等于4时.. 阅读全文

posted @ 2012-08-13 09:56 mycapple 阅读(273) 评论(0) 推荐(0) 编辑

NYOJ 19 擅长排列的小明 (排列组合)

摘要: 地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=19算法分析:暴力排列,递归,不太懂 1 #include<stdio.h> 2 int n,a[10]; 3 bool vis[10];//标示数字是否被用过 4 void f(int k,int m)//k用来给a中第k个元素赋值,m表示还需要寻找的数字个数 5 { 6 for(int i=1;i<=n;++i) 7 { 8 if(!vis[i]) a[k]=i; //未被标记赋值 9 else continue;... 阅读全文

posted @ 2012-08-13 09:29 mycapple 阅读(960) 评论(0) 推荐(0) 编辑

NYOJ 205 求余数

摘要: 同余定理(a+b)mod m=((a mod m)+(b mod m))mod m;a*b mod m=(a mod m)*(b mod m) mod m;a^b mod m=(a mod m)^b mod m; 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 char num[1000010]; 5 int main() 6 { 7 long int i; 8 int n,temp,t; 9 scanf("%d",&n);10 while(n--)1 阅读全文

posted @ 2012-08-13 08:36 mycapple 阅读(207) 评论(0) 推荐(0) 编辑

2012年8月12日

NYOJ 267 郁闷的C小加(二)

摘要: 地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=267 1 //本题是nyoj35与nyoj257的综合 2 #include<stdio.h> 3 #include<stdlib.h> 4 #define N 1010 5 char s[N]; 6 int i; 7 //字符栈的操作 8 typedef struct 9 { 10 char *base; 11 char *top; 12 }SqStack1; 13 int InitStack1(SqStack1 &S) 14 { 15 S.base=(c 阅读全文

posted @ 2012-08-12 16:57 mycapple 阅读(197) 评论(0) 推荐(0) 编辑

NYOJ 257 郁闷的C小加(一)

摘要: 同中缀式转化到后缀式地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=257 1 #include<stdio.h> 2 #include<stdlib.h> 3 #define N 1010 4 //字符栈的操作 5 typedef struct 6 { 7 char *base; 8 char *top; 9 }SqStack; 10 int InitStack(SqStack &S) 11 { 12 S.base=(char *)malloc(N*sizeof(char)); 13 if(!S.bas. 阅读全文

posted @ 2012-08-12 16:53 mycapple 阅读(185) 评论(0) 推荐(0) 编辑

HDU 1874 畅通工程续 (Dijkstra算法)

摘要: 1 #include <iostream> 2 3 using namespace std; 4 5 #define MAX_VERTEXT 250 6 const int MAX_WEIGHT= 0x7f7f7f7f; 7 8 int map[MAX_VERTEXT][MAX_VERTEXT]; 9 int path[MAX_VERTEXT];10 11 void Init()12 {13 memset(map,MAX_WEIGHT,sizeof(map));14 memset(path,MAX_WEIGHT,sizeof(path));15 }16 17 void ... 阅读全文

posted @ 2012-08-12 16:35 mycapple 阅读(207) 评论(0) 推荐(0) 编辑

Dijkstra算法模板

摘要: Dijkstra算法又称为单源最短路径,所谓单源是在一个有向图中,从一个顶点出发,求该顶点至所有可到达顶点的最短路径问题。设G=(V,E)是一个有向图,V表示顶点,E表示边。它的每一条边(i,j)属于E,都有一个非负权W(I,j),在G中指定一个结点v0,要求把从v0到G的每一个接vj(vj属于V)的最短有向路径找出来(或者指出不存在)。Dijstra算法是运用贪心的策略,从源点开始,不断地通过相联通的点找出到其他点的最短距离基本思想是:设置一个顶点的集合s,并不断地扩充这个集合,一个顶点属于集合s当且仅当从源点到该点的路径已求出。开始时s中仅有源点,并且调整非s中点的最短路径长度,找当前最短 阅读全文

posted @ 2012-08-12 09:04 mycapple 阅读(4485) 评论(0) 推荐(1) 编辑

2012年8月11日

HDU 1106 排序

摘要: 地址:http://acm.hdu.edu.cn/showproblem.php?pid=1106解题思路:这道题就是一个字符串处理啦,这道题我们要考虑几种情况 1.多个5连在一起2.第一个字符为53.最后一个字符为5 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 int cmp(const void*a,const void*b) 5 { 6 return *(int *)a-*(int *)b; //升序 7 } 8 int main() 9 {10 int i,flag, 阅读全文

posted @ 2012-08-11 11:39 mycapple 阅读(297) 评论(0) 推荐(0) 编辑

HDU 2085 核反应堆

摘要: 地址:http://acm.hdu.edu.cn/showproblem.php?pid=2085此题找出关系即可设n微秒时a( n ) 为高能粒子个数,b ( n )为低能粒子个数;经分析可得 a ( n ) = 3 * a( n - 1 ) + 2 * b ( n - 1 ), b ( n ) = a ( n - 1 ) + b ( n - 1 );然后直接打表即可,还有要注意要用long long 型存储 1 #include<stdio.h> 2 #include<stdlib.h> 3 long long sum[35][2]={1,0}; 4 int mai 阅读全文

posted @ 2012-08-11 11:37 mycapple 阅读(224) 评论(0) 推荐(0) 编辑

上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 28 下一页

导航