首页 > 代码库 > poj1247 bjfu1239水题
poj1247 bjfu1239水题
其实就是读题啦,读懂题很简单,就是问一个数组,存不存在一个点,按这个点切成两半,这两半的数字的和是一样的。不多说了,上代码
/* * Author : ben */#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <iostream>#include <algorithm>#include <queue>#include <set>#include <map>#include <stack>#include <string>#include <vector>#include <deque>#include <list>#include <functional>#include <numeric>#include <cctype>using namespace std;const int MAXN = 40;int data[MAXN];int sum1[MAXN], sum2[MAXN];int main() { int n, i; while (scanf("%d", &n) == 1 && n > 0) { sum1[0] = 0; for (i = 1; i <= n; i++) { scanf("%d", &data[i]); sum1[i] = sum1[i - 1] + data[i]; } sum2[n] = data[n]; for (i = n - 1; i > 0; i--) { sum2[i] = sum2[i + 1] + data[i]; } for (i = 1; i < n; i++) { if (sum1[i] == sum2[i + 1]) { printf("Sam stops at position %d and Ella stops at position %d.\n", i, i + 1); break; } } if (i == n) { printf("No equal partitioning.\n"); } } return 0;}
poj1247 bjfu1239水题
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。