上一页 1 ··· 3 4 5 6 7 8 下一页
摘要: 1 #include<iostream> 2 #include<cstring> 3 #include<stack> 4 using namespace std; 5 #define N_MAX 27 6 7 bool map[N_MAX][N_MAX]; 8 int indegree[N_MAX]; 9 int outdegree[N_MAX];10 int n,m;11 char str[N_MAX];12 bool floyd()13 {14 for(int k=0;k<n;++k)15 for(int i=0;i<n;++i)16 f.. 阅读全文
posted @ 2012-04-01 11:13 AndyDHG 阅读(148) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>using namespace std;int main(){ unsigned char ch='m'; unsigned char ch1=0x80; for(int i=0;i<8;++i) { if((ch&ch1)!=0)cout<<"1"; else cout<<"0"; ch1=ch1>>1; } cout<<endl; getchar(); return 0; }尤其要注意的是(ch&ch1)!=0这句,注 阅读全文
posted @ 2012-03-30 10:45 AndyDHG 阅读(177) 评论(0) 推荐(0) 编辑
摘要: A Pythagorean triplet is a set of three natural numbers, a b c, for which,a2 + b2 = c2For example, 32 + 42 = 9 + 16 = 25 = 52.There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.//通项公式//a=M^2-N^2 //b=2MN//c=M^2+N^2 //(M,N为正整数)int main(){ int a,b,c; ... 阅读全文
posted @ 2012-03-29 10:18 AndyDHG 阅读(165) 评论(0) 推荐(0) 编辑
摘要: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?#include<iostream>//#include<cstring>#include<algorithm>using namespace std;_in 阅读全文
posted @ 2012-03-29 08:36 AndyDHG 阅读(177) 评论(0) 推荐(0) 编辑
摘要: 公交车票价为5角。假设每位乘客只持有两种币值的货币:5角、1元。再假设持有5角的乘客有m人,持有1元的乘客有n人。由于特殊情况,开始的时候,售票员没有零钱可找。我们想知道这m+n名乘客以什么样的顺序购票则可以顺利完成购票过程。显然,m<n的时候,无论如何都不能完成,m>=n的时候,有些情况也不行。比如,第一个购票的乘客就持有1元。下面的程序计算出这m+n名乘客所有可能顺利完成购票的不同情况的组合数目。注意:只关心5角和1元交替出现的次序的不同排列,持有同样币值的两名乘客交换位置并不算做一种新的情况来计数。//m:持有5角币的人数//n:持有1元币的人数//返回:所有顺利完成购票过程 阅读全文
posted @ 2012-03-27 10:36 AndyDHG 阅读(537) 评论(0) 推荐(0) 编辑
摘要: 随机地交换牌的位置,随机地产生运算符,看看是符合要求,大量重复这个过程,看看能否碰上运气。实验表明,当试验次数很大的时候,“运气”的概率是很高的。 阅读全文
posted @ 2012-03-27 10:26 AndyDHG 阅读(522) 评论(0) 推荐(1) 编辑
摘要: 题目信息:10034 - Freckles 本题主要考察最小生成树的生成问题,这里是用链表写的,可能没有用数组简便,但练练链表。题目并没有构造出最小生成树,可以用邻接数组来构造出最小生成树,再用bfs遍历出最小生成树。#include<iostream>#include<list>#include<cmath>#include<cstdio>using namespace std;//利用最小生成树解决问题typedef struct node{ double x; double y;}Node;int main(){ int n; cin> 阅读全文
posted @ 2012-03-13 16:33 AndyDHG 阅读(216) 评论(0) 推荐(0) 编辑
摘要: 题目信息:uva 10161 - Ant on a Chessboard题目比较简单,用模拟方法写的,看清规律,也可以用数学放法来求解: 1 #include<iostream> 2 3 using namespace std; 4 5 int main() 6 { 7 int n; 8 while(true) 9 {10 cin>>n;11 if(n==0) break;12 int x,y,t;13 x=y=0;14 t=0;15 for(int i=1;i<=n/2... 阅读全文
posted @ 2012-03-08 11:24 AndyDHG 阅读(239) 评论(0) 推荐(0) 编辑
摘要: sprintf函数: 头文件:stdio.h 函数原型:int sprintf( char *buffer, const char *format [, argument] … ); 返回值:字符串长度(strlen) 例如:unsigned _int64 t=1;char temp[15]; for(int i=4;i<=42;++i){ sprintf(temp,"%llu",t<<i);}关于64为的整数可以看下面的解释(从百度空间里拷来的,写的很明白,原文可参考下面的连接):__int64 与long long int在做ACM题时,经常都会遇到一 阅读全文
posted @ 2012-03-03 14:30 AndyDHG 阅读(10186) 评论(0) 推荐(0) 编辑
摘要: 题目信息:10035 - Primary Arithmetic 题目不难,刚开始的时候1 999999这组数据没考虑。#include<iostream>#include<string>using namespace std;int main(){ string line,line1,line2; int carry,carryNum; while(cin>>line1>>line2) { if(line1 == "0" && line2=="0") break; else { carry= 阅读全文
posted @ 2012-03-03 12:14 AndyDHG 阅读(212) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 下一页