# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
626 |
2013-02-28T17:41:54 Z |
jwvg0425 |
파일 삭제 (GA3_delete) |
C++ |
|
0 ms |
0 KB |
struct F{int a,b;};
F D[3000];
void addFile(int i, int* B)
{
D[i].a++;
if(i==0)
return;
addFile(B[i],B);
}
void UpDelete(int i,int r,int M,int* B)
{
int k;
for(k=0;D[k].b!=i;k++);
D[k].a-=r;
if(B[i]==-1)
return;
UpDelete(B[D[k].b],r,M,B);
}
void deleteDir(int i,int M,int* B)
{
int j,k;
for(k=0;D[k].b!=i;k++);
D[k].a=0;
for(j=0;j<M;j++)
{
if(B[j]==D[k].b)
{
deleteDir(j,M,B);
}
}
}
int Compare(const void* a,const void* b)
{
return ((F*)b)->a-((F*)a)->a;
}
int DeletePlan(int N,int M, int K, int* A,int* B)
{
int i,s=0;
for(i=0;i<N;i++)
{
addFile(A[i],B);
}
for(i=0;i<M;i++)
{
D[i].b=i;
}
qsort(D,M,sizeof(F),Compare);
for(i=0;i<M;i++)
{
if(D[i].a<=K)
{
K-=D[i].a;
UpDelete(B[D[i].b],D[i].a,M,B);
deleteDir(D[i].b,M,B);
qsort(D,M,sizeof(F),Compare);
s++;
i=-1;
}
}
s+=K;
return s;
}
Compilation message
grader.cpp:30:2: warning: no newline at end of file
delete.cpp: In function 'int DeletePlan(int, int, int, int*, int*)':
delete.cpp:51: error: 'qsort' was not declared in this scope