Cf-1066b-heaters

Source: Internet
Author: User

The problem is to traverse from 1 to N, to find the farthest point in the unheated point to heat up to this point, or to see the code.

#include"bits/stdc++.h"using namespacestd;Const intinf=0x3f3f3f3f; typedefLong LongLL;inta[1005],ans;intMain () {intn,m; scanf ("%d%d",&n,&m);  for(intI=1; i<=n;i++) scanf ("%d",&A[i]);  for(intI=1; i<=n;ans++){        //let J be equal to the farthest value that can be heated to I point, the range that can be heated to I point is [j-m+1,j+m-1]//But if j+m-1 is greater than N, then (n,j+m-1] This paragraph to abandon, if j-m+1 is less than 1, then [j-m+1,1] This paragraph also to abandon;        intj=i+m-1;if(j>n) j=N;  while(j&&j>j-m) {            //The maximum point of the heater is found in the range that can be heated to the I point;            if(a[j]==1) Break; J--; }        //If 1 is not found within this range, then I will not be able to heat the point, I can directly output-1 and end the program        if(!j| | j<=j-m) {Puts ("-1"); return 0; }        //otherwise let I increase to J heating less than the minimum value is j+m;i=j+m; } printf ("%d", ans); return 0;}

Cf-1066b-heaters

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.