题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6396
假设k为5,那么开5个数组用来分别存放每头怪兽对应的五个防御力
用五个指针去从头开始遍历,如果当前值小于对应的攻击力,就判断一下这头怪兽的五个值是不是都小于其对应的男主的攻击力
如果都小于那么就把能力值都加上b继续找,直到找不到为止
namespace IO {
const int MX = 4e7; //1e7 占用内存 11000kb
char buf[MX]; int c, sz;
void begin() {
c = 0;
sz = fread(buf, 1, MX, stdin);//一次性全部读入
}
inline bool read(int &t) {
while (c < sz && buf[c] != '-' && (buf[c] < '0' || buf[c] > '9')) c++;
if (c >= sz) return false;//若读完整个缓冲块则退出
bool flag = 0; if(buf[c] == '-') flag = 1, c++;
for(t = 0; c < sz && '0' <= buf[c] && buf[c] <= '9'; c++) t = t * 10 + buf[c] - '0';
if(flag) t = -t;
return true;
}
}
IO::read();
在网上找了一个很厉害的输入挂,加上就过了,,,不然会T
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <bitset>
#include <cmath>
#include <cctype>
#include <unordered_map>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <iomanip>
using namespace std;
#define For(i,m,n) for(int i=m;i<=n;i++)
#define Dor(i,m,n) for(int i=m;i>=n;i--)
#define LL long long
#define lan(a,b) memset(a,b,sizeof(a))
const int N=100005;
struct node
{
int p,id;
bool operator <(const node &tem) const{return p<tem.p;}
};
vector<node> run[6];
int flag[N];
int num[6];
int b[N][6];
int p[6];
namespace IO {
const int MX = 4e7; //1e7 占用内存 11000kb
char buf[MX]; int c, sz;
void begin() {
c = 0;
sz = fread(buf, 1, MX, stdin);//一次性全部读入
}
inline bool read(int &t) {
while (c < sz && buf[c] != '-' && (buf[c] < '0' || buf[c] > '9')) c++;
if (c >= sz) return false;//若读完整个缓冲块则退出
bool flag = 0; if(buf[c] == '-') flag = 1, c++;
for(t = 0; c < sz && '0' <= buf[c] && buf[c] <= '9'; c++) t = t * 10 + buf[c] - '0';
if(flag) t = -t;
return true;
}
}
int main()
{
cin.tie(0);
cout.tie(0);
IO::begin();
int t;
IO::read(t);
while(t--)
{
printf("22");
lan(p,0);
lan(flag,0);
lan(b,0);
lan(num,0);
For(i,1,5)
run[i].clear();
int n,k;
IO::read(n);
IO::read(k);
for(int i=1;i<=k;i++)
IO::read(num[i]);
For(i,1,n)
{
For(j,1,k)
{
int tem;
IO::read(tem);
run[j].push_back((node){tem,i});
}
For(j,1,k)
IO::read(b[i][j]);
}
int f=1,ans=0;
For(i,1,k)sort(run[i].begin(),run[i].end());
while(f--){
For(i,1,k)
for(int j=p[i];j<n;j++,p[i]++){
// printf("run[%d][%d]:%d,num[%d]=%d\n",i,j,run[i][j].p,i,num[i]);
if(run[i][j].p<=num[i]){
int id=run[i][j].id;
flag[id]++;
if(flag[id]==k){
f=1;
ans++;
For(l,1,k)num[l]+=b[id][l];
}
}
else break;
}
}
printf("%d\n",ans);
For(i,1,k){
if(i==k)
printf("%d\n",num[i]);
else
printf("%d ",num[i]);
}
}
}
本文提供了一道来自杭电OJ编号为6396的题目解决方案,采用C++实现,通过定义多个数组来存储怪兽的不同防御力,并使用指针进行遍历比较,以确定主角能否击败怪兽并获取奖励。

被折叠的 条评论
为什么被折叠?



