简单题
幽静
这个作者很懒,什么都没留下…
展开
-
HDU 1108
这题目比较简单。可以用一个函数,求最大公约数的函数 题目 #include using namespace std; int gcd(int a,int b) //递归实现 求两个数的最大公约数 { return(b?gcd(b,a%b):a); } int main() { int a,b; while(cin>>a>>b) { int c;原创 2013-02-26 18:11:33 · 298 阅读 · 0 评论 -
hdu 2036(多边形面积)
水~~,只是里面有个公式还算比较好用,写一下。 #include #include #include using namespace std; int x[110],y[110]; int main() { int t; double ans; while(cin>>t,t) { ans=0; for(int i=0;i<t;i++) cin>>x[i]>原创 2013-08-10 00:29:54 · 526 阅读 · 0 评论 -
hdu 1019
值得思考,其题目意思: 给你一堆数 求这些数的最小公倍数~~ 利用最大公约数来求. gcd函数不要用递归,好像会卡掉 #include using namespace std; int gcd (int a,int b) { int r; if(a<b) swap(a,b); while(b) { r=a%b; a=b; b=r; }原创 2013-08-10 11:41:51 · 467 阅读 · 0 评论 -
hdu 1248(完全背包)
http://acm.hdu.edu.cn/showproblem.php?pid=1248 入门水题~~ #include using namespace std; struct pack { int v,c; }; pack p[5]; int f[10010],maxv; void cpack(pack p) { for(int i=p.c;i<=maxv;i++)原创 2013-08-09 23:47:02 · 593 阅读 · 0 评论 -
nyoj 187
筛选法求素数 #include #include #define size 2000010 using namespace std; bool visit[size]; int isprime[size]; void getprime() { int cs(0); memset(visit,0,sizeof(visit)); visit[0]=visit[1]=1;原创 2013-07-11 23:19:11 · 477 阅读 · 0 评论 -
hdu 1029
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1029 这本来是一道水题,但是还是错了很多次,因为有可能没有解,不用输出。也可以利用排序。 写这篇博客,主要是一种思想, 参考代码:http://blog.sina.com.cn/s/blog_ace0c3ed01016v66.html 利用两个数进行pk,比如说:1 2 3 4原创 2013-04-13 22:33:29 · 498 阅读 · 0 评论 -
hdu 2617
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2617 这道题的解题关键是:存储,利用前一个字符是否符合要求,去判断: #include using namespace std; char sev[10010]; int main() { int h,a,p,y; while(gets(sev)) { h=a=p=y=0;原创 2013-04-13 16:25:50 · 551 阅读 · 0 评论 -
18岁的生日
18岁生日 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 58 Accepted Submission(s) : 23 Font: Times New Roman | Verdana | Georgia Font原创 2013-04-10 14:25:04 · 858 阅读 · 0 评论 -
A+B
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3787 直观的说 ,这个数据比较小可以直接进行 int赋值,或者是用longlong类型 。#include #include long str(char s[]) { int i;long t=0; for(i=0;i<strlen(s);i++) if(s[i]>='0'&&s[i]<='9'原创 2013-04-09 18:22:47 · 465 阅读 · 0 评论 -
hdu 1559
水题;(dp) 先全部加起来处理一下,然后相减就是了; #include using namespace std; int s[1010][1010]; int main() { int T,n,m,x,y; cin>>T; while(T--) { cin>>m>>n>>x>>y; memset(s,0,sizeof(s)); for(int i=原创 2013-04-04 17:55:08 · 470 阅读 · 0 评论 -
括号配对问题 用数组解决
题目连接:http://acm.nyist.net/JudgeOnline/problem.php?pid=2 这个题目有很多的解法,用数据结构中的栈,模板,容器,其实归根到底还是可以用很简单的数组来解决。 题目的关键是:如果这个输入合法,那么一组输入中一定有 “[]”或者“()”这样的,有这样的就简化,去掉,最后这个数组为空就是正解。 先开一个辅助数组,然后从原数组中提取,如果是“[”或者原创 2013-03-02 21:26:57 · 579 阅读 · 0 评论 -
er
#include using namespace std; struct noot { int val; struct noot *lch; struct noot *rch; }; void init (noot *&t) { t=(noot *)malloc(sizeof(noot)); t->lch=NULL; t->rch=NULL; } void crea原创 2013-03-12 22:16:39 · 584 阅读 · 0 评论 -
HDU 1016 素数环
题目 这道题目可以算是一道简单的搜索题目,用来了解一下深度搜索(dfs) #include using namespace std; int prinum[]={0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, //用来判断相邻的两个数的和是不是素数,从0开始 0, 1, 0, 0, 0, 1,0, 1, 0, 0, 0, 1,原创 2013-02-27 23:22:28 · 388 阅读 · 0 评论 -
MAX SUM
题意,给你一组数,请你找出最大的数字。 链表表示,留着做个参考。 #include #include #include using namespace std; struct node { double v; node *next; }; int main() { int n; cin>>n; while(n--) { int m(0);原创 2013-02-27 12:47:59 · 306 阅读 · 0 评论 -
hdu 1018
大概的意思:给你一个n,输出n!的位数~~ n 看到上面的讨论,知道了一个数,它的位数有一个计算公式,n的位数= int (long10(n))+1; 从这里来看,n!=1*2*3*4.....*n; =int long10(1*2*3*4.......*n)+1; =int(l原创 2013-08-10 09:39:56 · 558 阅读 · 0 评论