CSU 1648

1648: Swipe

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 130   Solved: 25
[ Submit][ Status][ Web Board]

Description

德鲁伊在炉石传说中是一个很稳定的职业,主流的卡组套路有咆哮德,城墙德以及让人很无奈的疲劳德。然而,大部分的卡组总都包括“横扫”这张德鲁伊的职业法术卡。
 
 
 
我们假定战场上的敌人数目不定,敌人的血量已知,我们想知道最少使用多少张“横扫”能消灭战场上所有敌人。

Input

第一行一个整数T( T<=100), 表示测试数据的组数。
接下来有T组数据,
每组数据第一行n ( n<=1000) ,表示战场上敌人的数目
第二行有n个数,表示每个敌人当前的血量 (数值不大于1000000)

Output

每组数据输出一个整数,占一行,表示消灭所有敌人所需的最少“横扫”数目

Sample Input

2
3
1 2 3
2
4 
1 4 1 1

Sample Output

2
1
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1648
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
 
int n,sum,m;
int s[1005];
 
int cmp(int a,int b)
{
    return a<b;
}
 
int main ()
{
    int T;
    scanf ("%d",&T);
    while (T--)
    {
        sum = 0;
        scanf ("%d",&n);
        for (int i=0; i<n; i++)
        {
            scanf ("%d",&s[i]);
        }
        sort(s, s+n,cmp);
 
        for (m=0;;m++)
        {
 
            if (m >= s[n-1])
                break;
            s[n-1] -= 3;
            int t=n-1;
            int tp=s[n-1];
            if(s[n-1]<s[0])
            {
                for(int i=n-1; i>0; i--)
                {
                    s[i]=s[i-1];
                }
                s[0]=tp;
            }
            else
            {
                for (int i=n-2; i>=0; i--)
                {
                    if (s[n-1] >= s[i])
                    {
                        t=i+1;
                        break;
                    }
                }
 
                for(int i=n-1; i>t; i--)
                {
                    s[i]=s[i-1];
                }
                s[t]=tp;
            }
 
        }
        printf ("%d\n",m);
    }
    return 0;
}
/**************************************************************
    Problem: 1648
    User: xky1306101
    Language: C++
    Result: Accepted
    Time:748 ms
    Memory:1492 kb


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值