1020: I think it

时间限制: 1 Sec  内存限制: 32 MB

提交: 501  解决: 63

题目描述

Xiao Ming is only seven years old, Now I give him some numbers, and ask him what is the second largest sum if he can choose a part of them. For example, if I give him 1 、 2 、 3 , then he should tell me 5 as 6 is the largest and 5 is the second. I think
it is too hard for him, isn ’ t it?

输入

Standard input will contain multiple test cases. The first line of the input is a single integer T (1 <= T <=10) which is the number of test cases. And it will be followed by T consecutive test cases.
Each test case starts with a line containing an integer N (1<N<10) , the number I give Xiao Ming . The second line contains N Integer numbers ai (-10<ai<10),

输出

For each test case, output the answer.

样例输入

2
3
1 2 3
4
0 1 2 3

样例输出

5
5
#include<stdio.h>
int jisuan(int a[],int n)
{
int s,ma,i,j,k,b;
s=ma=a[0];
for(i=0; i<n; i++)
for(j=i; j<n; j++)
{
b=0;
for(k=i; k<=j; k++)b+=a[k];
if(b>ma)ma=b;
}
for(i=0; i<n; i++)
for(j=i; j<n; j++)
{
b=0;
for(k=i; k<=j; k++)b+=a[k];
if(b>s&&b<ma)s=b;
}
return s;
}
int main()
{
int N,n,a[15],i,t,j;
scanf("%d",&N);
while(N--)
{
scanf("%d",&n);
for(i=0; i<n; i++)scanf("%d",&a[i]);
for(i=0; i<n-1; i++)
for(j=0; j<n-i-1; j++)
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
printf("%d\n",jisuan(a,n));
}
return 0;
}

总是望着曾经的空间发呆,那些说好不分开的朋友不在了,转身,陌路。 熟悉的,安静了, 安静的,离开了, 离开的,陌生了, 陌生的,消失了, 消失的,陌路了。

YTU 1020: I think it的更多相关文章

  1. ytu 1057: 输入两个整数,求他们相除的余数(带参的宏 + 模板函数 练习)

    1057: 输入两个整数,求他们相除的余数 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 177  Solved: 136[Submit][Status ...

  2. ytu 1058: 三角形面积(带参的宏 练习)

    1058: 三角形面积 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 190  Solved: 128[Submit][Status][Web Boar ...

  3. CentOS6 下安装HP-LaserJet 1020打印机

    因为实验室有个多余的老服务器,所以近段时间想把老服务器做成打印机服务器,同时因为最近在学习linux,所以就像在CentOS6.3 上安装打印机驱动.因为是新手,所以走了不少弯路,今天终于把打印机安装 ...

  4. ytu 1980:小鼠迷宫问题(DFS 深度优先搜索)

     小鼠迷宫问题 Time Limit: 2 Sec  Memory Limit: 64 MB Submit: 1  Solved: 1 [Submit][Status][Web Board] Desc ...

  5. 1020: 部分A+B

    1020: 部分A+B 时间限制: 1 Sec  内存限制: 128 MB提交: 307  解决: 223[提交][状态][讨论版] 题目描述 正整数A的“DA(为1位整数)部分”定义为由A中所有DA ...

  6. PAT乙级 1020. 月饼 (25)(只得到23分)

    1020. 月饼 (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 月饼是中国人在中秋佳节时吃的一种传统食 ...

  7. 【BZOJ】【1020】【SHOI2008】安全的航线flight

    计算几何/二分/迭代/搜索+剪枝 写三个tag可能是因为从哪个方向来理解都可以吧…… 我完全不会计算几何所以抄了ydc的代码 题解:http://ydcydcy1.blog.163.com/blog/ ...

  8. 大数求模 sicily 1020

        Search

  9. PAT 1020

    1020. Tree Traversals (25) Suppose that all the keys in a binary tree are distinct positive integers ...

随机推荐

  1. 【01】sass安装

    因为sass依赖于ruby环境,所以装sass之前先确认装了ruby.先导官网下载个ruby   下载地址:https://rubyinstaller.org/downloads/       ** ...

  2. 关于对象字面量花括号{} key的类型

    原来对{}方式建立的实例化后的对象的key,理解不清,只知道,数组加不加“”,反正都是字符,现在要理解下,到底怎么回事?返回结果是 var a={}; a[1]="a"; a[&q ...

  3. 细胞分裂(洛谷 P1069)

    题目描述 Hanks 博士是 BT (Bio-Tech,生物技术) 领域的知名专家.现在,他正在为一个细胞实 验做准备工作:培养细胞样本. Hanks 博士手里现在有 N 种细胞,编号从 1~N,一个 ...

  4. 一段曲折的copy路程

    cp 的时候出现:-bash: /bin/cp: Argument list too longcp ./*.swf  /www/img/html/xxx/action/ 解决办法:find ./ -n ...

  5. poj——3177Redundant Paths

    poj——3177Redundant Paths      洛谷—— P2860 [USACO06JAN]冗余路径Redundant Paths Time Limit: 1000MS   Memory ...

  6. 【纯净版windows系统】U盘启动制作图文教程

    无废话,按照步骤来就可以. 1.一个大于4G的U盘(格式化)准备好U盘,请注意制作过程中对U盘有格式化操作,有用的东西请先备份 2.UltraISO(软碟通软件)下载安装百度“软碟通”,或者访问 ht ...

  7. 解决maven Generating project in Interactive mode

    在idea建一个基于maven结构的web项目时,cmd输出卡死在Generating project in Interactive mode不动了 用命令mvn archetype:generate ...

  8. DATASNAP高效的FIREDAC数据序列和还原

    变量定义: varFDConnection: TFDConnection;qCustomers: TFDQuery; qOrders: TFDQuery;FDSchemaAdapter: TFDSch ...

  9. java.util.MissingResourceException: Can't find resource for bundle oracle.sysman.db.rsc.LoginResourc

    http://blog.itpub.net/197458/viewspace-1055358/   oracle 10.2.0.4 windows 2003 X64 平台 系统安装EMCA正常.第一次 ...

  10. “约定优于配置”与Magento改造尝试四之block、helper和model载入

    暂定本章为这个系列最后一章,还是继续沿用模块的别名(alias)概念 <modules> <Mage_Wishlist> <version>1.6.0.0</ ...