1200*B. BerSU Ball(贪心)

解析;

        排序,然后遍历贪心选择。

#include<bits/stdc++.h>
using namespace std;
const int N=101;
int n,m,a[N],b[N],t,res;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	cin>>m;
	for(int i=1;i<=m;i++){
		cin>>b[i];
	}
	sort(a+1,a+n+1);
	sort(b+1,b+m+1);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(b[j]!=-1&&abs(b[j]-a[i])<=1){
				b[j]=-1,res++;
				break;
			}
		}
	}	
	cout<<res;
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
帮我注释下面代码class Ball: """ 针头 """ def __init__(self, angle): self.x = x0 self.y = y0 + length self.center = (self.x, self.y) self.radius = 12 self.angle = angle ball_group.append(self) def draw(self, surface): pygame.draw.line(surface, WHITE, shaft, self.center, 2) pygame.draw.circle(surface, WHITE, self.center, 12) def move(self, speed): """ 围绕转轴做圆周运动 :param speed: 转动的角速度 :return: """ if self.angle < 2 * math.pi: self.angle += speed else: self.angle = self.angle - 2 * math.pi self.x = x0 - length * math.sin(self.angle) self.y = y0 + length * math.cos(self.angle) self.center = (self.x, self.y) def check_collide(new_ball): for ball in ball_group: distance = math.sqrt(abs(ball.x - new_ball.x) ** 2 + abs(ball.y - new_ball.y) ** 2) if ball is not new_ball and distance <= new_ball.radius * 2: return True return False def game_init(): global stage, gaming, remain_ball, stage_pass,score if stage == len(all_stage): stage = 1 elif stage_pass: stage += 1 ball_group.clear() for a in all_stage[stage - 1]: b = Ball(a) remain_ball = ball_num[stage - 1] score=0 pygame.time.delay(200) gaming = True stage_pass = False button = Button('重新开始', color=(220, 0, 0)) button.rect.center = shaft button.click_connect(game_init) def restart(): for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() button.get_click(event) def game_stage(): global remain_ball, stage, gaming, stage_pass,score if remain_ball == 0 and gaming: stage_pass = True gaming = False
06-02

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值