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 ***************************** 一 ******* ...
随机推荐
- springboot跨域处理
/** * @author 657642432@qq.com * 跨域处理 */ @Configuration public class CorsConfig { @Bean public Filte ...
- 深入浅出java IO模型
一.同步和异步 同步:一个事件或者任务的执行,会使整个流程暂时等待,也就是说如果有多个任务要执行,必须要逐个进行. 异步:一个事件或者任务的执行,不会使整个流程暂时等待,也就是说如果有多个任务要执行, ...
- redis的客户端medis
medis是用js写的redis客户端工具,界面很好用,也很有用.点击这里可以下载到mac下的软件包. 下面是截图: 完结.
- R中遇到的部分问题
在Rstdio使用的是3.5.1的64位R版本中遇到问题:The Perl script 'WriteXLS.pl' failed to run successfully. 首先使用 Sys.whic ...
- Zookeeper概述和基本概念
一.Zookeeper背景 随着互联网技术的发展,企业对计算机系统的计算,存储能力要求越来越高,各大IT企业都在追求高并发,海量存储的极致,在这样的背景下,单纯依靠少量高性能单机来完成计算机,云计算的 ...
- yii2美化url
http://blog.csdn.net/xundh/article/details/45418265
- SQL Server OBJECTPROPERTY使用方法
OBJECTPROPERTY 返回有关当前数据库中的模式作用域对象的信息.此函数不能用于不是模式范围的对象,例如数据定义语言(DDL)触发器和事件通知. OBJECTPROPERTY 语法: OBJE ...
- php注册审查
思路 用户注册后就有该条用户记录,你对用户表设一个“审核状态”字段,默认值设为“未审核”,然后你写几句审核代码做成一个功能,按照你们的意愿若审核通过你把审核状态改为“已审核”就行了.用户想进行各种操作 ...
- es6函数模块-------初步学习
初步学习: 函数参数允许尾逗号 function clownsEverywhere( param1, param2, //param2后面有逗号 ) { } 函数参数可以赋初值 利用解构赋值默认值结合 ...
- Gym - 101875I I Will Go (dfs序)
题意:N个人要参加一个局,每个人有自己的好朋友,如果他的好朋友来,他才有可能来.N个人的关系不够成环.Q次查询,问若x来了,y是否肯定来. 分析:若点y是x的祖先,则y肯定回来.一次dfs确定每个点覆 ...