PIPIOJ: 1207 PIPI to fight monsters

1207 PIPI Fighting Monsters

Title description

Insert picture description here
Insert picture description here

Ideas

At first glance, I didn’t understand why two bullets could kill a monster with 12 HP. Then I thought about it carefully and found out that this is not just a matryoshka doll? If there is death, one person has to deduct two drops of blood per person, and then determine whether there is a monster death in this rebound. If there is also a monster death during the rebound, each monster will deduct two more drops of blood until no monster death occurs. The power of a bullet, if there are wild monsters alive, it will be repeated until all the wild monsters are killed. To be honest, this bullet is quite outrageous.

coding

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX=1e5;
int a[MAX];
int main()
{
    
    
    int n;
	char c;
	while(scanf("%d",&n)!=EOF){
    
    
		for(int i=1;i<=n;i++)
		{
    
    
			scanf("%d",&a[i]);
		}
		int ans=0;
		sort(a+1,a+1+n);
		int sum=0,flag=0;
		for(int i=1;i<=n;i++)
		{
    
    
			if(a[i]<=sum)continue;//不用奖励的子弹也能杀死 
			if(flag)sum+=2,flag=0;//用奖励的子弹 
			if(a[i]<=sum)//奖励的子弹把敌人杀死 
			{
    
    
				flag=1;//标记是否有奖励的子弹 
				continue;
			}
			int t=(a[i]-sum);
			int res=t/2;
			if(t%2)res++;
			sum+=res*2;
			flag=1;
			ans+=res;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Happy time is always short, let's see you next time! ! !

good good study,day day up! (study hard, improve every day)

Foresee the funeral, please listen to the decomposition next time! ! ! !

Guess you like

Origin blog.csdn.net/qq_41606378/article/details/113745648