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. springMVC 文件上传 HTTP Status 400 – Bad Request

    可能原因是:multipartResolver没有配置正确 请看解决方案: <!--文件上传 id必须为multipartResolver,不然报错HTTP Status 400 – Bad R ...

  2. luogu1856 [USACO5.5]矩形周长Picture

    看到一坨矩形就要想到扫描线.(poj atantis) 我们把横边竖边分开计算,因为横边竖边其实没有区别,以下论述全为考虑竖边的. 怎样统计一个竖边对答案的贡献呢?答:把这个竖边加入线段树,当前的总覆 ...

  3. kissy学习

    http://docs.kissyui.com/1.4/docs/html/guideline/kmd.html

  4. Leetcode 315.计算右侧小于当前元素的个数

    计算右侧小于当前元素的个数 给定一个整数数组 nums,按要求返回一个新数组 counts.数组 counts 有该性质: counts[i] 的值是  nums[i] 右侧小于 nums[i] 的元 ...

  5. asp.net 页面缓存、数据缓存

    页面缓存,webform框架的aspx页面,服务器引擎生成的页面可以被缓存.

  6. xftp向ubuntu传输文件错误

    xftp向ubuntu传输文件错误原因: 登陆用户对文件夹没有权限. 解决方法:授予权限 chmod 777 该目录名

  7. 如何改变linux系统的只读文件的权限

    vim 编辑可以在命令模式输入 :wq! 保存退出可以用chmod 命令修改文件权限. chmod命令是非常重要的,用于改变文件或目录的访问权限.用户用它控制文件或目录的访问权限.该命令有两种用法.一 ...

  8. FastDFS+nginx+php的完整应用[转储]

    FastDFS功能简介: FastDFS是一个开源的轻量级分布式文件系统,它对文件进行管理,功能包括:文件存储.文件同步.文件访问(文件上传.文件下载)等,解决了大容量存储和负载均衡的问题.特别适合以 ...

  9. EsAlert

    https://www.cnblogs.com/zhaishaomin/p/7417306.html https://blog.csdn.net/pujiaolin/article/details/5 ...

  10. MySQL查询在一个表而不在另一个表中的数据

    1.使用not in,容易理解,效率低 select distinct A.ID from A where A.ID not in (select ID from B) 2.使用left join.. ...