链接:登录—专业IT笔试面试备考平台_牛客网
来源:牛客网
题目描述
公元2348年,人类与外星帝国爆发了星际战争,但是人类的科技过于落后,在正面战场节节败退。现在ZH是人类派出的唯一一艘恒星级战舰的指挥官。ZH需要穿越星海突击敌军母星,但是外星帝国在路上布置了很多引力波屏障,这种屏障需要特制的攻城武器才能攻破。
恒星级战舰十分强大,可以挂载无限多的攻城武器,但是初始时没有挂载武器,战舰的初始结构值为 ,在突破的路上ZH会遇到一下几种事件:
0 x
战舰获得了一门属性值为 的武器;1 x
战舰跃迁过程中损坏了一门属性值为 的武器,保证损坏的武器原来一定存在;2 x h
战舰遇到了一个屏障,屏障的结构值为 ,特征值为 ,每个武器对它造成的伤害为(武器属性值⊕屏障特征值)(武器属性值 \oplus 屏障特征值)(武器属性值⊕屏障特征值)( 的意思是按位异或),输出 战舰中可以对屏障造成伤害 大于 的武器数量,如果没有可以一次击破屏障的武器,战舰会直接强行穿过屏障,但是会减少一点结构值。
最后输出战舰剩余结构值。
保证战舰结构值最终大于等于0。
输入描述:
第一行输入为两个整数n,hp{n,hp}n,hp
接下来n{n}n 行每行为一个事件
1≤n≤1051\leq n \leq 10^51≤n≤105
0≤x,hp,h≤1090\leq x,hp, h \leq10^90≤x,hp,h≤109
输出描述:
每次事件2输出一个整数为可用武器数量占一行
最后输出战舰剩余结构值
示例1
输入
复制7 2 0 3 0 4 2 6 3 0 2 2 6 3 1 3 2 6 3
7 2 0 3 0 4 2 6 3 0 2 2 6 3 1 3 2 6 3
输出
复制1 2 1 2
1 2 1 2
我的代码:
#include<bits/stdc++.h>
using namespace std;
int ch[100100],cnt,ct;
int main(){
int n,hp;
cin>>n>>hp;
int t;//pos=0;
for(int i=1;i<=n;i++){
//ct++;
cin>>t;
if(t==0){
int p;
cin>>p;
ch[i]=p;
//x+=p;
//cnt++;
}
if(t==1){
int p;
cin>>p;
for(int j=1;j<=i;j++){
if(ch[j]==p){
// x-=p;
// cnt--;
// break;
ch[j]=0;
break;
}
//cout<<ch[j]<<"#";
}
}
if(t==2){
int xt,h;
cin>>xt>>h;
//if(h>=(x^xt)){
// hp--;
/*for(int j=1;j<=k;j++){
sum=ch[j]+sum;
if(h>sum^xt){
cnt=0;
}
}*/
// cnt=0,x=0;
// cout<<cnt<<endl;
//}
/*else if(h==(x^xt)){
x=0;
cnt=0;
hp--;
cout<<cnt<<endl;
}*/
cnt=0;
for(int j=1;j<=i;j++){
//sum=(sum+ch[j]);
if(ch[j]!=0){
if((ch[j]^xt)>h){
cnt++;
//pos=1;
//x=x-ch[j];
}
}
}
cout<<cnt<<endl;
if(cnt==0) hp--;
//cout<<0<<endl;
//x=(xt^x)-h;
}
}
cout<<hp;
return 0;
}
大哥的
#include<bits/stdc++.h>
using namespace std;
int n,hp,op,x,y;
int main(){
cin>>n>>hp;
vector<int> v;
while(n--){
cin>>op;
if(op==0){
cin>>x;
v.push_back(x);
}
else if(op==1){
cin>>x;
vector<int>::iterator it=find(v.begin(),v.end(),x);
v.erase(it);
}
else{
cin>>x>>y;
int cnt=0,s=v.size();;
for(int i=0;i<s;i++)
if(y<(v[i]^x) ) cnt++;
cout<<cnt<<"\n";
if(cnt==0) hp--;
}
}
cout<<hp;
return 0;
}