HDU Image Recognition

//先得把模型抽象出来,找出要统计的,那些不在统计范围内的根据情况的不同,用相应的方法分开
//扫描线->对后面统计有作用的留下 对后面统计没做用的删去
//离线排序 用flag表示产生作用和没作用,然后依次统计
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

const int maxn=1005;
int map[maxn][maxn];
int U[maxn][maxn];
int D[maxn][maxn];
int L[maxn][maxn];
int R[maxn][maxn];
int B[maxn];
struct node{
	int flag;
	int id;
	int x,y;
	bool operator<(const node & t)const {
		if(id!=t.id)
			return id<t.id;
		return flag>t.flag;
	}
}p[maxn<<2];

void init(int n){
	int i,j;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++)
			if(j==0)L[i][j]=(map[i][j]==1);
			else if(map[i][j])
				L[i][j]=L[i][j-1]+1;
			else 
				L[i][j]=0;
		for(j=n-1;j>=0;j--)
			if(j==n-1)R[i][j]=(map[i][j]==1);
			else if(map[i][j])
				R[i][j]=R[i][j+1]+1;
			else
				R[i][j]=0;
	}
	for(j=0;j<n;j++){
		for(i=0;i<n;i++)
			if(i==0)U[i][j]=(map[i][j]==1);
			else if(map[i][j])
				U[i][j]=U[i-1][j]+1;
			else 
				U[i][j]=0;
		for(i=n-1;i>=0;i--)
			if(i==n-1) D[i][j]=(map[i][j]==1);
			else if(map[i][j])
				D[i][j]=D[i+1][j]+1;
			else 
				D[i][j]=0;
	}
}

int sum(int id){
	int ret=0;
	for(int i=id;i>0;i-=(i&(-i)))
		ret+=B[i];
	return ret;
}

void update(int id,int x,int n){
	for(int i=id;i<=n;i+=(i&(-i)))
		B[i]+=x;
}

int Min(int a,int b){
	return a<b?a:b;
}

int main()
{
	int T;
	int n,cnt;
	int i,j,k;
	int x,y;
	scanf("%d",&T);
	for(int cas = 1;cas <= T; cas++ ) {
		scanf("%d",&n);
		for( i =0; i < n; i++) 
			for( j = 0 ; j < n ; j++)
				scanf("%d",&map[i][j]);
		init(n);
		int ans=0;
		for (i=0;i<n;i++){	
			cnt=0;
			for(k=i,j=0;k<n && j<n;k++,j++){
				p[cnt].id=j+1;
				p[cnt].x=k;
				p[cnt].y=j;
				p[cnt++].flag=1;
				p[cnt].id=j+Min(R[k][j],D[k][j]);
				p[cnt].x=k;
				p[cnt].y=j;
				p[cnt++].flag=-1;
			}
			sort(p,p+cnt);
			memset(B,0,sizeof(B));
			for(j=0;j<cnt;j++){
				x=p[j].x;y=p[j].y;
				if(p[j].flag==1){
					update(p[j].y+1,1,n);
					ans+=sum(p[j].y+1)-sum(p[j].y+1-Min(U[x][y],L[x][y]));
				}
				else {
					update(p[j].y+1,-1,n);
				}
			}
		}
		//printf("ans==%d\n",ans);
		for(j=1;j<n;j++){
			cnt=0;
			for(k=j,i=0;k<n && i<n;k++,i++){
					p[cnt].id=i+1;
					p[cnt].x=i;
					p[cnt].y=k;
					p[cnt++].flag=1;
					p[cnt].id=i+Min(R[i][k],D[i][k]);
					p[cnt].x=i;
					p[cnt].y=k;
					p[cnt++].flag=-1;
			}
			sort(p,p+cnt);
			memset(B,0,sizeof(B));
			for(i=0;i<cnt;i++){
				x=p[i].x;y=p[i].y;
				if(p[i].flag==1){
					update(p[i].x+1,1,n);
					ans+=sum(p[i].x+1)-sum(p[i].x+1-Min(U[x][y],L[x][y]));
				}
				else{
					update(p[i].x+1,-1,n);
				}
			}
		}
		printf("Case %d: %d\n",cas,ans);
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Foreword Computational Medical Image Analysis has become a prominent field of research at the intersection of Informatics, Computational Sciences, and Medicine, supported by a vibrant community of researchers working in academics, industry, and clinical centers. During the past few years, Machine Learning methods have brought a revolution to the Computer Vision community, introducing novel efficient solutions to many image analysis problemsthat had long remained unsolved.For this revolution to enter the field of Medical Image Analysis, dedicated methods must be designed which take into account the specificity of medical images. Indeed, medical images capture the anatomy and physiology of patients through the measurements of geometrical, biophysical, and biochemical properties of their living tissues. These images are acquired with algorithms that exploit complex med- ical imaging processes whose principles must be well understood as well as those governing the complex structures and functions of the human body. The book Deep Learning for Medical Image Analysis edited by S. Kevin Zhou, Hayit Greenspan, and Dinggang Shen, top-notch researchers from both academia and industry in designing machine learning methods for medical image analysis, cov- ers state-of-the-art reviews of deep learning approaches for medical image analysis, including medical image detection/recognition, medical image segmentation, medi- cal image registration, computer aided diagnosis and disease quantification, to name some of the most important addressed problems. The book, which starts with an in- troduction to Convolutional Neural Networks for Computer Vision presents a set of novel deep learning methods applied to a variety of clinical problems and imaging modalities operating at various scales, including X-ray radiographies, Magnetic Res- onance Imaging, Computed Tomography, microscopic imaging, ultrasound imaging, etc. This impressive collection of excellent contributions will definitely se
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值