UVA LIVE 7146 Defeat the Enemy

来源:互联网 发布:ajax post提交json 编辑:程序博客网 时间:2024/05/21 08:39

这个题跟codeforces 556 D Case of Fugitive思路一样

关于codeforces 556 D Case of Fugitive的做法的链接http://blog.csdn.net/stl112514/article/details/46868749


题意大概我方有n个军队,敌方有m个军队,军队有两个属性:攻击力和防御力

一个军队能打败另一个军队的条件:一军队攻击力不低于另一个军队防御力


大概是2014上海区域赛最简单的一个题?


#include<map>#include<string>#include<cstring>#include<cstdio>#include<cstdlib>#include<cmath>#include<queue>#include<vector>#include<iostream>#include<algorithm>#include<bitset>#include<climits>#include<list>#include<iomanip>#include<stack>#include<set>using namespace std;struct Tr{int at,df;bool operator <(Tr one)const{return df<one.df;}}gd[int(1e5)+10],bd[int(1e5)+10];bool cmp(Tr one,Tr two){return one.at>two.at;}bool cmp1(Tr one,Tr two){return one.df>two.df;}int main(){int T;cin>>T;for(int cs=1;cs<=T;cs++){int n,m;cin>>n>>m;for(int i=0;i<n;i++)cin>>gd[i].at>>gd[i].df;for(int i=0;i<m;i++)cin>>bd[i].at>>bd[i].df;sort(gd,gd+n,cmp);sort(bd,bd+m,cmp1);map<Tr,int>mp;int ans=0;for(int i=0,j=0;i<m;i++){while(j<n&&gd[j].at>=bd[i].df)mp[gd[j++]]++;if(mp.empty()){ans=-1;break;}map<Tr,int>::iterator it;swap(bd[i].at,bd[i].df);it=mp.upper_bound(bd[i]);swap(bd[i].at,bd[i].df);if(it==mp.end())it=mp.begin();Tr t=it->first;it->second--;if(it->second==0)mp.erase(it);if(t.at<bd[i].df){ans=-1;break;}if(t.df<=bd[i].at)ans++;}if(ans!=-1)ans=n-ans;printf("Case #%d: %d\n",cs,ans);}return 0;}


Time Limit:3000MS

7146 Defeat The EnemyLong long ago there is a strong tribe living on the earth. They always have wars and eonquer others.One day, there is another tribe become their target. The strong tribe has decide to terminate them!!!There are m villages in the other tribe. Each village contains a troop with attack power EAttacki,and defense power EDefensei. Our tribe has n troops to attack the enemy. Each troop also has theattack power Attacki, and defense power Defensei. We can use at most one troop to attack one enemyvillage and a troop can only be used to attack only one enemy village. Even if a troop survives anattack, it can’t be used again in another attack.The battle between 2 troops are really simple. The troops use their attack power to attack againstthe other troop simultaneously. If a troop’s defense power is less than or equal to the other troop’sattack power, it will be destroyed. It’s possible that both troops survive or destroy.The main target of our tribe is to destroy all the enemy troops. Also, our tribe would like to havemost number of troops survive in this war.InputThe first line of the input gives the number of test cases, T. T test cases follow. Each test case startwith 2 numbers n and m, the number of our troops and the number of enemy villages. n lines follow,each with Attacki and Defensei, the attack power and defense power of our troops. The next m linesdescribe the enemy troops. Each line consist of EAttacki and EDefensei, the attack power and defensepower of enemy troopsOutputFor each test ease, output one line containing ‘Case #x: y’, where x is the test case number (startingfrom 1) and y is the max number of survive troops of our tribe. If it‘s impossible to destroy all enemytroops, output ‘-1’ instead.Limits:1 ≤ T ≤ 100,1 ≤ n, m ≤ 105,1 ≤ Attacki, Defensei, EAttacki, EDefensei ≤ 109,Sample Input23 25 77 31 24 42 22 13 41 105 6ACM-ICPC Live Archive: 7146 – Defeat The Enemy 2/2Sample OutputCase #1: 3Case #2: -1



0 0
原创粉丝点击