http://poj.org/problem?id=1247

Magnificent Meatballs
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 6739   Accepted: 4471

Description

Sam and Ella run a catering service. They like to put on a show when serving meatballs to guests seated at round tables. They march out of the kitchen with pots of meatballs and start serving adjacent guests. Ella goes counterclockwise and Sam goes clockwise, until they both plop down their last meatball, at the same time, again at adjacent guests. This impressive routine can only be accomplished if they can divide the table into two sections, each having the same number of meatballs. You are to write a program to assist them.

At these catering events, each table seats 2 <= N <= 30 guests. Each guest orders at least one and at most nine meatballs. Each place at the table is numbered from 1 to N, with the host at position 1 and the host's spouse at position N. Sam always serves the host first then proceeds to serve guests in increasing order. Ella serves the spouse first, then serves guests in decreasing order. The figures illustrate the first two example input cases. 

Input

Input consists of one or more test cases. Each test case contains the number of guests N followed by meatballs ordered by each guest, from guest 1 to guest N. The end of the input is a line with a single zero. 

Output

For each table, output a single line with the ending positions for Sam and Ella, or the sentence indicating an equal partitioning isn't possible. Use the exact formatting shown below. 

Sample Input

5 9 4 2 8 3
5 3 9 4 2 8
6 1 2 1 2 1 2
6 1 2 1 2 1 1
0

Sample Output

Sam stops at position 2 and Ella stops at position 3.
No equal partitioning.
No equal partitioning.
Sam stops at position 3 and Ella stops at position 4.

  其实刚开始对题目的意思没有把握准,但是把题目的意思理解了之后就非常的简单,这道题的意思可以简单的理解为:圆桌上有N个数字,Sam从1的位置开始往N走,而Ella则从N往1走,问他们哪个相遇的位置能让两端的数字的和相等;如果不论在哪个位置都不能相等的话,那就输出 No equal partitioning.

  好了,现在就简单多了吧。

#include "stdio.h"
#include "math.h"
#include "string.h"
#include "stdlib.h" int main(int argc, char const *argv[])
{
int data[], _i, n, sum, s1, s2; while(scanf("%d", &n), n){
sum = ;
for(_i=; _i<n; _i++){
scanf("%d", &data[_i]);
sum += data[_i];
}
s1 = , s2 = sum;
for(_i=; _i<n; _i++){
s1 += data[_i];
s2 -= data[_i];
if(s1 == s2){
break;
}
}
if(_i>=n){
printf("No equal partitioning.\n");
}else{
printf("Sam stops at position %d and Ella stops at position %d.\n", _i+, _i+);
}
} return ;
}

POJ1247-Magnificent Meatballs的更多相关文章

  1. ZOJ Problem Set - 1402 Magnificent Meatballs

    比较简单的题目,题目大意就是将n个数字围成一个圈,找到一个划分,是的划分左边的数字之和等于右边的数字之和: e.g 10 1 2 2 5,那么可以找到一个划分10 | 1 2 2 5使得两边数字之和都 ...

  2. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  3. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  4. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  5. nevertheless|magnificent |prosperous|

    ADV 然而;不过You use nevertheless when saying something that contrasts with what has just been said. Mos ...

  6. poj1247 bjfu1239水题

    其实就是读题啦,读懂题很简单,就是问一个数组,存不存在一个点,按这个点切成两半,这两半的数字的和是一样的.不多说了,上代码 /* * Author : ben */ #include <cstd ...

  7. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  8. yoman 创建generator

    yoman作为一个模板工具,能够创建自己的模板,下面具体介绍下. 首先 安装一个模板工具(npm install -g generator-generator),此工具会自动创建一些必要的文件.安装完 ...

  9. AssetBundle loading failed because.....已解决

    http://blog.csdn.net/ldghd/article/details/9632455 *****************************      一      ******* ...

随机推荐

  1. 六、Mosquitto 高级应用之SSL/TLS

    mosquitto提供SSL支持加密的网络连接和身份验证.本章节讲述次功能的实现. 在此之前需要一些准备工作. 准本工作: 一台 Linux 服务器. 安装好 openssl (不会明白怎么安装 op ...

  2. CTreeView 的教程

    整个网上搜了一圈没有好的CTreeView 的教程,所以自己谢谢看. CTreeView 是什么? C打头的东西当然是一个类了. 有类就有继承,他的继承关系如下. 有个东西和他比较像 叫CTreeCt ...

  3. Selenium之使用PageFactory初始化pageobject

    使用PageFactory初始化pageobject有什么作用呢,下面举个例子来说明 public BaiduPage baiduPage = PageFactory.initElements(dri ...

  4. java反射之构造方法(三)

    一. 1. 二.获取类的构造方法信息. ######################################################################## 三.

  5. hbase(二)

    一.HBase简介 1.1简介 hbase是bigtable的开源山寨版本.是建立的hdfs之上,提供高可靠性.高性能.列存储.可伸缩.实时读写的数据库系统.它介于nosql和RDBMS之间,仅能通过 ...

  6. 2017 Multi-University Training Contest - Team 4 hdu6069 Counting Divisors

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6069 题目: Counting Divisors Time Limit: 10000/5000 ...

  7. 【转载】IDEA:放置型塔防备忘录

    下周开始做原型了,我需要再次细细的整理一遍设计思路,确保每一个设计都能为了我所追求的玩家体验添砖加瓦,而不是互相打架.同时本文还能提供最原始的VISION,待到将来开发万一陷入泥淖,翻出此文来可以起到 ...

  8. CCTableView

    今天用到TableView, 我就来记录一下....这些都是在网上找到了资料 //首先 继承 : public cocos2d::extension::CCTableViewDelegate,publ ...

  9. testng失败截图,注解方式调用。

    今天一整天都在研究testng失败截图的方法,参考网上的前辈们的资料,加上自己的理解,终于搞出来了. package com.dengnapianhuahai; /** * 自定义注释 * */ im ...

  10. spark程序设计

    Spark程序设计—创建RDD:从Scala集合构造成RDD parallelize(a, 3) makeRDD(a, 3) 他俩使用方式一样,只不过名字不一样 Spark程序设计—创建RDD:本地文 ...