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 ***************************** 一 ******* ...
随机推荐
- OCR技术浅探: 语言模型和综合评估(4)
语言模型 由于图像质量等原因,性能再好的识别模型,都会有识别错误的可能性,为了减少识别错误率,可以将识别问题跟统计语言模型结合起来,通过动态规划的方法给出最优的识别结果.这是改进OCR识别效果的重要方 ...
- Apache Spark 2.0三种API的传说:RDD、DataFrame和Dataset
Apache Spark吸引广大社区开发者的一个重要原因是:Apache Spark提供极其简单.易用的APIs,支持跨多种语言(比如:Scala.Java.Python和R)来操作大数据. 本文主要 ...
- 生信-RPKM与FPKM学习[转载]
转自:https://baike.baidu.com/item/RPKM/1197657 均反应基因的表达水平 1.RPKM的计算公式 分母是总共比对到这个基因的reads的数目(条 为单位),分母是 ...
- Leetcode 236
思路:1.如果p或q就是根节点,那么LCA=p或q,返回根节点(递归出口) 2.分治 2.1 Divide:分别计算左字树和右子树的LCA 2.2 Conquer:如果左字树和右子树的计算结果均不为空 ...
- CCF 炉石传说(模拟)
试题编号: 201612-3 试题名称: 炉石传说 时间限制: 1.0s 内存限制: 256.0MB 问题描述 <炉石传说:魔兽英雄传>(Hearthstone: Heroes of Wa ...
- git 常用命令行操作
git常用命令行操作: 点击 git bash 进入到命令行: git clone https://github.com/wlz1244/qingoo.git //下载一个master分支代码 g ...
- 在python3下使用OpenCV做离散余弦变换DCT及其反变换IDCT
对图像处理经常用到DCT, Python下有很多带有DCT算法包, 这里使用OpenCV的DCT做变换, 并简单置0部分数据, 再查看反变换图像的效果. import numpy as np impo ...
- 一道C++练习题,替换一个字符串里所有实例
做了一道C++练习题,替换一个字符串里面的所有实例. #include <iostream> #include <string> using namespace std; co ...
- nfs挂载
安装: yum install nfs-utils rpcbind 配置共享目录:vim /etc/exports /xxx/cloudcms *(insecure,rw,async,no_root_ ...
- 20145240《网络对抗》MSF基础应用
MSF基础应用 一个主动攻击,如ms08_067 启动msf search ms08_067,查找相应的漏洞,查询可攻击的模块. 根据上述漏洞的模块use exploit/windows/smb/ms ...