zoj 1402 Magnificent Meatballs

原创 2012年03月23日 23:51:46
#include "iostream"
#include "memory.h"
using namespace std;

int meatballs[40];

int main()
{
	int guestnum, i, j, sum1, sum2;
	while (cin >> guestnum && guestnum)
	{
		memset(meatballs, 0, sizeof(meatballs));
		sum1 = sum2 = 0;
		for (i = 0; i < guestnum; i++)
			cin >> meatballs[i];
		sum1 += meatballs[0];
		sum2 += meatballs[guestnum-1];
		for (i = 1, j = guestnum-2; ;)
		{
			if (i > j)  break;//就是由于这个条件的位置没有放对,WA了几次!考虑不够周全!
			if (sum1 > sum2)
			{
				sum2 += meatballs[j];
				j = j -1;
			}
			else 
			{
				sum1 += meatballs[i];
				i = i + 1;
			}
		}
		if (sum1 == sum2)
			cout << "Sam stops at position " << i << " and Ella stops at position " << i + 1<< "." << endl;
		else
			cout << "No equal partitioning." << endl;
	}
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

zoj1402-------------Magnificent Meatballs

Sam and Ella run a catering service. They like to put on a show when serving meatballs to guests sea...

POJ1247:Magnificent Meatballs

Description Sam and Ella run a catering service. They like to put on a show when serving meatballs ...

poj1247(Magnificent Meatballs)

这个题很简单也没有什么值得注意的trick,所以直接发代码 Magnificent Meatballs Time Limit: 1000MS   Memory Limit: 1...

POJ 1247 Magnificent Meatballs(我的水题之路——数组两边求和)

Magnificent Meatballs Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5...

Magnificent Meatballs

Sam and Ella run a catering service. They like to put on a show when serving meatballs to guests sea...

ZOJ-1402

import java.util.Scanner; public class Main { public static void main(String[] args) { Sc...

From augment attenuated cheeseburgers to crimini augment meatballs

From augment attenuated cheeseburgers to crimini augment meatballs, aggregate was trending at three ...

RdfSnap225_1402_Setup

  • 2015-08-26 09:54
  • 2.92MB
  • 下载

51Nod - 1402 模拟 + 贪心

题意: 一个N长的数组s[](注意这里的数组初始下标设为1,而不是0,即N个元素为s[1],s[2],...,s[N]),满足以下性质: 1)每个元素都是非负的整数,且s[1]=0; ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)