POJ 1247 Magnificent Meatballs

原题链接:http://acm.pku.edu.cn/JudgeOnline/problem?id=1247

版权声明版权归作者WeiSteven所有,转载请注明! 

本题是讲两个人,负责对围坐在圆桌周围的所有guests进行分发Meatballs。

每个座位上的人需要的不同,请问能否建立一个分割点,使得两人负责的Meatballs的数量一样。

简单的一道题:

AC的参考代码:

代码
 1 #include <stdio.h>
 2 int N[31];//最多有31个guests
 3 
 4 void doData(int n)
 5 {
 6     int i=0,j=n-1;
 7     int sumA=N[0];
 8     int sumB=N[n-1];
 9     while(i!=j-1)
10     {
11         if(sumA<sumB)
12         {
13             i++;
14             sumA+=N[i];
15         }
16         else
17         {
18             j--;
19             sumB+=N[j];
20         }
21     }
22     if(sumA==sumB)
23         printf("Sam stops at position %d and Ella stops at position %d.\n",i+1,j+1);
24     else
25         printf("No equal partitioning.\n");
26 }
27 int main()
28 {
29     freopen("in.txt","r",stdin);
30     int n;
31     while(scanf("%d",&n)!=EOF&&n!=0)
32     {
33         for(int i=0;i<n;i++)
34         {
35             scanf("%d",&N[i]);
36         }
37         doData(n);
38     }
39     return 1;
40 }
原文地址:https://www.cnblogs.com/weisteve/p/1798537.html