I People Counting

当时没想到,现在感觉思路打开就好了

思路:每次遇到一个部分就把身体其他部分一起变为一个不可能的符号并cnt++. 根据这个把相片从头到尾全部扫一遍就好。

#include<iostream>
#include<cstring>
using namespace std;
int H,W,cnt;
char photo[105][105];
const char m[3][4]={{"-O-"},{"/|\\"},{"(-)"}}; //记录完整人的样子;
void change(int i,int j);
void print();
void count(int i,int j)
{
	if(photo[i][j]=='.') return ;
	else if(photo[i][j]=='O') change(i,j-1),cnt++;
	else if(photo[i][j]=='/') change(i-1,j),cnt++;
	else if(photo[i][j]=='|') change(i-1,j-1),cnt++;
	else if(photo[i][j]=='\\') change(i-1,j-2),cnt++;
	else if(photo[i][j]=='(') change(i-2,j),cnt++;
	else if(photo[i][j]==')') change(i-2,j-2),cnt++;
//	print();
}
void change(int i,int j)
{
	for(int a=0;a<3;a++)
	for(int b=0;b<3;b++)
	if(i+a>=0&&i+a<H&&j+b>=0&&j+b<W&&m[a][b]==photo[i+a][j+b]) //一样就变为'.'
	photo[i+a][j+b]='.';
}
int main()
{
	int k;
	cin>>k;
	while(k--)
	{
		cin>>H>>W;
		memset(photo,0,sizeof(photo));
		for(int i=0;i<H;i++)
		for(int j=0;j<W;j++)
		cin>>photo[i][j];
		cnt=0;
		for(int i=0;i<H;i++)  //从头到尾遍历一遍;
		for(int j=0;j<W;j++)
		count(i,j);
		cout<<cnt;
		if(k) cout<<endl;
	}
	return 0;
} 
void print()
{
	for(int i=0;i<H;i++)
	{
		for(int j=0;j<W;j++)
		cout<<photo[i][j];
		cout<<endl;
	}
	cout<<endl;
}










  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值