WOJ1010-Alternate Sum

Alternate sum of a nonempty set is the result of operations described as follow: Firstly, all the elements of arranged in
non-increasing sequence. Secondly, alternate sum could be obtained by the following formula:

Where:
and
For example, and so alternate sum of is 2. It?s very easy for you to
compute the alternate sum, isn?t it? But can you tell me the total value of all the subsets? alternate sum in set ?

输入格式

There are several test cases. For each test case, it contains:
Line 1: One integer N (1<=N<=1000) which specifies the size of set
Line 2: N integers (you are ensured that the absolute value of each integer is less than ) which specify the elements of set .
There is a blank between two consecutive integers.
The input will be ended by zero.

输出格式

The answer of the total value may be very large, so you should divide this answer by 2006 and just output the remainder instead.

样例输入

1
-1
2
0 4
3
1 3 2
0

样例输出

2005
8
12

#include<stdio.h>
#include<stdlib.h>
int main()
{
int n,i,answer,max;
int setN[1000];
while(scanf("%d",&n),n)
{
   for(i=0;i<n;i++)
   scanf("%d",&setN[i]);
   max=setN[0];
   for(i=1;i<n;i++)
    if(setN[i]>max)
     max=setN[i];
   answer=max;
   for(i=1;i<n;i++)
   {
    answer*=2;
    if(answer<0)//防止负数越界
     answer+=2006;
    answer%=2006;
   }
   if(answer<0)
    answer+=2006;
   printf("%d\n",answer%2006);
  
}
return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值