C - Bear and Finding Criminals(对称性+枚举)

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
我在想,抓小偷不应该是距离近的抓吗?非要对称,这个题感觉不符合常识;嘻嘻
题意:从出发点对称找,如果两边都有那么+2,如果一边有那么+1(这里的一边只针对有一边越界了的,如果两边都没有越界就不加1滴),如果越界了注意限制条件就行:
AC代码:

#include<bits/stdc++.h>//A - Decoding  
using namespace std;
typedef long long ll;
int main(){
  int n,x,a[200];
scanf("%d %d",&n,&x);
for(int i=1;i<=n;i++)scanf("%d",a+i);
  int ans=0;
  if(a[x])ans++;//提前判断 出发点是不是有犯罪的(criminal)
  int f1=0,f2=0;
  for(int i=x-1,j=x+1;;i--,j++){
  	    if(i<1)f1=1;//如果左边越界
  	    if(j>n)f2=1;//如果右边越界
  	    if(f1&&f2)break;
  	    if(!f1&&!f2){
  	    	   if(a[i]==a[j]&&a[j]==1)ans+=2;
  	    	   continue;
		  }
		  if(f1&&!f2){
		  	if(a[j])ans++;
		  	continue;
		  }
		  if(!f1&&f2){
		  	  if(a[i])ans++;
		  	  continue;
		  }
  }
    printf("%d\n",ans);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
代码每句话多啥意思// if ( num_iter < 10000 ) // cout << "current=" << current->index.transpose() << endl; if (current->index(0) == endPtr->index(0) && current->index(1) == endPtr->index(1) && current->index(2) == endPtr->index(2))判断当前节点是否为终点。 { // ros::Time time_2 = ros::Time::now(); // printf("\033[34mA star iter:%d, time:%.3f\033[0m\n",num_iter, (time_2 - time_1).toSec()*1000); // if((time_2 - time_1).toSec() > 0.1) // ROS_WARN("Time consume in A star path finding is %f", (time_2 - time_1).toSec() ); gridPath_ = retrievePath(current); return true; } current->state = GridNode::CLOSEDSET; //move current node from open set to closed set. for (int dx = -1; dx <= 1; dx++) for (int dy = -1; dy <= 1; dy++) for (int dz = -1; dz <= 1; dz++) { if (dx == 0 && dy == 0 && dz == 0) continue; Vector3i neighborIdx; neighborIdx(0) = (current->index)(0) + dx; neighborIdx(1) = (current->index)(1) + dy; neighborIdx(2) = (current->index)(2) + dz; if (neighborIdx(0) < 1 || neighborIdx(0) >= POOL_SIZE_(0) - 1 || neighborIdx(1) < 1 || neighborIdx(1) >= POOL_SIZE_(1) - 1 || neighborIdx(2) < 1 || neighborIdx(2) >= POOL_SIZE_(2) - 1) { continue; } neighborPtr = GridNodeMap_[neighborIdx(0)][neighborIdx(1)][neighborIdx(2)]; neighborPtr->index = neighborIdx; bool flag_explored = neighborPtr->rounds == rounds_; if (flag_explored && neighborPtr->state == GridNode::CLOSEDSET) { continue; //in closed set. } neighborPtr->rounds = rounds_; if (checkOccupancy(Index2Coord(neighborPtr->index))) { continue; } double static_cost = sqrt(dx * dx + dy * dy + dz * dz); tentative_gScore = current->gScore + static_cost;
最新发布
06-06

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值