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

看了n遍 老是wa 。。。大家帮忙帮我看看

Posted by windson at 2008-03-27 01:06:50 on Problem 3125
#include <iostream>
#include <memory.h> 
using namespace std;

int main()
{
	int t;
	scanf("%d",&t);
	while (t--)
	{
		int i,n,m,a[101],k=-1,l=-1;
		int p,e1=0,big1=0,e2=0,e3=0,e4=0,big2=0;
		memset(a,0,sizeof(a));
		scanf("%d%d",&n,&m);
		for(i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
		}
		p=a[m];
		for(i=0;i<=m;i++)
		{
			if(a[i]>p)
			{
				big1=big1+1;
				l=i;
			}
			if(a[i]==p) e1=e1+1;
		}
		for(i=m;i<n;i++)
		{
			if(a[i]>p)
			{
				big2=big2+1;
				k=i;
			}
			if(a[i]==p) e2=e2+1;
		}
		if(k>=0){
			for(i=k;i<n;i++)
			{
				if(a[i]==p)
					e3=e3+1;
			}
		}
		if(l>=0){
			for(i=l;i<=m;i++)
			{
				if(a[i]==p)
				{
					e4=e4+1;
				}
			}
		}
		if(big1>0&&big2>0) printf("%d\n",big1+big2+e1+e3);
		if(big1>0&&big2==0) printf("%d\n",big1+e4);
		if(big1==0&&big2==0) printf("%d\n",e1);
		if(big1==0&&big2>0) printf("%d\n",e1+big2+e3);
	}
	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