Bzoj 1293 scoi2009 birthday gift heap

Source: Internet
Author: User

Given N points on a number axis, each point has a color. k colors are used in total to find a shortest interval, including all k colors.

After a while, 0.0 first thought about the second answer, and later found that the data range was too large to write 0.0. Later, I went to the question to find out that Nima was really clever.

Maintain a heap and add the first beads of each color to the heap. Then, remove the leftmost beads, add the next beads of this color, and update ans.

Sure enough, we still need to use a small data structure such as a heap constant for such a big data range, 0.0.

I wrote the heap but opened the STL queue 0.0. Don't say I'm sick. I'm just not used to the STL heap.

#include<queue>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;typedef pair<int,int> abcd;int n,m,k,top,ans=0x7fffffff,maxnum=0;abcd heap[70];queue<int>q[70];void Insert(abcd x){heap[++top]=x;int t=top;while( t>1 && heap[t]


Bzoj 1293 scoi2009 birthday gift heap

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.