TJU ACM Problem 【4158】

来源:互联网 发布:虚拟局域网 软件 推荐 编辑:程序博客网 时间:2024/05/16 13:04

Alice and Bob like game. They often play the game together.
Today, they are playing a card game. At first, there are NN cards on table. Each cards have a number. The rules of this game is follow:
First, Alice choose one card from the first card and the last card.
And then Bob choose one card from the first card and the last card of the remaningN1N−1 cards.
And then Alice choose one card from the first card and the last card of the remaningN2N−2 cards.
...end until there is no card.
they can get points from the number on the cards. The winner whose point is most.
For example, there are 3 cards, 3 7 5. First, Alice can choose 3 and 5. Alice choose 5, and then Bob can choose 3 and 7, Bob choose 7, and then Alice choose 3. The point of Alice is 8, and point of Bob is 7. So Alice is winner, and the difference of points is 1.
Now, give you NN cards. We can assume that Alice and Bob are very smart, you need tell us the difference of the point of Alice and Bob.

Input

The input consists of multiple test cases. The first line contains an integer TT, indicating the number of test cases.(1T10)(1≤T≤10)
Each case contains two lines, the first line contains one integer NN, means the number of cards.(1N20)(1≤N≤20)
The second contains NN positive numbers means the point on the card. the point on the card is less than104104

Output

For each case output the difference of points of Alice and Bob

Sample Input

333 10 543 7 8 541 1 1 1

Sample Output

-210
#include <iostream>#include <string>#include<cstdlib>using namespace std;int main(){   int t,n,i;   int a[20];   cin>>t;//用例组数   int beg,fin;   int alice,bob;   while(t--)   {       alice=0;       bob=0;       cin>>n;       beg=0;       fin=n-1;       for(i=0;i<n;i++)        cin>>a[i];        for(i=1;i<=n;i++)        {            if(beg<=fin)            {                if(i%2!=0)//alice选择                {                    if(a[beg]>=a[fin])                    {                        alice+=a[beg];                        beg++;                    }                    else if(a[beg]<=a[fin])                    {                        alice+=a[fin];                        fin--;                    }                }                else//bob选                {                     if(a[beg]>=a[fin])                    {                        bob+=a[beg];                        beg++;                    }                    else if(a[beg]<=a[fin])                    {                        bob+=a[fin];                        fin--;                    }                }            }        }        cout<<alice-bob<<endl;   }    return 0;}

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 买房交首付时的收据发票掉了怎么办 苹果商城消费提示问题忘记了怎么办 psd文件超过2g不能存储怎么办 手机拍的照片做微信头像太大怎么办 上传的照片在等待中传不上去怎么办 淘宝购物车里的图片模糊怎么办 天猫超市一箱饮料少两瓶怎么办 网上卖一件代发顾客要退货怎么办 京东买东西卖家拒绝发货怎么办 淘宝不小心退款给买家了怎么办 不小心智能清理了淘宝物流怎么办 移动卡绑定了太多东西换联通怎么办 淘宝上卖出的东西快递弄丢了怎么办 京东第三方不确认收货怎么办? 天猫评价被判定为广告怎么办 天猫一个订单用卷分单退货怎么办 天猫对已付款成功后自动退款怎么办 拼多多新人红包减价卖家怎么办 魔力宝贝手机版注册人数已满怎么办 买家投诉虚假签收淘宝卖家该怎么办 手机淘宝商家老打骚扰电话怎么办 手机上查询详单忘记服务密码怎么办 淘宝上的东西买过就找不到了怎么办 刚刚开的淘宝企业店没有流量怎么办 有图片怎么在淘宝找不到商品怎么办 白色高跟鞋鞋面磨脏了怎么办弄干净 我跟鞋后跟磨烂的脚怎么办? 内衣买回来有一股刺鼻的味道怎么办 裁剪袖子开口偏了1公分怎么办 对于这乱扔垃圾不听劝者该怎么办 感觉被南通蒲公英店铺骗了怎么办 6个月宝宝吃米粉不吃奶怎么办 十个月的宝宝不吃辅食怎么办 5个月宝宝拉肚子有泡沫怎么办 生完孩子后皮肤暗黄怎么办 开服装店批发服装的吊牌怎么办 天虹的鞋一天就坏了怎么办 车被钥匙划了露底漆了怎么办 数控铣z轴回不了参考点怎么办 白色衣服被黑色衣服染了怎么办 夏天出汗衣服粘身上都是毛毛怎么办