Sequence II
6990: Sequence II
时间限制: 3 Sec 内存限制: 128 MB
提交: 206 解决: 23
[提交][状态][讨论版][命题人:admin]
题目描述
Given a permutation p of integers from 1 to n. Remove an element from the permutation such that the number of "good" elements is maximized.
输入
For each test case, the first line contains an integer n(1≤ n≤ 10^6), representing the length of the given permutation.
The second line contains n integers p1,p2,\cdots,pn(1≤ pi≤ n), representing the given permutation p.
It’s guaranteed that Σn≤ 2× 10^7.
输出
样例输入
2
1
1
5
5 1 2 3 4
样例输出
1
5
骚的输入操作,用scanf()居然超时!
#include <bits/stdc++.h>
using namespace std;
int scan()
{
int res=0;
char ch;
ch=getchar();
if(ch>='0' && ch<='9')
{
res=ch-'0';
}
while((ch=getchar())>='0' && ch<='9')
{
res=res*10+ch-'0';
}
return res;
}
void out(int a)
{
if(a>9)
{
out(a/10);
}
putchar(a%10+'0');
}
int b[1000100];
int a[1000100];
int main()
{
int t,n,rr,zxz,minn,minnn;
t=scan();
while(t--)
{
memset(b,0,sizeof(b));
n=scan();
if(n==1)
{
a[0]=scan();
out(a[0]);
putchar('\n');
}
if(n==2)
{
a[0]=scan();
a[1]=scan();
out(min(a[0],a[1]));
putchar('\n');
}
if(n>=3)
{
for(int i=0; i<=n-1; i++)
{
a[i]=scan();
if(i==1)
{
minnn=min(a[0],a[1]);
minn=max(a[0],a[1]);
if(a[0]<a[1])
{
b[a[0]]++;
b[a[1]]++;
}
}
else if(i>1)
{
if(a[i]<minnn)
{
minn=minnn;
minnn=a[i];
}
else if(a[i]>minnn && a[i]<minn)
{
b[minnn]++;
b[a[i]]++;
minn=a[i];
}
else if(a[i]>minn)
{
b[a[i]]++;
}
}
}
rr=1e9+7;
zxz=1e9+7;
for(int i=0;i<=n-1;i++)
{
if(b[a[i]]<zxz)
{
zxz=b[a[i]];
rr=a[i];
}
else if(b[a[i]]==zxz && a[i]<rr)
{
rr=a[i];
}
}
out(rr);
putchar('\n');
}
}
return 0;
}
Sequence II的更多相关文章
- HDU 5919 Sequence II 主席树
Sequence II Problem Description Mr. Frog has an integer sequence of length n, which can be denoted ...
- HDU 5919 Sequence II(主席树+逆序思想)
Sequence II Time Limit: 9000/4500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) To ...
- HDOJ 5147 Sequence II 树阵
树阵: 每个号码的前面维修比其数数少,和大量的这后一种数比他的数字 再枚举每一个位置组合一下 Sequence II Time Limit: 5000/2500 MS (Java/Others) ...
- bestcoder#23 1002 Sequence II 树状数组+DP
Sequence II Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 5147 Sequence II 树状数组
Sequence II Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Prob ...
- hdu 5147 Sequence II (树状数组 求逆序数)
题目链接 Sequence II Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- [HDU5919]Sequence II
[HDU5919]Sequence II 试题描述 Mr. Frog has an integer sequence of length n, which can be denoted as a1,a ...
- hdu 5147 Sequence II【树状数组/线段树】
Sequence IITime Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem ...
- HDU 5919 -- Sequence II (主席树)
题意: 给一串数字,每个数字的位置是这个数第一次出现的位置. 每个询问对于序列的一个子区间,设一共有k个不同的数,求第ceil(k/2)个数的位置. 因为强制在线,所以离线乱搞pass掉. 主席树可解 ...
随机推荐
- dual 视图模拟 Oracle
CREATE OR REPLACE VIEW dual ASSELECT NULL::"unknown"WHERE 1 = 1;
- [Swift]LeetCode1078. Bigram 分词 | Occurrences After Bigram
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- 《SQL 进阶教程》case :用一条 SQL 语句进行不同条件的统计
进行不同条件的统计是case表达式的著名用法之一 select name,sum(case when sex = 1 then population else 0 end) as cnt_m,sum( ...
- Kali下安装rar
1.在kali中安装rar解压软件 方法一: apt-get install rar 方法二: 下载RAR:wget https://www.rarlab.com/rar/rarlinux-x64-5 ...
- mycat学习日记:全局sequence
mycat分库分表的情况下,原生mysql的自增长主键无法满足主键全局唯一这个要求.看了MYCAT社区从零开始的一篇博客,加上自己的实践,大概总结一下. 目前mycat对于全局sequence主要提供 ...
- CDH5.7.2离线部署笔记
1.部署基本信息说明: 1.1.主机信息 操作系统:选择CentOS6.7 x86-64版本 MEM:64GB,CPU: E5-2630 v3 @ 2.40GHz, DISK:2TB*4(数据节点存储 ...
- Spark Mllib里如何将如温度、湿度和风速等数值特征字段用除以***进行标准化(图文详解)
不多说,直接上干货! 具体,见 Hadoop+Spark大数据巨量分析与机器学习整合开发实战的第18章 决策树回归分类Bike Sharing数据集
- 使用OAuth保护REST API并使用简单的Angular客户端
1.概述 在本教程中,我们将使用OAuth保护REST API并从简单的Angular客户端使用它. 我们要构建的应用程序将包含四个独立的模块: 授权服务器 资源服务器 UI implicit - 使 ...
- Spring Cloud 熔断器
目录 Spring Cloud 熔断器 Hystrix ribbon中使用hystrix feign中使用hystrix Spring Cloud 熔断器 在微服务架构中,根据业务来拆分成一个个的服务 ...
- Spring MVC 示例
Srping MVC项目结构如下: 一.首先创建一个Dynamic Web Project 二.WebContent/WEB-INF/文件夹下新增 web.xml,配置servlet 容器对于web. ...