(File IO): input: card.in output: card.out
time limit: 1000 ms space constraints: 262144 KB specific restrictions
Goto ProblemSet
Title Description
is very much like a card cows, though she did not thumb, but she has a near-obsession with the love of playing cards. Unfortunately, other cattle in the herd are not good opponent. Their level is really bad. They are always in a completely predictable manner to play cards! despite this,
still can choose how to win.
and her friend Elsie playing a simple card game, they have got to pay a
cards cards, digital numbers on the card is
, and are divided into two, to a card
and a card to
.
Then they began to play cards, a total of conduct
wheel, in each round,
和
are playing a card, the cards who have a big points.
magical
can be predicted
cards sequence, and the like as in winning. please confirm
the maximum number of points can be earned.
Enter
the first line an integer
.
The next
line is
to round out the continuous game cards. Please note that it is easy to determine from the information
card.
Output
line is given
can score the maximum number of points.
Sample input
. 3
. 1
. 6
. 4
Sample Output
2
Data range limit
Tip
Bessie hands of cards are
, according to her
sequential 2 points cards can be obtained.
Problem-solving ideas
greedy.
Prepare two orderly queues, with the principle of Tian Ji's horse.
Code
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cmath>
using namespace std;
int n,m,a[100010],b[50010],c[50010],x,ans,k,k1,j;
int main(){
freopen("card.in","r",stdin);
freopen("card.out","w",stdout);
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&x);
a[x]=1;
}
k=0,k1=0;
for(int i=1;i<=n*2;i++)
if(!a[i])
b[++k]=i;
else
c[++k1]=i;
j=1,ans=0;
for(int i=1;i<=n;i++)
{
if(c[j]<b[i])
{
j++;
ans++;
if(j>n)
{
printf("%d",ans);
return 0;
}
}
}
printf("%d",ans);
}