FreeBSD ports中make可带有的参数[转]
2009-03-21 20:34
281 查看
第一个,一开始做的,比较杂乱:
/* THE PROGRAM IS MADE BY PYY */ /*----------------------------------------------------------------------------// Copyright (c) 2012 panyanyany All rights reserved. URL : http://acm.hdu.edu.cn/showproblem.php?pid=1003 Name : 1003 Max Sum Date : Thursday, July 05, 2012 Time Stage : 1 hour Result: 6132517 2012-07-05 11:39:32 Accepted 1003 0MS 1008K 1950 B C++ pyy Test Data : Review : //----------------------------------------------------------------------------*/ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <vector> #include <algorithm> #include <iostream> #include <queue> #include <set> #include <string> using namespace std ; #define MEM(a, v) memset (a, v, sizeof (a)) // a for address, v for value #define max(x, y) ((x) > (y) ? (x) : (y)) #define min(x, y) ((x) < (y) ? (x) : (y)) #define INF (0x3f3f3f3f) #define MAXN 100009 #define L(x) ((x)<<1) #define R(x) (((x)<<1)|1) #define M(x, y) (((x)+(y)) >> 1) #define DB /##/ typedef __int64 LL; int sum[MAXN], v[MAXN], s, t, head, tail, n, tcase; int main() { int i, j, MaxSum, FinSum; while (scanf("%d", &tcase) != EOF) { for (j = 1; j <= tcase; ++j) { scanf("%d", &n); for (i = 0; i < n; ++i) { scanf("%d", v+i); if(0 == i) { FinSum = sum[i] = v[i]; s = t = head = tail = i; } else { if (sum[i-1] < 0) { head = tail = i; sum[i] = v[i]; } else { int tmp = sum[i-1] + v[i]; // if (tmp >= 0)//只有大于0的值才可能+后面的数变成更大的数 // { sum[i] = tmp; tail = i; // } /* else// 若加起来的值为负数,则不如不加 { sum[i] = v[i]; head = tail = i; } */ } if (FinSum < sum[i]) { s = head; t = tail; FinSum = sum[i]; } } } printf("Case %d:\n%d %d %d\n", j, FinSum, s+1, t+1); if (j < tcase) putchar('\n'); } } return 0; }
第二个,修改过的,参考了别人的代码:
/* THE PROGRAM IS MADE BY PYY */ /*----------------------------------------------------------------------------// Copyright (c) 2012 panyanyany All rights reserved. URL : Name : Date : Thursday, July 05, 2012 Time Stage : Result: 6132607 2012-07-05 12:00:59 Accepted 1003 0MS 616K 1623 B C++ pyy Test Data : Review : //----------------------------------------------------------------------------*/ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <vector> #include <algorithm> #include <iostream> #include <queue> #include <set> #include <string> using namespace std ; #define MEM(a, v) memset (a, v, sizeof (a)) // a for address, v for value #define max(x, y) ((x) > (y) ? (x) : (y)) #define min(x, y) ((x) < (y) ? (x) : (y)) #define INF (0x3f3f3f3f) #define MAXN 100009 #define L(x) ((x)<<1) #define R(x) (((x)<<1)|1) #define M(x, y) (((x)+(y)) >> 1) #define DB /##/ typedef __int64 LL; int v[MAXN], s, t, head, n, tcase; int main() { int i, j, FinSum, CurSum; while (scanf("%d", &tcase) != EOF) { for (j = 1; j <= tcase; ++j) { scanf("%d", &n); FinSum = -100000000; CurSum = head = 0; for (i = 0; i < n; ++i) { scanf("%d", v+i); CurSum += v[i]; // 下面两个if不能调换过来,否则将无法处理只有一个负数的情况 if (FinSum < CurSum) { FinSum = CurSum; s = head; t = i; } if (CurSum < 0) { CurSum = 0; head = i+1; } } printf("Case %d:\n%d %d %d\n", j, FinSum, s+1, t+1); if (j < tcase) putchar('\n'); } } return 0; }
相关文章推荐
- [收藏] FreeBSD ports中make可带有的参数
- FreeBSD ports中make可带有的参数[CNFUG]
- FreeBSD的ports中的make可带有的参数
- [收藏] FreeBSD ports中make可带有的参数
- FreeBSD ports中make可带有的参数
- [收藏] FreeBSD ports中make可带有的参数
- FreeBSD ports的make 参数
- FreeBSD ports中make可带有的参数
- 象mysql之类的源代码包都在freebsd的哪个目录,用什么参数make。
- thinkphp的url地址栏的参数错误并且带有%
- Oracle中调用带有返回参数的存储过程
- 编译内核驱动make时的M参数
- tomcat取带有中文的参数乱码的解决办法
- SpringBoot中自定义properties文件配置参数并带有输入提示
- jggrid带有参数
- Makefile笔记二【函数和make的规则参数】
- LINQ TO SQL:动态执行带有有参数的存储过程
- freebsd安装ports
- 如何通过反射调用带有ref或者out的参数的方法[迁移]
- asp.net实现调用带有输出参数的存储过程实例