Cod sursa(job #13171)

Utilizator witchchiorescu madalina witch Data 5 februarie 2007 22:29:05
Problema Secventa 5 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.14 kb
//chiorescu madalina - botosani

#include<stdio.h>
FILE *f,*g;
f=fopen("secv5.in","r");
g=fopen("secv5.out","w");

int v[100],n,l,u,nr1,s[100];

int verif(int x,int y)
{int nr=0,i;
for(i=x;i<=y;i++) if(v[s[i]]==0) 
{nr++;v[s[i]]=1;if(nr>u){for(int i1=1;i1<=n;i++) v[s[i1]]=0; return 0;}}
//else if(v[s[i]]==1) {nr--;v[s[i]]++;if(nr>u){for(i=1;i<=n;i++) v[s[i]]=0; return 0;}}

if(nr<l) {for(i=1;i<=n;i++) v[s[i]]=0;return 0;}
for(i=1;i<=n;i++) v[s[i]]=0;
return nr;}



int main()
{
fscanf(f,"%d%d%d",&n,&l,&u);
int i,j;
for(i=1;i<=n;i++) fscanf(f,"%d",&s[i]);

for(i=1;i<=n-l+1;i++)
{j=i+l-1;
while(verif(i,j)==0&&j<n+4) j++;
if(j<=n)
{nr1++;
int nr=0,i1; 

for(i1=i;i1<=j;i1++) if(v[s[i1]]==0)
{nr++;v[s[i1]]=1;} else v[s[i1]]++;
/*for(i1=i;i1<=j;i1++) cout<<s[i1]<<" ";cout<<"\t"<<nr<<endl;*/
 

j++;
while(j<=n)
{if(v[s[j]]==0) {nr++;v[s[j]]=1;}

//for(i1=i;i1<=j;i1++) cout<<s[i1]<<" ";cout<<"\t"<<nr<<endl;
if(nr<=u&&nr>=l) {/*for(i1=i;i1<=j;i1++) cout<<s[i1]<<" ";cout<<"\t"<<nr<<endl;*/  nr1++;}
j++;}
for(i1=1;i1<=n;i1++) v[s[i1]]=0;
}}



fprintf(g,"%d",&nr1);
fclose(f);fclose(g);return 0;}