Millet oj
These days a little awkward. . . . I wrote a title has not been written. . . . . . . . . . . . . . . Well keep trying. . He wrote half a topic Godfrey turned out before the Lord
Poker game
description
Dark Lady Sylvanas will revive Godfrey is one of the Forsaken. This time of Godfrey, has no lifetime appearance, looks sinister and cunning, words no longer have any courtesy modification, often vicious language will say it, talk about their past, full of only resentment. Godfrey certainly do not want to submit to Sylvanas, but in order to achieve unaware of betrayal, he needs to prove their "loyalty" - went to destroy strongholds Union Seventh Army, waiting for his reward nothing else Luo is a product little monster cooking machine.
Seventh Army stronghold of countless enemies, Godfrey holding a rifle Enchant, bullet fired will jump between enemies, one bullet can cause 2 damage to all enemies, if it leads to any enemy bullet death (ie, blood is less than or equal to 0), the bullet also deals 2 damage to all enemies again, until no deaths so far new enemy.
Well, Godfrey need to play a few bullets to destroy all enemy?
Entry
Each input is the enemy of blood, separated by a space, the end of the carriage. 0 <number of enemies <= 10000; 0 <enemy's blood <= 10 ^ 9
Export
Output number is a number that is a minimum of play Godfrey bullets
This title has a look at a maximum 10,000 enemy So bubble sort is absolutely beng ... so it can only be used to quickly sort
There are two implementations.
-
stdlib.h library which comes with a qsort () function. . Here are temporarily detailed to the links. . .
-
I wrote a quick sort
Problem-solving ideas
After the sorting is done less blood enemies certainly die first, and then only once for the cycle time to see the last person from the first person to. . . . Solved. . . . . . . . . . . . . . . . . . . .
Or pasting the code (here is the library qsort)
#include "stdio.h"
#include "stdlib.h"
int compare(const void *a, const void *b)
{
return *(int*)a - *(int*)b; //降序排列
}
int main()
{
static int a, b[10000];
static int i, j, k,ans;
char o;
while (~scanf("%d", &a))
{
o = getchar();
if (o == 'p')
break;
b[i++] = a;
}
//升序快速排序
int length1 = i;//元素的个数
qsort(b, length1, sizeof(int), compare);
// printf("%d %d %d %d %d \n",b[0],b[1],b[2],b[3],b[4]);
int sum=0, flag=0;
for (j = 0; j < i; j++)
{
if (b[j] <= sum)continue;//不用奖励的子弹也可以杀死
if (flag)sum += 2, flag = 0;
if (b[j] <= sum)
{
flag = 1;//有奖励的子弹
continue;
}
int t = b[j] - sum;
int res = (t +1)/ 2;//防止为奇数
sum += res * 2;
flag = 1;
ans += res;
}
printf("%d\n",ans);
// scanf_s("%d",&a);
return 0;
}
As this two days to write a question a little frustrated. . Love is not published package (prepared under electric charge) \ n today to buy a book in a big brother recommended "Algorithm Design and Analysis" \ 0
return 0;
//Gone