POJ1247-Magnificent Meatballs
http://poj.org/problem?id=1247
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 6739 | Accepted: 4471 |
Description
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
Output
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的更多相关文章
- ZOJ Problem Set - 1402 Magnificent Meatballs
比较简单的题目,题目大意就是将n个数字围成一个圈,找到一个划分,是的划分左边的数字之和等于右边的数字之和: e.g 10 1 2 2 5,那么可以找到一个划分10 | 1 2 2 5使得两边数字之和都 ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- nevertheless|magnificent |prosperous|
ADV 然而;不过You use nevertheless when saying something that contrasts with what has just been said. Mos ...
- poj1247 bjfu1239水题
其实就是读题啦,读懂题很简单,就是问一个数组,存不存在一个点,按这个点切成两半,这两半的数字的和是一样的.不多说了,上代码 /* * Author : ben */ #include <cstd ...
- 2016ACM青岛区域赛题解
A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- yoman 创建generator
yoman作为一个模板工具,能够创建自己的模板,下面具体介绍下. 首先 安装一个模板工具(npm install -g generator-generator),此工具会自动创建一些必要的文件.安装完 ...
- AssetBundle loading failed because.....已解决
http://blog.csdn.net/ldghd/article/details/9632455 ***************************** 一 ******* ...
随机推荐
- socketserver 并发连接
socketserver.TCPServer Example server side 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ...
- centos7编译安装Python3.6(与2.7并存)
首先去官网下载python3.6 https://www.python.org/ 环境准备:#yum install openssl-devel bzip2-devel expat-devel gdb ...
- OS X 10.9 Mavericks下如何安装Command Line Tools(命令行工具)
OS X 10.9 Mavericks下如何安装Command Line Tools(命令行工具) 今天OS X 10.9 Mavericks正式发布,免费更新,立即去更新看看效果. 不过升级后安装命 ...
- 安装mysql8.0.11以及修改root密码、连接navicat for mysql。
最近在学习node.js,少不得要跟数据库打交道,于是打算安装一个数据库软件,在mongedb和mysql之间选择了mysql.作为一个数据库新人不敢评论孰好孰坏,最后选择mysql纯属因为公司在用m ...
- PKU 2082 Terrible Sets(单调栈)
题目大意:原题链接 一排紧密相连的矩形,求能构成的最大矩形面积. 为了防止栈为空,所以提前加入元素(0,0). #include<cstdio> #include<stack> ...
- Android如何定制一个下拉刷新,上滑加载更多的容器
前言 下拉刷新和上滑加载更多,是一种比较常用的列表数据交互方式. android提供了原生的下拉刷新容器 SwipeRefreshLayout,可惜样式不能定制. 于是打算自己实现一个专用的.但是下拉 ...
- C++ char float int string 之间的转换
string str = "123"; string 转 int int i = atoi( str.c_str() ); string 转 float float f = ato ...
- netty7---自定义序列化接口
package com.cn.core; import java.nio.ByteOrder; import java.nio.charset.Charset; import java.util.Ar ...
- 【c++ primer, 5e】【try语句块】
p172~p177:c++的try语句块和异常处理: 1.通常,与用户交互的代码和对象相加(底层的代码)是分离开的,异常由与用户交互的代码处理(底层代码抛出异常就可以了). 2.C++的runtime ...
- python error: curl: (1) Protocol "'https" not supported or disabled in libcurl
python 调用curl访问一个网页时,出现error: curl: (1) Protocol "'https" not supported or disabled in lib ...