数组

Problem Description

Array is frequently used when we are programing. We are familiar with it. Here is a problem about array. 
Do enjoy it and try your best to solve it.
Assume there is an array: a[1],a[2],...a[n](a[i] is positive integer, 1<=i<=n) and a[i]<=a[j](1<=i<j<=n)
Now we define another array:b[1],b[2],...,b[a[n]
b[i]=min{v|a[v]>=i},1<=i<=a[n]
Finally, the problem is: given the value[n+a[n]), you have to find the maximum of (a[1]+a[2]+...+a[n]+
b[1]+b[2]+...+b[a[n]]).

Input

The first line of the input is a positive integer T. T is the number of the test cases followed. Each test case 
contains an integer V(1<V<10000) which tell you the value(n+a[n]). There may be one or several spaces 
before or after the integer.

Output

The output of the problem should consist of one line of output for each test case.
The output of each test case only contains one integer M, M is the maximum of (a[1]+a[2]+...+a[n]+
b[1]+b[2]+...+b[a[n]]). No any redundant space is needed.

Sample Input

2
2
3

Sample Output

2
4
/*
解题报告:给出V(n+a[n]), 由题可知 a[n] >= n, 如果V是奇数,a[v/2] = v/2+1;
             如果是偶数,则a[v/2] = v/2;      
             题中有b[i]=min{v|a[v]>=i},1<=i<=a[n],    只有当a[i] = i(1<=i<=v/2), 
             b[i]可以取最大值,则最后a[1]+....+a[n] + b[1]+....+b[a[n]] 最大。
*/
//标程:
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
// 	freopen("a.txt","r",stdin);
    int t, n;
	cin >> t;
	while(t --)
	{
		cin >> n;
		int sum = 0, i;
	        for(i = 1; i <= n/2; i ++)
			sum += 2*i;
		if(n%2==1) sum += (n/2+1);
		cout << sum << endl;
	}
	return 0;
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值