Garlic lessons Photosynthesis Baidu star 2012.12.23 Topic 1

Source: Internet
Author: User

Links: https://nanti.jisuanke.com/t/38

Du Bear is a learning child, he always likes to do some small experiments in life, this time du Bear want to study photosynthesis.

The experimental materials of Du bear are as follows: magical seeds, ordinary cartons and some light sources. At first, the Du bear planted the seeds evenly on the bottom of the box, which you can consider as the x-axis, where the seed is located on the x-axis. The Du bear then covered the box with cardboard and installed some light sources on the cardboard (see figure). The magical seeds will grow upward until there is no light in the case of light. Now du Bear wants to know how high each seed is at the end of the experiment.

The top is the light source, the angle between the light source and the top is 45°, the yellow part is the light, the green is the plant.

Enter the first line to give a t that represents the number of groups of test data. The first line of data for each group is three integers n,m,h (1≤n≤100,000, 0≤m≤100,000, 1≤h≤10,000), n is the number of seeds (numbering 1-n), M is the number of lights, and H indicates the height of the box. Next m line, one integer for each line, Xi, indicates the position of the first light source at the top.

For each set of test data, output n rows, and a number per line indicates the final height of the seed of the first I.

The array did not clear cause WA a day of sadness ....

Obviously normal people can think of two points, but this problem, is an integer case of BFS a trip on OK O (n+h) solution. , in fact, even the fractional discretization plus priority queue can be done ... Just change the big log to small log, calculate the constant optimization?

... On the Code

#include <stdio.h>#include<cstring>#include<iostream>#include<vector>using namespacestd;Const intMAXN = 1e5+1e4+Ten;intANS[MAXN];BOOLVIS[MAXN];intN,m,h;vector<int>b;voidinit () {memset (ans,-1,sizeof(ans)); memset (Vis,0,sizeof(VIS));    A.clear ();    B.clear (); scanf ("%d%d%d",&n,&m,&h); }BOOLFintPOS) {    if(pos>=0&&pos<=n+h&&vis[pos]==false) {returnVis[pos] =true;} Else return false;}voidBFS () {intT;  for(intI=0; i<m;i++) {scanf ("%d",&t); Vis[t]=true;    A.push_back (t); }    intLim = A.size (), H =h;  while(lim&&H) { for(intI=0; i<lim;i++)        {            intx =A[i]; ANS[X]=H; if(F (x1)) B.push_back (X-1); if(F (x+1)) B.push_back (x+1);        } swap (A, b); H--; Lim=a.size ();    B.clear (); }}intMain () {intT; scanf ("%d",&T);  for(intI=0; i<t;i++) {init ();          BFS ();  for(intI=1; i<=n;i++) {printf ("%d\n", Max (ans[i),0)); }    }    return 0;}
AC Code

Garlic lessons Photosynthesis Baidu star 2012.12.23 Topic 1

Related Article

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.