CF 253B Two Heaps

#include<stdio.h>
#include<algorithm>
#include<map>
using namespace std;
struct Node
{
int x;
int number;
int i;
int flag;
}a[];
int b[];
map<int,int>ma,mb1,mb2;
bool cmp1(Node a,Node b)
{
if(a.i<b.i)return true;
return false;
}
bool cmp2(Node a,Node b)
{
if(a.number<b.number)return true;
if(a.number==b.number&&a.x<b.x)return true;
return false;
}
int main()
{
int i,n;
while(scanf("%d",&n)!=EOF)
{
ma.clear();
mb1.clear();
mb2.clear();
n=*n;
for(i=;i<n;i++)
{
scanf("%d",&a[i].x);
a[i].i=i;
ma[a[i].x]++;
//a[i].number=1;
}
for(i=;i<n;i++)
a[i].number=ma[a[i].x];
sort(a,a+n,cmp2);//number
/*for(i=0;i<n;i++)
printf("%d:%d ",a[i].x,a[i].number);*/
for(i=;i<n;i+=)
{
a[i].flag=;
mb1[a[i].x];
a[i+].flag=;
mb2[a[i+].x];
}
sort(a,a+n,cmp1);
printf("%d\n",mb1.size()*mb2.size());
for(i=;i<n-;i++)
printf("%d ",a[i].flag);
printf("%d\n",a[n-].flag);
}
return ;
}
上一篇:java simple check whether a file or directory.


下一篇:QEMU KVM Libvirt(12): Live Migration