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

全部评论

相关推荐

头像 会员标识
04-07 22:36
已编辑
南京邮电大学 Java
点赞 评论 收藏
分享
Beeee0927:正确的建议
点赞 评论 收藏
分享
双飞二本嵌入式求拷打我是在&nbsp;BOSS&nbsp;上投递的简历,好多都没人回复,这是开场白和简历求大神帮忙看看。您好!我是2025届应届生,最快可在一周内上岗,能够实习六个月以上,并接受加班。以下是我的核心优势和相关经验:1.&nbsp;嵌入式开发能力:&nbsp;&nbsp;&nbsp;熟练掌握STM32系列单片机及其外设(如GPIO、定时器、ADC、DAC、I2C、SPI、UART等),能够独立完成硬件驱动开发和调试。&nbsp;&nbsp;熟悉FreeRTOS实时操作系统,具备多任务调度和资源管理经验。&nbsp;&nbsp;熟悉LVGL图形库开发,能够实现嵌入式设备的图形界面设计。2.&nbsp;硬件设计能力:&nbsp;&nbsp;&nbsp;具备PCB设计经验,曾为2023年工创赛物流搬运赛道设计小车主板,带领团队获得国家级银奖。&nbsp;&nbsp;&nbsp;熟悉硬件原理图分析,能够快速理解并调试硬件电路。3.&nbsp;机器人开发与竞赛经验:&nbsp;&nbsp;&nbsp;在全国大学生智能车竞赛、ROS机器人竞赛中多次获得国家级奖项,具备丰富的机器人开发经验。&nbsp;&nbsp;&nbsp;熟悉Linux环境,对ROS和ROS&nbsp;2有一定了解,能够进行机器人系统的开发与调试。4.&nbsp;编程能力:&nbsp;&nbsp;&nbsp;熟悉C/C++,熟悉Python,能够高效完成嵌入式开发和算法实现。&nbsp;&nbsp;&nbsp;具备良好的代码规范和文档编写能力。5.&nbsp;团队协作与领导能力:&nbsp;&nbsp;&nbsp;在多个项目中担任核心开发或团队负责人,具备良好的沟通能力和团队协作精神。&nbsp;&nbsp;&nbsp;在工创赛中带领团队完成项目规划、任务分配和技术攻关,展现了较强的领导力。我对嵌入式开发、机器人技术和智能硬件充满热情,期待加入贵公司,与团队共同成长,为公司创造价值!如果有合适的岗位,欢迎随时联系我,期待进一步沟通!
沉淀一会:嵌入式就是狗屎
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务