B2761 [JLOI2011]不重复数字 离散化
就是一道离散化的裸题,但是在写的时候遇到了一些不可描述的问题,但是还是很顺利的。
题干:
Description
给出N个数,要求把其中重复的去掉,只保留第一次出现的数。
例如,给出的数为1 ,其中2和3有重复,去除后的结果为1 。
Input
输入第一行为正整数T,表示有T组数据。
接下来每组数据包括两行,第一行为正整数N,表示有N个数。第二行为要去重的N个正整数。
Output
对于每组数据,输出一行,为去重后剩下的数字,数字之间用一个空格隔开。
Sample Input Sample Output HINT
对于30%的数据, <= N <= ,给出的数不大于100,均为非负整数;
对于50%的数据, <= N <= ,给出的数不大于10000,均为非负整数;
对于100%的数据, <= N <= ,给出的数在32位有符号整数范围内。
提示:
由于数据量很大,使用C++的同学请使用scanf和printf来进行输入输出操作,以免浪费不必要的时间。
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
#define duke(i,a,n) for(int i = a;i <= n;i++)
#define lv(i,a,n) for(int i = a;i >= n;i--)
#define clean(a) memset(a,0,sizeof(a))
const int INF = << ;
typedef long long ll;
typedef double db;
template <class T>
void read(T &x)
{
char c;
bool op = ;
while(c = getchar(), c < '' || c > '')
if(c == '-') op = ;
x = c - '';
while(c = getchar(), c >= '' && c <= '')
x = x * + c - '';
if(op) x = -x;
}
template <class T>
void write(T x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar('' + x % );
}
struct node
{
ll v,id;
bool operator == (const node other) const
{
return v == other.v;
}
bool operator < (const node other) const
{
if(v != other.v)
return v < other.v;
else
return id < other.id;
}
}a[];
int n;
bool cmp(node a,node b)
{
return a.id < b.id;
}
int main()
{
int t;
read(t);
while(t--)
{
read(n);
duke(i,,n)
{
read(a[i].v);
a[i].id = i;
}
sort(a + ,a + n + );
int k = unique(a + ,a + n + ) - a - ;
sort(a + ,a + k + ,cmp);
duke(i,,k)
printf("%lld ",a[i].v);
printf("\n");
}
return ;
}
B2761 [JLOI2011]不重复数字 离散化的更多相关文章
- [BZOJ2761][JLOI2011]不重复数字
[BZOJ2761][JLOI2011]不重复数字 试题描述 给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复 ...
- BZOJ 2761: [JLOI2011]不重复数字 水题
2761: [JLOI2011]不重复数字 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2100 Solved: 809 题目连接 http:// ...
- bzoj 2761 [JLOI2011]不重复数字(哈希表)
2761: [JLOI2011]不重复数字 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3210 Solved: 1186[Submit][Sta ...
- 2761: [JLOI2011]不重复数字(平衡树)
2761: [JLOI2011]不重复数字 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2133 Solved: 825[Submit][Stat ...
- 2761: [JLOI2011]不重复数字(哈希表)
2761: [JLOI2011]不重复数字 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1770 Solved: 675[Submit][Stat ...
- 题解 P4305 【[JLOI2011]不重复数字】
来一波用vector的最短代码题解 P4305 [JLOI2011]不重复数字 关于hash表的部分大家可以看一看其他的题解,我就不说了 不定长数组vector的几个基本用法: 定义: vector& ...
- [BZOJ2761] [JLOI2011] 不重复数字 (C++ STL - set)
不重复数字 题目: 给出N个数,要求把其中重复的去掉,只保留第一次出现的数.例如,给出的数 为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 1 ...
- 【BZOJ】2761: [JLOI2011]不重复数字(set+巨水题+超坑题)
http://www.lydsy.com/JudgeOnline/problem.php?id=2761 太水了,不说了. 但是这格式错误我已经没话说了....行末不能有空格 #include < ...
- 【bzoj2761】[JLOI2011]不重复数字
给出N个数,要求把其中重复的去掉,只保留第一次出现的数. 例如,给出的数为1 2 18 3 3 19 2 3 6 5 4,其中2和3有重复,去除后的结果为1 2 18 3 19 6 5 4. Inpu ...
随机推荐
- 05C语言数组
C语言数组 一维数组 类型符 数组名[常量表达式] #include <stdio.h> int main(){ ] = {,,,}; int a; ;a<;a++){ printf ...
- 深入分析同步工具类之AbstractQueuedSynchronizer
概览: AQS(简称)依赖内部维护的一个FIFO(先进先出)队列,可以很好的实现阻塞.同步:volatile修饰的属性state,哪个线程先改变这个状态值,那么这个线程就获得了优先权,可以做任何事 ...
- ubuntu环境搭建DNS服务器
1 安装bind9 apt install bind9 2 修改 named.conf.local,添加要解析的域名及对应的域名配置文件 zone "test.cn"{ type ...
- Jenkins 的插件AnsiColor 多颜色
- Wind rotor states
test test Table of Contents 1. Wind rotor states 1.1. Turbulent Wake State 1.2. Vortex Ring State 1. ...
- 算(tyvjP4700)
背景 zhx和他的妹子出去玩. 描述
- golang中channels的本质详解,经典!
原文:https://www.goinggo.net/2014/02/the-nature-of-channels-in-go.html The Nature Of Channels In Go 这篇 ...
- POJ 1260-Pearls(DP)
Pearls Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7465 Accepted: 3695 Descriptio ...
- Oracle 简单的列转行
需求是,统计每一个部门不同工种的薪水总和. SQL> select deptno,ename,job,sal from emp; DEPTNO ENAME JOB ...
- [LeetCode][Java] 4Sum
题目: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = ...