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. ZOJ 3824 Fiber-optic Network

    Fiber-optic Network Time Limit: 15000ms Memory Limit: 262144KB This problem will be judged on ZJU. O ...

  2. Leetcode 233.数字1的个数

    数字1的个数 给定一个整数 n,计算所有小于等于 n 的非负整数中数字 1 出现的个数. 示例: 输入: 13 输出: 6 解释: 数字 1 出现在以下数字中: 1, 10, 11, 12, 13 . ...

  3. 将登录等信息保存到session中和退出session

    JShop简介:jshop是一套使用Java语言开发的B2C网店系统,致力于为个人和中小企业提供免费.好用的网店系统. 项目主页:http://git.oschina.net/dinguangx/js ...

  4. ***iOS学习之Table View的简单使用和DEMO示例(共Plain普通+Grouped分组两种)

    Table View简单描述: 在iPhone和其他iOS的很多程序中都会看到Table View的出现,除了一般的表格资料展示之外,设置的属性资料往往也用到Table View,Table View ...

  5. IdHttp 资料

    http://blog.csdn.net/delphizhou/article/details/3085704 IdHttp 资料 网上找了些不过很不好找.今天找了些收藏在一起.以便他人查阅, idh ...

  6. python学习之---- paramiko 模块

    paramiko 模块 功能:提供了ssh及sftp进行远程登录服务器执行命令和上传下载文件的功能.这是一个第三方的软件包,使用之前需要安装. 1  基于用户名和密码的 sshclient 方式登录 ...

  7. HUNAN 11567 Escaping (最大流)

    http://acm.hunnu.edu.cn/online/?action=problem&type=list&courseid=0&querytext=&pagen ...

  8. 包装类Float中为什么有两个常量来表示最小值

    1)问:包装类Float中为什么有两个常量来表示最小值:MIN_VALUE和MIN_NORMAL ① MIN_VALUE:最小正非零值常量,是非规格化浮点数所能表示的最小值.值为 3.4E-45 的常 ...

  9. redis连接数据库进行操作

    该项目需要的类目录 1.首先我们需要创建我们的实体类 2.放置我们的dao层,在里面写入方法 3.配置类Appconfig需要加入我们的JdbcTemplate方法,因为我们用的是spring,所以需 ...

  10. jenkins的代理设置,方便下载插件

    jenkins在下载插件的时候,总是网络不通,需要设置代理跨越长城 java.net.SocketTimeoutException: connect timed out Caused: java.ne ...