The photosynthesis of garlic guest

Source: Internet
Author: User

du Bear is a child who loves to learn, he always likes to do some small experiments in life, this time du The bear wants to study photosynthesis.

du Bear's experimental materials 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, and the angle between the sides of the light source is 45° , the yellow part is the light, the green is the plant.

Enter the first line to give aTA number that represents the group of test data. The first row of each set of data is three integersn,m,h (1≤n≤100,000, 0≤m≤100,000, 1≤h≤10,000),Nindicates the number of seeds(numbering1-n),mindicates the number of lights,Hindicates the height of the box. Nextmrows, one integer per lineXirepresents the firstIThe position of the light source at the top. ????

for each set of test data, output N line, one number per line indicates the first I The final height of the seed.

Sample Example 1

Input:

2

7 1 2

4

4 4 1

1

2

3

4

Output:

0

0

1

2

1

0

0

1

1

1

1

  1. #include <stdio.h>
  2. #include <string.h>
  3. #define ABS (a) ((a) >0? ( A):(-a))
  4. #define M 100000
  5. int light[m];
  6. int Main () {
  7. ???? int T,n,m,h,i,add,sign,t;
  8. ???? scanf ("%d", &t);
  9. ???? while (t--) {
  10. ???????? scanf ("%d%d%d", &n,&m,&h);
  11. ???????? memset (light,0,sizeof(light));
  12. ???????? for (i=0;i<m;i++) {
  13. ???????????? scanf ("%d", &t);
  14. ???????????? Light[t]=1;
  15. ????????}
  16. ???????? for (i=1;i<=n;i++) {
  17. ???????????? Add=0;
  18. ???????????? Sign=1;
  19. ???????????? while (Light[i+add]==0&&abs (add)
  20. ???????????????? if (sign) {
  21. ???????????????????? if (add>=0) add++;
  22. ???????????????????? else add--;
  23. ???????????????????? sign=0;
  24. ????????????????}
  25. ???????????????? else sign=1;
  26. ???????????????? if (i-add>0&&i-add<=n) Add=-add;
  27. ????????????}
  28. ???????????? Add=abs (add);
  29. ???????????? printf ("%d\n", H-add);
  30. ????????}
  31. ????}
  32. ???? return 0;
  33. }

?

By carefully understanding the topic and thinking about it, you will know that the maximum height each plant can grow is???? H-mins (mins is the distance from its nearest light source). So as long as can find from the first plant the nearest light source can, how to find it?

I use the left and right detection method (the name that my brain complements). ), inspired by the square detection method to solve the hash conflict, for plant I we first observe his left distance of 1, and then observe the right distance of 1 of the position

If there is no light source, then find the left distance of 2 position, and so on, until the distance is greater than or equal to H or find the light source, if found, then the height of the current plant can be output, otherwise the plant height of 0;

Formula Spit Groove (The reason why the old in the account of garlic customers have two reasons, first, simple .....) (After all, I novice), the second, there will be a reasonable classification of the topic, so that I can focus on the practice, but, although this problem is classified in two points to find, but I can not see where two points need to say, there should be two points to find the solution, but I did not think, later thought to re-write it (and The trouble here is to look for possible cross-border, and nothing else.

If it were not for the two days, I felt no need to write. )

The photosynthesis of garlic guest

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.