# 今日头条2017秋招笔试_1

Posted by 111qqz on Thursday, March 30, 2017

## TOC

``````                                    题目描述
``````

a＜= b＜= c
b - a＜= 10
c - b＜= 10

20 35 23 40

div2 A的难度…直接贪就好,不给数据范围的都是耍流氓…

``````/* ***********************************************
Author :111qqz
Created Time :2017年03月30日 星期四 12时55分21秒
File Name :code/toutiao/1.cpp
************************************************ */
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#define fst first
#define sec second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ms(a,x) memset(a,x,sizeof(a))
typedef long long LL;
#define pi pair < int ,int >
#define MP make_pair
using namespace std;
const double eps = 1E-8;
const int dx4[4]={1,0,0,-1};
const int dy4[4]={0,-1,1,0};
const int inf = 0x3f3f3f3f;
int n;
vector<int>vec;
int main()
{
#ifndef  ONLINE_JUDGE
freopen("code/in.txt","r",stdin);
#endif
int ans = 0 ;
cin>>n;
for ( int i = 1 ; i <= n ; i++)
{
int x;
scanf("%d",&x);
vec.push_back(x);
}
sort(vec.begin(),vec.end());
int cur = 0 ;
for ( int i = 0 ;i < n ; i++)
{
if (cur==0)
{
cur++;
continue;
}
if (cur==1)
{
if (vec[i]-vec[i-1]<=10)
{
cur++;
continue;
}
if (vec[i]-vec[i-1]>20)
{
cur+=2;
ans+=2;
cur%=3;
i--;
continue;
}
if (vec[i]-vec[i-1]>10)
{
cur+=2;
cur%=3;
ans++;
}
continue;
}
if (cur==2)
{
if (vec[i]-vec[i-1]<=10)
{
cur++;
cur%=3;
continue;
}
else
{
cur++;
ans++;
i--;
cur%=3;
continue;
}
}
}
if (cur!=0)
ans = ans + 3-cur;
cout<<ans<<endl;
#ifndef ONLINE_JUDGE
fclose(stdin);
#endif
return 0;
}
``````

「真诚赞赏，手留余香」