poj 1247 Magnificent Meatballs

简介:

这道题主要就是先理解题意就成功了一大半。。。很水的题目

题意:就是求当两个人按顺时针方向和按逆时针方向放置肉丸子后,当两个人肉丸子相等时所处的位置。

按以下顺序考虑:

1.如果肉丸的总数是奇数,那就不用往下考虑了,一定不行

2.把总数除以2,然后从host(N=1)开始sum-=seat【i】,一旦sum==0,证明成功;小于0,失败;否则就继续循环。。。

一个很简单的数学问题,我看到网上有写O(n^2)的代码的,不知道怎么考虑的。。。


AC的代码:

#include <stdio.h>

int main()
{
	int n;
	int seat[35];
	int i;
	while(scanf("%d",&n))
	{
		if(n==0)
			return 0;

		int sum=0;
		for(i=1;i<=n;i++)
		{
			scanf("%d",&seat[i]);
			sum+=seat[i];
		}

		if(sum%2)  
        {
			printf("No equal partitioning.\n");
            continue;
        }

		else
			sum/=2;

		for(i=1; ;i++)
		{
			sum-=seat[i];

			if(sum==0)
            {
                printf("Sam stops at position %d and Ella stops at position %d.\n",i,i+1);
                break;  
            }

            else if(sum<0)
            {
                    printf("No equal partitioning.\n");
                    break;
            }
		}
	}

	return 0;
}


相关文章
POJ 2027 No Brainer
POJ 2027 No Brainer
111 0
POJ 1012 Joseph
Joseph Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 53862   Accepted: 20551 Description The Joseph's problem is notoriously known.
843 0
|
测试技术
POJ 1001
此题用最朴素的思路实现即可,需模拟加法器,乘法器,最烦人的地方是特殊情形,如末位是小数点(12.^2=144,取小数点),整数末位是0(100^2=10000),0次幂,测试用例可能超出题目中说的范围,可能包含0次幂(100.0^0=0, 0.10^1=0.1)。
752 0
|
C语言
poj 2503 查字典
Description You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language.
866 0
|
并行计算 网络架构
poj-1005-l tanink i need a houseboat
Description Fred Mapper is considering purchasing some land in Louisiana to build his house on. In the process of investigating the land, he learned ...
986 0
|
机器学习/深度学习 算法