选择
- hdfs检查节点健康状态的指令
- a,b,c,d,e五个数进栈,随意进出请问a为开始有几种情况
大题
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int a[1000020];
int main(){
int n;
while(cin>>n){
int ans=0,cnt=0;
for(int i=1;i<=n;i++) cin>>a[i];
int temp=a[1];
for(int i=2;i<=n;i++){
if(temp!=a[i]){
cnt++;
ans=i;
}
}
if(cnt==1){
cout<<ans<<endl;
}
else cout<<1<<endl;
}
return 0;
}
- 输入三个数,输出经过多少次操作可以使三个数相等
操作1:两个数同时加1
操作2:一个数加2
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
int a,b,c;
const int maxn=105;
int book[105][105][105];
struct data{
int a,b,c,step;
data(){}
data(int aa,int bb,int cc,int stepp){
a=aa;
b=bb;
c=cc;
step=stepp;
}
};
queue<data>que;
int bfs(int a,int b,int c){
while(!que.empty()){
que.pop();
}
book[a][b][c]=1;
que.push(data(a,b,c,0));
while(!que.empty()){
data temp=que.front();
que.pop();
if(temp.a==temp.b&&temp.b==temp.c){
return temp.step;
}
if(book[temp.a+1][temp.b+1][temp.c]==-1){
que.push(data(temp.a+1,temp.b+1,temp.c,temp.step+1));
book[temp.a+1][temp.b+1][temp.c]=1;
}
if(book[temp.a+1][temp.b][temp.c+1]==-1){
que.push(data(temp.a+1,temp.b,temp.c+1,temp.step+1));
book[temp.a+1][temp.b][temp.c+1]=1;
}
if(book[temp.a][temp.b+1][temp.c+1]==-1){
que.push(data(temp.a,temp.b+1,temp.c+1,temp.step+1));
book[temp.a][temp.b+1][temp.c+1]=1;
}
if(book[temp.a][temp.b][temp.c+2]==-1){
que.push(data(temp.a,temp.b,temp.c+2,temp.step+1));
book[temp.a][temp.b][temp.c+2]=1;
}
if(book[temp.a][temp.b+2][temp.c]==-1){
que.push(data(temp.a,temp.b+2,temp.c,temp.step+1));
book[temp.a][temp.b+2][temp.c]=1;
}
if(book[temp.a+2][temp.b][temp.c]==-1){
que.push(data(temp.a+2,temp.b,temp.c,temp.step+1));
book[temp.a+2][temp.b][temp.c]=1;
}
}
return -1;
}
int main(){
while(~scanf("%d%d%d",&a,&b,&c)){
memset(book,-1,sizeof(book));
cout<<bfs(a,b,c)<<endl;
}
return 0;
}