The Dragon of Loowater(勇者斗恶龙)

Once upon a time, in the Kingdom of Loowater, a minor nuisance turned into a major problem.

The shores of Rellau Creek in central Loowater had always been a prime breeding ground for geese. Due to the lack of predators, the geese population was out of control. The people of Loowater mostly kept clear of the geese. Occasionally, a goose would attack one of the people, and perhaps bite off a finger or two, but in general, the people tolerated the geese as a minor nuisance.

One day, a freak mutation occurred, and one of the geese spawned a multi-headed fire-breathing dragon. When the dragon grew up, he threatened to burn the Kingdom of Loowater to a crisp. Loowater had a major problem. The king was alarmed, and called on his knights to slay the dragon and save the kingdom.

The knights explained: "To slay the dragon, we must chop off all its heads. Each knight can chop off one of the dragon's heads. The heads of the dragon are of different sizes. In order to chop off a head, a knight must be at least as tall as the diameter of the head. The knights' union demands that for chopping off a head, a knight must be paid a wage equal to one gold coin for each centimetre of the knight's height."

Would there be enough knights to defeat the dragon? The king called on his advisors to help him decide how many and which knights to hire. After having lost a lot of money building Mir Park, the king wanted to minimize the expense of slaying the dragon. As one of the advisors, your job was to help the king. You took it very seriously: if you failed, you and the whole kingdom would be burnt to a crisp!

Input Specification:

The input contains several test cases. The first line of each test case contains two integers between 1 and 20000 inclusive, indicating the number n of heads that the dragon has, and the number m of knights in the kingdom. The next n lines each contain an integer, and give the diameters of the dragon's heads, in centimetres. The following m lines each contain an integer, and specify the heights of the knights of Loowater, also in centimetres.

The last test case is followed by a line containing:

0 0

Output Specification:

For each test case, output a line containing the minimum number of gold coins that the king needs to pay to slay the dragon. If it is not possible for the knights of Loowater to slay the dragon, output the line:

Loowater is doomed!

Sample Input:

2 3
5
4
7
8
4
2 1
5
5
10
0 0

Output for Sample Input:

11
Loowater is doomed!

代码如下:

#include <cstdio>
int N[20000],M[20000];
int n,m;
void sort(int a[])//排序骑士
{
	for (int i = 0; i < m; i++)
	{
		for (int j = i + 1; j < m; j++)
		{
			if (a[i] > a[j])
			{
				int temp = a[i];
				a[i] = a[j];
				a[j] = temp;
			}
		}
	}
}
int main()
{
	while (scanf("%d%d",&n,&m) == 2 && n && m)
	{
		for (int i = 0; i < n; i++)
		{
			scanf("%d",&N[i]);
		}
		for (int j = 0; j < m; j++)
		{
			scanf("%d",&M[j]);
		}
		sort(M);//排序
		int cost = 0,cnt = 0;//cost保存总花费,cnt保存已被砍头个数
		for (int k = 0; k < n; k++)
		{
			for (int j = 0; j < m; j++)
			{
				if (M[j] >= N[k])
				{
					cost += M[j];
					M[j] = 0;
					cnt++;
					break;
				}
			}
		}
		if (cnt < n)
			printf("Loowater is doomed!\n");
		else
			printf("%d\n",cost);
	}
	return 0;
}

 
好的,下面是一个简单的JAVA实现勇者恶龙的回合制游戏的示例代码,包括4个技能、闪避防御操作和道具系统: ```java import java.util.Scanner; public class DragonQuestGame { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Hero hero = new Hero("勇者", 100, 10, 5, 5); Dragon dragon = new Dragon("恶龙", 150, 15, 10, 10); while (hero.isAlive() && dragon.isAlive()) { System.out.println(hero.getName() + "的回合"); System.out.println("请选择技能:1.普通攻击 2.火球术 3.冰冻术 4.治疗术"); int skillChoice = scanner.nextInt(); switch (skillChoice) { case 1: hero.attack(dragon); break; case 2: hero.fireball(dragon); break; case 3: hero.freeze(dragon); break; case 4: hero.heal(); break; } if (!dragon.isAlive()) { break; } System.out.println(dragon.getName() + "的回合"); if (Math.random() < 0.5) { dragon.attack(hero); } else { if (Math.random() < 0.5) { hero.dodge(); } else { hero.defend(); } } } if (hero.isAlive()) { System.out.println(hero.getName() + "获胜!"); } else { System.out.println(dragon.getName() + "获胜!"); } } } class Hero { private String name; private int hp; private int attack; private int fireballDamage; private int freezeDuration; public Hero(String name, int hp, int attack, int fireballDamage, int freezeDuration) { this.name = name; this.hp = hp; this.attack = attack; this.fireballDamage = fireballDamage; this.freezeDuration = freezeDuration; } public String getName() { return name; } public boolean isAlive() { return hp > 0; } public void attack(Dragon dragon) { System.out.println(name + "使用普通攻击攻击" + dragon.getName()); dragon.takeDamage(attack); } public void fireball(Dragon dragon) { System.out.println(name + "使用火球术攻击" + dragon.getName()); dragon.takeDamage(fireballDamage); } public void freeze(Dragon dragon) { System.out.println(name + "使用冰冻术攻击" + dragon.getName()); dragon.freeze(freezeDuration); } public void heal() { System.out.println(name + "使用治疗术恢复生命值"); hp += 20; } public void dodge() { System.out.println(name + "成功闪避了攻击"); } public void defend() { System.out.println(name + "成功防御了攻击"); } public void takeDamage(int damage) { hp -= damage; System.out.println(name + "受到" + damage + "点伤害,剩余生命值:" + hp); } } class Dragon { private String name; private int hp; private int attack; private int freezeDuration; private boolean isFrozen; public Dragon(String name, int hp, int attack, int freezeDuration, double dodgeProbability) { this.name = name; this.hp = hp; this.attack = attack; this.freezeDuration = freezeDuration; this.isFrozen = false; } public String getName() { return name; } public boolean isAlive() { return hp > 0; } public void attack(Hero hero) { System.out.println(name + "使用普通攻击攻击" + hero.getName()); if (Math.random() < 0.5) { hero.dodge(); } else { hero.takeDamage(attack); } } public void freeze(int duration) { System.out.println(name + "使用冰冻术冻结了" + duration + "回合"); isFrozen = true; freezeDuration = duration; } public void takeDamage(int damage) { hp -= damage; System.out.println(name + "受到" + damage + "点伤害,剩余生命值:" + hp); } public void tick() { if (isFrozen) { System.out.println(name + "被冰冻了" + freezeDuration + "回合"); freezeDuration--; if (freezeDuration == 0) { isFrozen = false; } } } } ``` 在这个示例代码中,Hero类代表勇者Dragon类代表恶龙,每个角色都有名字、生命值、攻击力和其他属性。当勇者恶龙的生命值都大于0时,轮流进行回合,每回合勇者可以选择使用4个技能中的一个,恶龙则会根据随机概率进行攻击、闪避或防御。当其中一方生命值降为0时结束游戏。 该示例代码还包括一个简单的道具系统,可以根据需要添加更多道具和功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值