1101. Quick Sort (25)

389 篇文章 1 订阅
140 篇文章 0 订阅

1101. Quick Sort (25)
时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B
判题程序 Standard 作者 CAO, Peng

There is a classical process named partition in the famous quick sort algorithm. In this process we typically choose one element as the pivot. Then the elements less than the pivot are moved to its left and those larger than the pivot to its right. Given N distinct positive integers after a run of partition, could you tell how many elements could be the selected pivot for this partition?
For example, given N = 5 and the numbers 1, 3, 2, 4, and 5. We have:

1 could be the pivot since there is no element to its left and all the elements to its right are larger than it;
3 must not be the pivot since although all the elements to its left are smaller, the number 2 to its right is less than it as well;
2 must not be the pivot since although all the elements to its right are larger, the number 3 to its left is larger than it as well;
and for the similar reason, 4 and 5 could also be the pivot.
Hence in total there are 3 pivot candidates.
Input Specification:
Each input file contains one test case. For each case, the first line gives a positive integer N (<= 105). Then the next line contains N distinct positive integers no larger than 109. The numbers in a line are separated by spaces.
Output Specification:
For each test case, output in the first line the number of pivot candidates. Then in the next line print these candidates in increasing order. There must be exactly 1 space between two adjacent numbers, and no extra space at the end of each line.
Sample Input:
5
1 3 2 4 5
Sample Output:
3
1 4 5

思路:
主元的话一定是 大于其所在位置左边的所有元素的最大值,小于右边所有元素的最小值(不包括本身)

注意点:

  • 最小值右移30位,不能右移31,右移31的话变成了负数
  • 最后一定要加一个换行(可能是特殊数据,没有主元的情况)
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
#include <fstream>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;

const int MaxN = 100010;
const int INF = 1 << 30;

int Data[MaxN] ,LeftMax[MaxN], RightMin[MaxN];
int main()
{
#ifdef _DEBUG
    freopen("data.txt", "r+", stdin);
    //fstream cin("data.txt");
#endif // _DEBUG

    int N;

    queue<int> que;
    scanf("%d", &N);

    LeftMax[0] = 0;
    RightMin[N - 1] = INF;

    for (int i = 0; i < N; ++i)
        scanf("%d", &Data[i]);

    for (int i = 1; i < N; ++i)
    {
        LeftMax[i] = max(LeftMax[i - 1], Data[i - 1]);
    }

    for (int i = N - 2; i >= 0; --i)
    {
        RightMin[i] = min(RightMin[i + 1], Data[i + 1]);
    }

    for (int i = 0; i < N; ++i)
    {
        if (LeftMax[i] <= Data[i] && Data[i] <= RightMin[i])
            que.push(Data[i]);
    }

    printf("%d\n", que.size());

    while (!que.empty())
    {
        printf("%d", que.front());
        que.pop();
        if (!que.empty())
            printf(" ");
    }
    printf("\n");


#ifdef _DEBUG
    //cin.close();
#ifndef _CODEBLOCKS
    std::system("pause");
#endif // !_CODEBLOCKS
#endif // _DEBUG

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕业设计,基于SpringBoot+Vue+MySQL开发的海滨体育馆管理系统,源码+数据库+毕业论文+视频演示 本基于Spring Boot的海滨体育馆管理系统设计目标是实现海滨体育馆的信息化管理,提高管理效率,使得海滨体育馆管理工作规范化、高效化。 本文重点阐述了海滨体育馆管理系统的开发过程,以实际运用为开发背景,基于Spring Boot框架,运用了Java技术和MySQL作为系统数据库进行开发,充分保证系统的安全性和稳定性。本系统界面良好,操作简单方便,通过系统概述、系统分析、系统设计、数据库设计、系统测试这几个部分,详细的说明了系统的开发过程,最后并对整个开发过程进行了总结,实现了海滨体育馆相关信息管理的重要功能。 本系统的使用使管理人员从繁重的工作中解脱出来,实现无纸化办公,能够有效的提高海滨体育馆管理效率。 关键词:海滨体育馆管理,Java技术,MySQL数据库,Spring Boot框架 本基于Spring Boot的海滨体育馆管理系统主要实现了管理员功能模块和学生功能模块两大部分,这两大功能模块分别实现的功能如下: (1)管理员功能模块 管理员登录后可对系统进行全面管理操作,包括个人中心、学生管理、器材管理、器材借出管理、器材归还管理、器材分类管理、校队签到管理、进入登记管理、离开登记管理、活动预约管理、灯光保修管理、体育论坛以及系统管理。 (2)学生功能模块 学生在系统前台可查看系统信息,包括首页、器材、体育论坛以及体育资讯等,没有账号的学生可进行注册操作,注册登录后主要功能模块包括个人中心、器材管理、器材借出管理、器材归还管理、校队签到管理、进入登记管理、离开登记管理、活动预约管理。
毕业设计,基于SpringBoot+Vue+MySQL开发的学科竞赛管理系统,源码+数据库+毕业论文+视频演示 随着国家教育体制的改革,全国各地举办的竞赛活动数目也是逐年增加,面对如此大的数目的竞赛信息,传统竞赛管理方式已经无法满足需求,为了提高效率,竞赛管理系统应运而生。 本学科竞赛管理系统以实际运用为开发背景,基于Spring Boot框架、Vue框架,运用了Java语言和MySQL数据库进行开发设计,充分保证系统的安全性和稳定性。本系统界面良好,操作简单方便,通过系统概述、系统分析、系统设计、数据库设计、系统测试这几个部分,详细的说明了系统的开发过程,最后并对整个开发过程进行了总结,实现了学科竞赛管理的重要功能。 本学科竞赛管理系统运行效果稳定,操作方便、快捷,界面友好,是一个功能全面、实用性好、安全性高,并具有良好的可扩展性、可维护性的学科竞赛管理平台。 关键词:学科竞赛管理,Java语言,MySQL数据库,Vue框架 此学科竞赛管理系统的设计与实现功能分析主要分为管理员功能模块和学生功能模块两大模块,下面详细介绍这两大模块的主要功能: (1)管理员:管理员登陆后可对系统进行全面管理,管理员主要功能模块包括个人中心、学生管理、教师管理、赛项信息管理、赛项报名管理、奖项统计管理、管理员管理以及系统管理,管理员实现了对系统信息的查看、添加、修改和删除的功能。 (2)学生:学生进入本学科竞赛管理系统的设计与实现前台可查看系统信息,包括首页、赛项信息以及新闻资讯等,注册登录后主要功能模块包括个人中心和赛项报名管理。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值