Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

暴力过的,供参考,求优化

Posted by Fredxiang at 2013-01-28 01:56:20 on Problem 3158
#include<stdio.h>  
#include<string.h>
char bottom[110],top[100];
int mini(int a,int b)
{
	if(a<b)
		return a;
	else
		return b;
}
int main()
{	
	int min,la,lb,i,j,flag,i1,j1;
	
	gets(bottom);
	gets(top);

	la=strlen(bottom);
	lb=strlen(top);
	min=la+lb;

	for(i=0,j=lb-1;i<la;i++)
	{
		flag=1;
		for(i1=i,j1=j; i1>=0 && j1>=0; i1--,j1--)
			if(bottom[i1]-'0'+top[j1]-'0'==4)
			{
				flag=0;
				break;
			}
		if(flag && la+lb-mini(i+1,lb)<min)
			min=la+lb-mini(i+1,lb);	
	}

	
	for(j=0,i=la-1;j<lb;j++)
	{
		flag=1;
		for(i1=i,j1=j; i1>=0 && j1>=0; i1--,j1--)
			if(bottom[i1]-'0'+top[j1]-'0'==4)
			{
				flag=0;
				break;
			}
		if(flag && la+lb-mini(j+1,la)<min)
			min=la+lb-mini(j+1,la);	
	}
	printf("%d\n\n",min);
	
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator