63 条题解
-
0doveccl LV 8 @ 2013-08-13 12:19:54
var n,m,i,h,t,temp,num:longint;
q:array[1..100000] of longint;
function find(x:longint):boolean;
var i:longint;
begin
for i:=h to t do
if q[i]=x then exit(true);
exit(false);
end;
procedure add(x:longint);
begin
if t-h+1=m then
inc(h);
inc(t);
q[t]:=x;
end;
begin
h:=1;
t:=0;
num:=0;
readln(m,n);
for i:=1 to n do
begin
read(temp);
if not(find(temp)) then
begin
inc(num);
add(temp);
end;
end;
writeln(num);
end. -
02013-08-07 11:40:55@
O(∩_∩)O~ 一次AC 刷水题最舒服了
Var n,m,head,tail,i,j,ans,x:longint;
a,q:array[1..1000000] of longint;
Begin
head:=1;
Readln(m,n);
For i:=1 to n do
Begin
read(x);
If (a[x]=0) and (tail-head+1<m) then
begin
inc(ans);
inc(tail);
q[tail]:=x;
inc(a[x]);
End;
If (a[x]=0) and (tail-head+1>=m) then
begin
a[q[head]]:=0;
inc(head);
inc(ans);
inc(tail);
q[tail]:=x;
inc(a[x]);
End;
End;
Writeln(ans);
End. -
02013-07-25 15:44:34@
include <stdio.h>
include <stdlib.h>
include <string.h>
int main()
{
int m, n, i, j, k, flag, flag2, sum;
k = sum =0;
int s[1001],h[1001];scanf("%d%d", &m, &n);
memset(s,0,sizeof(s));for (i=0;i<n;i++)
{
flag= flag2 = 0;
scanf("%d", &s[i]);
for (j=0;j<m;j++)
{
if(s[i]==h[j])
{
flag=1;
}
}
if(flag)
continue;
for (j=0;j<m;j++)
{
if(k==m)
{
h[j] = h[(j+1)];
flag2 = 1;
}
else
break;
}
if(flag2)
h[m-1]=s[i];
else
{
h[k]=s[i];
k++;
}
sum++;
}
printf("%d\n", sum);
return 0;
}