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 ...
随机推荐
- phpExcel导出excel打不开问题
用wps和office都打不开,使用旧版的office打开了 出现了一些 warming警告,虽然warming不影响函数的执行,但是php导出excel文件,是header出来的.这个warning ...
- [转载] kprobe原理解析(一)
From: https://www.cnblogs.com/honpey/p/4575928.html kprobe原理解析(一) kprobe是linux内核的一个重要特性,是一个轻量级的内核调试工 ...
- static private 与 final 的用法总结
1.static表示静态.他是属于类的.可以在本身类里直接调用,或在其它类里用类名.方法名调用.不加static表示是实例的方法,必须用实例来调用.在本类里也一样,必须用实例调用 2.private是 ...
- Mozilla新特性只支持https网站
Mozilla的官方博客2015.4.30正式宣布了淘汰HTTP的方案. 其中包括:设定一个日期,所有的新特性将只提供给HTTPS网站:HTTP网站将逐步被禁止访问浏览器功能,尤其是那些与用户安全和隐 ...
- Intellij IDEA神器居然还有这些小技巧---超级好用的
Intellij IDEA神器居然还有这些小技巧----https://my.oschina.net/samgege/blog/1808622?p=8
- Codeforces Round #234 (Div. 2)
A. Inna and Choose Options time limit per test 1 second memory limit per test 256 megabytes input st ...
- 转载 - C++ - placement new
出处:http://www.cnblogs.com/wanghetao/archive/2011/11/21/2257403.html 有关placement new ...
- python中实现将普通字典dict转换为java中的treeMap
上代码: from heapq import heappush,heappop from collections import OrderedDict def toTreeMap(paramMap): ...
- rest frame work纪念版代码
models.py from django.db import models from pygments.lexers import get_all_lexers from pygments.styl ...
- org.apache.maven.archiver.MavenArchiver.getManifest(org.apache.maven.project.MavenProject, org.apach
https://www.cnblogs.com/wxymg/p/8630471.html