切水果


#include <iostream>
using namespace std;
int main() {
	int mesh[40][50];
	int tempx, tempy;
	int row = 0;
	int point = 0;
	int pointTemp[4];//h,s,p,n
	int time=0;
	memset(mesh, 0, sizeof(mesh));
	memset(pointTemp, 0, sizeof(pointTemp));
	cin >> row;
	for (int i = 0; i < row; i++) {
		cin >> tempx;
		cin >> tempy;
		mesh[tempx][tempy] = 1;
		point++;
	}
	int cutDir = 0;
	for (int x = 0; x < 40; x++) {
		for (int y = 0; y < 50; y++) {//find num
			if (mesh[x][y] == 1) {//找到就切
				time++;
				mesh[x][y] = 0;
				point--;
				for (int h = 0; h < 50; h++) {//横
					if (mesh[x][h] == 1) {
						pointTemp[0]++;
					}
				}
				for (int s = 0; s < 40; s++) {//竖
					if (mesh[s][y] == 1) {
						pointTemp[1]++;
					}
				}
				for (int s = 0; s < 40; s++) {
					for (int h = 0; h < 50; h++) {
						if ((s + h) == (x + y) && mesh[s][h] == 1) {//撇
							pointTemp[2]++;
						}
					}
				}
				for (int s = 0; s < 40; s++) {
					for (int h = 0; h < 50; h++) {
						if ((40 + 50 - s + h) == (40 + 50 - x + y) && mesh[s][h] == 1) {//n捺
							pointTemp[3]++;
						}
					}
				}
				int bigTemp = pointTemp[0];
				cutDir = 0;
				for (int big = 1; big < 4; big++) {
					if (pointTemp[big] > bigTemp) {
						bigTemp = pointTemp[big];
						cutDir = big;
					}
				}
				switch (cutDir) {
				case 0:
					for (int h = 0; h < 50; h++) {//横
						if (mesh[x][h] == 1) {
							mesh[x][h] = 0;
						}
					}break;
				case 1:
					for (int s = 0; s < 40; s++) {
						if (mesh[s][y] == 1) {
							mesh[s][y] = 0;
						}
					}break;
				case 2:
					for (int s = 0; s < 40; s++) {
						for (int h = 0; h < 50; h++) {
							if ((s + h) == (x + y) && mesh[s][h] == 1) {
								mesh[s][h] = 0;
							}
						}
					}break;
				case 3:
					for (int s = 0; s < 40; s++) {
						for (int h = 0; h < 50; h++) {
							if ((40 + 50 - s + h) == (40 + 50 - x + y) && mesh[s][h] == 1) {
								mesh[s][h] = 0;
							}
						}
					}break;
				default:break;
				}
			}
		}
	}
	cout << time <<endl;
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值