Skip to main content
  1. Posts/

whust 2016 warm up ||codeforces 682 B. Alyona and Mex (离散化)

·1 min
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

cf682B题目链接

题意:给出n个数。。每个数可以任意减小到一个正整数。。。问进行恰当的操作后。。。最小的没有出现的正整数的最大可能取值。。

思路:傻逼题。。。直接离散化。。。。注意不能超过初始。。。

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年07月18日 星期一 12时43分41秒
 4File Name :code/2016whus/B.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33const int N=1E5+7;
34int b[N];
35int a[N];
36int n;
37int main()
38{
39	#ifndef  ONLINE_JUDGE
40	freopen("code/in.txt","r",stdin);
41  #endif
42
43	cin>>n;
44	ms(a,0);
45	for ( int i = 1 ; i <= n ; i++) scanf("%d",&a[i]);
46	sort(a+1,a+n+1);
47	int cnt = 0 ;
48	for ( int i = 1 ; i <= n ; i++)
49	{
50	    if (cnt+1<=a[i]) cnt++;
51	    b[i] = cnt;
52	}
53
54
55//	for ( int i = 1 ; i <= n ; i++) cout<<b[i]<<endl;
56	cout<<b[n]+1<<endl;
57  #ifndef ONLINE_JUDGE
58  fclose(stdin);
59  #endif
60    return 0;
61}

Related

uva 120 Stacks of Flapjacks

·2 mins
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid;=8&page;=show_problem&problem;=56 题意:给出一个长度为n的序列(无重复元素),询问经过多少次flip(i)操作,使得序列升序排列。定义flip(i)为将1到n-i+1的元素反转… 思路:先离散化,然后注意读入….

codeforces 29 C. Mail Stamps

http://codeforces.com/contest/29/problem/C 题意:给出n个边的关系,保证可以构成一条链。正向或者反向输出这个链。 思路:由于下标很大(1E9),而关系个数只有1E5..需要离散化。。而且离散化的同时不能丢失边的关系。。。实际上。。直接用vector+map就好了。。。 map >e;即可。然后找到一个度为1的点。。做个dfs…