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...
  • zzukun
  • zzukun
  • 2012年08月03日 20:44
  • 217

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...
  • xhldtc
  • xhldtc
  • 2013年12月16日 11:23
  • 266

From augment attenuated cheeseburgers to crimini augment meatballs

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

洛谷 P1402 酒店之王

dinic
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:zoj 1402 Magnificent Meatballs
举报原因:
原因补充:

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