Bzoj 1293 Birthday Present

Source: Internet
Author: User

A year of Sichuan province election.

Enumerate each bead and look for all the kinds of beads in front of it and its maximum distance (this distance must include all the beads) and then update the answer.

For convenience, we sort the beads and form the list of links (also in reverse order).

However, this water problem ziliuziliu still not very good to think out. I don't know what's going on. This problem is actually quite simple ah.

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define INF 0X7FFFFFFF
#define MAXN 1000050
#define MAXV 65
using namespace Std;
int CNT=0,NUM[MAXN],NEXT[MAXN],HEAD[MAXV];
int N,k,x,r,a[maxn],ans;
int find (int x)
{
int tmp=0;
for (int i=1;i<=k;i++)
{
while (Num[head[i]]>a[x])
{
Head[i]=next[head[i]];
if (head[i]==0) return 0;
}
if (Num[head[i]]<a[x])
Tmp=max (Tmp,a[x]-num[head[i]);
}
Ans=min (ANS,TMP);
return 1;
}
int main ()
{
Ans=inf;
memset (head,0,sizeof (head));
memset (Next,0,sizeof (next));
scanf ("%d%d", &n,&k);
for (int i=1;i<=k;i++)
{
scanf ("%d", &x);
for (int j=1;j<=x;j++)
{
scanf ("%d", &r);
A[++cnt]=r;
Num[cnt]=r;
Next[cnt]=head[i];
head[i]=cnt;
}
}
Sort (a+1,a+cnt+1);
for (int i=cnt;i>=1;i--)
{
if (a[i]!=a[i+1])
{
int Flag=find (i);
if (flag==0) break;
}
}
printf ("%d\n", ans);
return 0;
}

Bzoj 1293 Birthday Present

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.