sdnu 1427 来一个小暴力加预处理数组就好了

1487.Problem_E

Time Limit: 1000 MS    Memory Limit: 32768 KB
Total Submission(s): 38    Accepted Submission(s): 12

Description

Woniuxia is preparing for internship. So he is bound to take a written examination and an interview. But as we all know,his level is too low. Look! The written test question stumped him again. Fortunately you couldn't stand idly by when you are beside him. Would you please to help him solve the problem as follows?

Give you a set of data,please delete three numbers among them,which can make the rest of the data is divided into four sections and the sum of each section is equal.

If it is possible,output the three deleted numbers' position in the array.

If not,output "I am done."

Input

The first line is an integer n(1 <= n <= 1000), indicating the number of the sequence.

The next line contain ai the n number (pending sequence). (0<=ai<=100000)

Output

Print the result, the three position of delete the number or “I am done.”.

Sample Input

71 1 1 1 1 1 1

Sample Output

2 4 6

Source

Unknown

                这道题的话,就是给你一堆数~~然后让取3个数字~让剩余的4个部分的和相等;

                我们可以先建立一个sum数组,表示前n个数的和是多少~~因为这个有大量的数据的区间查询。然后接一个暴力就好了~~我加了一个优先队列纯属无聊。。。。

#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<queue>
#include<functional>
using namespace std;
int m[1005];
long long int sum[1005] = { 0 };
int main()
{
	int n;
	scanf("%d", &n);
	for (int s = 1; s <= n; s++)
	{
		scanf("%d", &m[s]);
		sum[s] = sum[s - 1] + m[s];
	}
	priority_queue<int, vector<int>, greater<int> >ans;
	int spot = 0;
	for (int s = 1; s <= n; s++)
	{
		spot=0;
		int q;
		for ( q = 1; q <= s - 1; q++)
		{
			if (2 * sum[q - 1] == sum[s - 1] - m[q]&&sum[q-1]!=0)
			{
				spot++;
				break;
			}
		}
		int p;
		for ( p = s + 1; p <= n; p++)
		{
			if (2 * (sum[p - 1] - sum[s]) == sum[n] - sum[s] - m[p]&& sum[p - 1] - sum[s]==sum[q-1])
			{
				spot++;
				break;
			}
		}
		//cout << spot << endl;
		if (spot == 2)
		{
			ans.push(s);
			ans.push(p);
			ans.push(q);
			break;
		}
	}
	if (!ans.empty())
	{
		int t = ans.top();
		ans.pop();
		printf("%d", t);
		while (!ans.empty())
		{
			printf(" %d", ans.top());
			ans.pop();
		}
		cout << endl;
	}
	else
	{
		printf("I am done.\n");
	}
	return 0;
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值