【2018icpc宁夏邀请赛现场赛】【Gym - 102222H】Fight Against Monsters(贪心排序)
題干:
It is my great honour to introduce myself to you here. My name is Aloysius Benjy Cobweb Dartagnan Egbert Felix Gaspar Humbert Ignatius Jayden Kasper Leroy Maximilian. As a storyteller, today I decide to tell you and others a story about the hero Huriyyah, and the monsters.
Once upon a time, citizens in the city were suffering from?nn?powerful monsters. They ate small children who went out alone and even killed innocent persons. Before the hero appeared, the apprehension had overwhelmed the people for several decades.
For the good of these unfortunate citizens, Huriyyah set off to the forest which was the main lair of monsters and fought with?nn?fierce and cruel monsters. The health point of the?ii-th monster was?HPiHPi, and its attack value was?ATKiATKi.
They fought in a cave through a turn-based battle. During each second, the hero Huriyyah was attacked by monsters at first, and the damage was the sum of attack values of all alive monsters. Then he selected a monster and attacked it. The monster would suffer the damage of?kk?(its health point would decrease by?kk) which was the times of attacks it had been came under. That is to say, for each monster, the damage of the first time that Huriyyah attacked it was?11, and the damage of Huriyyah's second attack to this monster was?22, the third time to this monster was?33, and so on. If at some time, the health point of a monster was less than or equal to zero, it died. The hero won if all monsters were killed.
Now, my smart audience, can you calculate the minimum amount of total damages our hero should suffer before he won the battle?
Input
The input contains several test cases, and the first line is a positive integer?TTindicating the number of test cases which is up to?103103.
For each test case, the first line contains an integers?n?(1≤n≤105)n?(1≤n≤105)?which is the number of monsters.
The?ii-th line of the following?nn?lines contains two integers?HPiHPi?and?ATKi?(1≤HPi,ATKi≤105)ATKi?(1≤HPi,ATKi≤105)?which describe a monster.
We guarantee that the sum of?nn?in all test cases is up to?106106.
Output
For each test case, output a line containing?Case #x: y, where?x?is the test case number starting from?11, and?y?is the minimum amount of total damages the hero should suffer.
Example
Input
2 3 1 1 2 2 3 3 3 3 1 2 2 1 3Output
Case #1: 19 Case #2: 14題目大意:
有n個野怪,給出生命和攻擊力,每個回合所有活著的妖怪一起攻擊你一次,之后你可以選擇一個野怪攻擊,如果你是第i次攻擊這個野怪,那么造成的傷害就是i,問你殺死所有野怪后受到的最小傷害。
解題報告:
按照造成的傷害排序之后求個結果就行了。
AC代碼:
#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<stack> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define FF first #define SS second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 2e5 + 5; struct Node {ll hp,atk;int num;bool operator<(const Node & b) const {return num*b.atk < b.num*atk;} } R[MAX]; const int UP = 555; int n; int db[MAX]; int main() {for(int i = 1; i<=UP; i++) {db[i] = db[i-1] + i;}int T,iCase=0;cin>>T;while(T--) {scanf("%d",&n);for(int i = 1; i<=n; i++) {scanf("%lld%lld",&R[i].hp,&R[i].atk);R[i].num = lower_bound(db,db+544,R[i].hp) - db;}sort(R+1,R+n+1);ll ans = 0,curt=0;for(int i = 1; i<=n; i++) curt += R[i].num, ans += curt * R[i].atk;printf("Case #%d: %lld\n",++iCase,ans);}return 0 ; }?
總結
以上是生活随笔為你收集整理的【2018icpc宁夏邀请赛现场赛】【Gym - 102222H】Fight Against Monsters(贪心排序)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《Valheim英灵神殿》常用指令一览
- 下一篇: 《Valheim英灵神殿》全物品代码一览