POJ1247-Magnificent meatbils

Source: Internet
Author: User

 

Http://poj.org/problem? Id = 1247

Magnificent meatbils
Time limit:1000 ms   Memory limit:10000 K
Total submissions:6739   Accepted:4471

Description

Sam and Ella run a catering service. they like to put on a show when serving meatbils to guests seated at round tables. they march out of the kitchen with pots of meatbils 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 meatbils. 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 meatbils. 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 have strate 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 meatbils 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 35 3 9 4 2 86 1 2 1 2 1 26 1 2 1 2 1 10

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.

 

In fact, I was not sure about the purpose of the question at the beginning, but after I understood the meaning of the question, it was very simple. The meaning of this question can be simply understood as: There are n numbers on the round table, sam starts from position 1 to n, while Ella goes from N to 1 and asks where they meet to make the numbers at both ends equal; if no equal position is available, no equal partitioning is output.

Now it's much easier.

#include "stdio.h"#include "math.h"#include "string.h"#include "stdlib.h"int main(int argc, char const *argv[]){    int data[35], _i, n, sum, s1, s2;    while(scanf("%d", &n), n){        sum = 0;        for(_i=0; _i<n; _i++){            scanf("%d", &data[_i]);            sum += data[_i];        }        s1 = 0, s2 = sum;        for(_i=0; _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+1, _i+2);        }    }    return 0;}

 

POJ1247-Magnificent meatbils

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.