UVALive 7146 Defeat the Enemy

题意:

你有n个攻击力为A,防御力为D的兽人,敌人有m个攻击力为EA,防御力为ED的兽人,两个兽人在对战时同时攻击对方,当攻击力高于对方的防御力时,即可杀死对方。你的兽人只能用一次。问你在杀死所有敌人的前提下你的兽人最多能剩多少。

思路:

将我们的兽人按攻击力A从大到小排列,敌人按防御力D从大到小排列,然后枚举每只敌人,将能杀死他也就是攻击力高于他的兽人防御力丢到一个multiset中,对于当前敌人,在multiset中找一个D刚好大于他攻击力的我们的兽人来干他,如果找不到大于他攻击力的就取一个防御力最小的和他同归于尽。这样做总是最优的。

#include<cstdio>
#include<set>
#include<algorithm>
using namespace std;

const int MAX=1e5+5;
int n,m;
multiset<int> s;
multiset<int>::iterator it;

struct Node{
	int A,D;
}a[MAX],b[MAX];

bool cmp1(Node a,Node b){
	return a.A>b.A;
}

bool cmp2(Node a,Node b){
	return a.D>b.D;
}

int main(){
	int T,cas=1;
	scanf("%d",&T);
	while(T--){
		scanf("%d%d",&n,&m);
		for(int i=0;i<n;i++){
			scanf("%d%d",&a[i].A,&a[i].D);
		}
		for(int i=0;i<m;i++){
			scanf("%d%d",&b[i].A,&b[i].D);
		}
		sort(a,a+n,cmp1);
		sort(b,b+m,cmp2);
		int ans=n,j=0;
		bool flag=true;
		s.clear();
		for(int i=0;i<m;i++){
			for(;j<n;j++){
				if(b[i].D<=a[j].A){
					s.insert(a[j].D);
				}
				else break;
			}
			if(s.empty()){
				flag=false;
				break;
			}
			it=s.upper_bound(b[i].A);
			if(it==s.end()) it=s.begin(),ans--;
			s.erase(it);
		}
		printf("Case #%d: ",cas++);
		if(flag) printf("%d\n",ans);
		else printf("-1\n");
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The Mongol Empire was one of the largest empires in history, stretching from Eastern Europe to Asia. It was founded by Genghis Khan in 1206 and lasted until the mid-14th century. The empire was known for its military prowess, innovative tactics, and the use of terror to intimidate its enemies. Genghis Khan was born in 1162 in the region that is now Mongolia. He was born into a family of nomads and grew up herding sheep and hunting. At the age of 16, he was captured by a rival tribe and enslaved. He escaped and later began to unite the various tribes of the region under his leadership. In 1206, he was declared the supreme ruler of the Mongol Empire. Under Genghis Khan's leadership, the Mongol Empire began to expand rapidly. Genghis Khan was a brilliant military strategist and his army was known for its speed and mobility. The Mongols were also skilled horsemen and archers, and they were able to defeat much larger armies using innovative tactics such as feigned retreats and surprise attacks. After Genghis Khan's death in 1227, his empire was divided among his four sons. Over the next few decades, the Mongol Empire continued to expand under the leadership of Genghis Khan's descendants. They conquered China, Central Asia, and parts of Eastern Europe. The Mongols were known for their brutality and the use of terror to intimidate their enemies. They were also tolerant of other religions and cultures, and they allowed conquered peoples to retain their own customs and traditions. One of the most famous Mongol leaders was Kublai Khan, who ruled China from 1279 to 1294. He founded the Yuan Dynasty, which was the first foreign dynasty to rule China. Kublai Khan was a patron of the arts and literature, and he encouraged the development of new technologies such as paper money and gunpowder. He also sent emissaries to Europe, including Marco Polo, who wrote about his travels in China. The Mongol Empire began to decline in the mid-14th century. The empire had become too large to be effectively governed, and there were internal divisions and conflicts among the ruling families. The Black Death, which swept through Europe and Asia in the mid-14th century, also had a devastating impact on the Mongol Empire. By the end of the 14th century, the Mongol Empire had disintegrated into several smaller states. Despite its reputation for brutality, the Mongol Empire had a significant impact on world history. The Mongols were responsible for the spread of ideas, technologies, and cultures across Eurasia. They also played a role in the development of international trade and commerce. The Mongol Empire was a significant force in world history, and its legacy can still be felt today.

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值