Contest2089, contest

Source: Internet
Author: User

Contest2089, contest

Problem E: SwipeTime Limit: 1 Sec Memory Limit: 128 MB
Submit: 100 Solved: 15
[Submit] [Status] [Web Board] Description Druid is a very stable profession in the legend of hearth stone. The mainstream card sets have the ROAR, city wall, and helpless fatigue. However, most card groups always include the druid professional spell card "sweep. We assume that the number of enemies on the battlefield is not fixed, and the enemy's blood volume is known. We want to know the minimum number of "sweeps" used to eliminate all enemies on the battlefield. The first line of Input is an integer T (T <= 100), indicating the number of groups of test data. Next we will have T groups of data. The first row of each group of data is n (n <= 1000), which indicates that the number of enemies on the battlefield is n in the second row, indicates the current blood volume of each enemy (the value is not greater than 1000000) Output an integer for each group of data, occupying a row, indicating the minimum "sweep" number of Sample Input required to eliminate all enemies
231 2 324 1 4 1 1
Sample Output
21
HINT

 

 

Train of Thought: the greatest attack each time; the maximum minus 3, put in order, the standard line (that is, the number of all minus) plus 1;
Question link: http://acm.csu.edu.cn/OnlineJudge/problem.php? Id = 1648
Reprinted, please specify the Source: search for & STAR kids
#include <iostream>#include <stdio.h>#include <string.h>#include <stack>#include <queue>#include <map>#include <set>#include <vector>#include <math.h>#include <bitset>#include <algorithm>#include <climits>using namespace std; #define LS 2*i#define RS 2*i+1#define UP(i,x,y) for(i=x;i<=y;i++)#define DOWN(i,x,y) for(i=x;i>=y;i--)#define MEM(a,x) memset(a,x,sizeof(a))#define W(a) while(a)#define gcd(a,b) __gcd(a,b)#define LL long long#define N 20005#define MOD 1000000007#define INF 0x3f3f3f3f#define EXP 1e-8 int a[1005],t,n; int main(){    int i,j,k;    scanf("%d",&t);    W(t--)    {        scanf("%d",&n);        UP(i,0,n-1)        {            scanf("%d",&a[i]);        }        if(n==1)        {            if(a[0]%4)                printf("%d\n",a[0]/4+1);            else                printf("%d\n",a[0]/4);            continue;        }        sort(a,a+n);        int ans = 0;        W(a[n-1]-ans>0)        {            ans++;            a[n-1]-=3;            for(i = n-2; i>=0; i--)            {                if(a[n-1]>a[i]||i==0)                {                    int tem = a[i+1];                    a[i+1] = a[n-1];                    for(j=n-1; j>=i+3; j--)                        a[j]=a[j-1];                    a[i+2] = tem;                    break;                }            }        }        printf("%d\n",ans);    }     return 0;} /**************************************************************    Problem: 1648    User: aking2015    Language: C++    Result: Accepted    Time:812 ms    Memory:1492 kb****************************************************************/

We will try again tomorrow... Sleep



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.