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;
}

全部评论

相关推荐

09-23 14:45
贵州大学 财务
你真的不如他呢:才四家,四十家再说吧
点赞 评论 收藏
分享
敢逐云霄志:你打招呼语怎么能这么长,hr都没看下去的欲望,简明扼要说重点,就读于某某学校某某专业,26届应届毕业生,学信网可查,先后在某某公司实习过(如有),然后做过什么项目,想找一份什么样的工作,可实习几个月以上,期待您的回复。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务