HDU-6396-Swordsman(文件输入+优先队列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6396
Problem Description Lawson is a magic swordsman with k kinds of magic attributes v1,v2,v3,…,vk . Now Lawson is faced with n monsters and the i -th monster also has k kinds of defensive attributes ai,1,ai,2,ai,3,…,ai,k . If v1≥ai,1 and v2≥ai,2 and v3≥ai,3 and … and vk≥ai,k , Lawson can kill the i -th monster (each monster can be killed for at most one time) and get EXP from the battle, which means vj will increase bi,j for j=1,2,3,…,k . Input There are multiple test cases. The first line of input contains an integer T , indicating the number of test cases. For each test case: It is guaranteed that the sum of all n ≤5×105 . Output For each test case: Sample Input 1 4 3 7 1 1 5 5 2 6 3 1 24 1 1 1 2 1 0 4 1 5 1 1 6 0 1 5 3 1 Sample Output 3 23 8 4 Hint For the sample, initial V = [7, 1, 1] ① kill monster #4 (6, 0, 1), V + [5, 3, 1] = [12, 4, 2] ② kill monster #3 (0, 4, 1), V + [5, 1, 1] = [17, 5, 3] ③ kill monster #1 (5, 5, 2), V + [6, 3, 1] = [23, 8, 4] After three battles, Lawson are still not able to kill monster #2 (24, 1, 1) because 23 < 24. |
题目大意:一个k系法师,他的每种元素都有一个法强vi,他碰见 了n个怪物,第i个怪物对每种魔法有着自己的魔抗a[i][k];
大法师只有所有元素的法强都大于怪物对应的法强的时候才会击杀怪物
大法师每次击杀一个怪物,会得到怪物的经验,经验会提升大法师不同元素的法强,问大法师最多能有多少法强。
read()函数的板子:https://blog.csdn.net/qq_37632935/article/details/81665581
输入太多,用read()函数读(这道题本身就是read的板子),至于打怪升级这件事,开五个优先队列,每个优先队列存入怪物的魔抗+ID(k不是五的其他的按0计算),遍历五个优先队列,对于能被击破魔抗的ID 加一,并将它移除队列,如果最后ID==5则这只怪物能被击杀,直接进行经验加成,最后一只怪物都杀不了时结束循环
ac;
//一页 27行就很舒服
#include<stdio.h>
#include<string.h>
#include<math.h> //#include<map>
//#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<bitset>
#include<string>
#include<fstream>
#include<iostream>
#include<algorithm>
using namespace std; #define ll long long
#define INF 0x3f3f3f3f
#define mod 998244353
//#define max(a,b) (a)>(b)?(a):(b)
//#define min(a,b) (a)<(b)?(a):(b)
#define clean(a,b) memset(a,b,sizeof(a))// 水印
//std::ios::sync_with_stdio(false);//需要自己写文件读入scanf和getchar()都不能用。
//freopen("1.txt","r",stdin);
namespace fastIO {#define BUF_SIZE 100000//fread -> readbool IOerror = 0;inline char nc() {static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE;if(p1 == pend) {p1 = buf;pend = buf + fread(buf, 1, BUF_SIZE, stdin);if(pend == p1) {IOerror = 1;return -1;}}return *p1++;}inline bool blank(char ch) {return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';}inline void read(int &x) {char ch;while(blank(ch = nc()));if(IOerror) return;for(x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0');}#undef BUF_SIZE
};
using namespace fastIO;struct node{int blood;int ID;node (int _blood=0,int _ID=0):blood(_blood),ID(_ID){}bool operator <(const node &a)const{return blood>a.blood;}
};
int v[10],ves[100100],arr[100100][6];
int n,k;priority_queue<node> que[6];int main()
{//freopen("in.txt", "r",stdin);//因为用的是文件读入,因此我们只能在文件中写样例,叫代码的时候要将本地的文件操作注释掉,否则会 WAint t;read(t);while(t--){clean(ves,0);clean(arr,0);clean(v,0);read(n);read(k);for(int i=1;i<=k;++i)read(v[i]);for(int i=1;i<=n;++i){for(int j=1;j<=5;++j){int blood;if(j<=k){read(blood);que[j].push(node(blood,i));}elseque[j].push(node(0,i));}//输入血量 ,ID=i for(int j=1;j<=5;++j){int add;if(j<=k){read(add);arr[i][j]=add;}elsearr[i][j]=0;}//输入经验 }//输入完成 //debug 没有错
// for(int i=1;i<=5;++i)
// {
// while(que[i].size())
// {
// cout<<que[i].top().blood<<" "<<que[i].top().ID<<" |";
// que[i].pop();
// }
// cout<<endl;
// }
// for(int i=1;i<=n;++i)
// {
// for(int j=1;j<=5;++j)
// cout<<arr[i][j]<<" ";
// cout<<endl;
// }int sum=0;while(1){int f=0;for(int i=1;i<=5;++i){while(que[i].size()){node now=que[i].top();if(now.blood<=v[i]){que[i].pop();ves[now.ID]++;if(ves[now.ID]==5){sum++;f=1;for(int j=1;j<=5;++j)v[j]=v[j]+arr[now.ID][j];}}elsebreak;}
// for(int j=1;j<=n;++j)
// cout<<ves[j]<<" ";
// cout<<endl;}if(f==0)break;}printf("%d\n",sum);for(int i=1;i<k;++i)printf("%d ",v[i]);printf("%d\n",v[k]);for(int i=0;i<6;++i){while(que[i].size())que[i].pop();}
// cout<<sum<<endl;
// for(int i=1;i<=k;++i)
// cout<<v[i]<<" ";}
}
HDU-6396-Swordsman(文件输入+优先队列)相关推荐
- hdu 6396 Swordsman
题目:点击打开链接 题意:打小怪兽的题目,主角有k个技能,每个技能有对应的攻击力ai,怪兽有k个防御值bi,k个强化能量ci.只有所有的ai > = bi,这只小怪兽才会被打死.然后主角的技能就 ...
- hdu 6396 Swordsman (技巧)
大意: n个怪, m种能力值, 当自己所有能力值不低于某只怪时可以杀死它, 并获得它的所有能力, 求最大杀几只 将每只怪拆成$m$个, 排下序贪心即可, 复杂度$O(nm)$, 原题极其卡时间, 我的 ...
- C++文件输入和输出
1.引入头文件fstream fstream头文件定义了用于文件输入的类ifstream和文件输出的类ofstream 2.写文件 1)创建一个ofstream对象来管理输出流 2)将该对象与文件关联 ...
- C/C++-标准输入/输出重定向为文件输入/输出
/*Time: 2017-02-22 11:11:15Describe: C++程序将标准输入/输出重定向为文件输入/输出. */#include <iostream> #include ...
- matlab怎么输入输出文件,[转载]底层文件输入输出函数
[转载]底层文件输入输出函数 http://sincerewfeng.spaces.live.com/ fclose :关闭文件 fopen :打开文件 fread :从文件中读入二进制数据 fwri ...
- java输出流输入流的使用_Java中的IO流之文件输入输出流
Java中的IO流之文件输入输出流 1.文件流介绍 文件流是以字节为单位进行读写文件的,所以属于字节流,并且是低级流.文件流位于java.io包下. 输入输出流分别是FileInputSteam和Fi ...
- 1.6 Java字节流的使用:字节输入/输出流、文件输入/输出流、字节数组输入/输出流
InputStream 是 Java 所有字节输入流类的父类, OutputStream 是 Java 所有字节输出流类的父类, 它们都是一个抽象类,因此继承它们的子类要重新定义父类中的抽象方法. 下 ...
- yamlcpp遍历_OpenCV文件输入和输出使用XML和YAML文件
目标 您会找到以下问题的答案:如何使用YAML或XML文件打印和读取文本和OpenCV文本条目? OpenCV数据结构如何做同样的操作? 如何为您的数据结构做这个? 源代码 您可以从这里下载,也可以在 ...
- Samba nsswitch/pam_winbind.c文件输入验证漏洞
漏洞名称: Samba nsswitch/pam_winbind.c文件输入验证漏洞 CNNVD编号: CNNVD-201312-047 发布时间: 2013-12-05 更新时间: 2013-12- ...
- OpenCV XML和YAML文件的文件输入和输出
OpenCV XML和YAML文件的文件输入和输出 XML和YAML文件的文件输入和输出 目标 源代码 解释 XML / YAML文件打开和关闭. 文本和数字的输入和输出. OpenCV数据结构的输入 ...
最新文章
- 操作系统学习:启动进入实模式
- verilog设计一个补码加减法运算器_漫画:为什么计算机用补码存储数据?
- mysql show作用_mysql的show操作
- 浅谈Android中Lifecycle
- c# 扩展方法奇思妙用高级篇一:改进 Scottgu 的 In 扩展
- mysql 优化方法有哪些?
- centos6.5+jexus5.6.3+mono 3.10实践,让asp.net在linux上飞一会儿
- HTML+CSS+JS 实现全屏下雪动画背景用户登录注册表单
- 32 位和 64 位版本的 Office 2010 之间的兼容性
- Mac电脑上哪个解压缩软件好用?MAC上好用的解压缩软件分享
- Creo9.0 绘制中心线
- 移动端APP测试总结
- [附源码]PHP计算机毕业设计小区水电管理系统(程序+LW)
- 企业计算机系统管理基本要求,药品经营企业计算机系统介绍.ppt
- 自定义View入门 --转载自武老师博客160303
- 分享一个直接加QQ好友的链接或会话的
- 【YM】ssh命令 远程登录Linux
- android随机数1 100,android 产生0~100之间的随机数
- 如何高枕无忧地使用PostgreSQL?
- 三星android8 日期,三星披露升级Android 8.0时间 明年年初
热门文章
- biztalk 2006 事务补偿模型[翻译]
- 工作缺点和不足及措施_个人工作问题不足20条以及改进措施
- 什么是平面设计,平面设计主要做什么?
- PowerShell输出IP地址
- erp实施 数据库面试题_erp实施顾问笔试题有什么_erp实施顾问
- qq邮件exchange服务器,解决Exchange邮件系统无法接收QQ邮件的问题
- GeoServer中利用SLD配图之矢量图层配图
- 星际争霸2的图形界面几乎全部使用Flash搭建?
- itools电脑显示服务器维护,win10系统iTools无法打开且服务无法启动的具体技巧
- IT 行业的创新 - 创新的迷思 (7-8)