Sha 1372-Log Jumping (inference)

Source: Internet
Author: User

Question: 1372-Log Jumping the start position and length of n boards. Overlapping boards can jump to each other to obtain the maximum number of rings. Train of Thought: first sort by the starting position, and then judge whether he and the previous one can jump to each other with one more board each time. If yes, they can add more boards. Code:

# Include

 
  
# Include

  
   
# Include using namespace std; # define max (a, B) (a)> (B )? (A) :( B) # define INF 0x3f3f3fconst int N = 5005; int t, n, k, I, start [N]; bool check (int s, int e) {return e-s <= k;} int main () {scanf ("% d", & t); while (t --) {int ans = 0; scanf ("% d", & n, & k); for (I = 0; I <n; I ++) scanf ("% d ", & start [I]); sort (start, start + n); I = 0; while (I <n) {int sum = 1; while (I <n-1 & (sum = 1 & check (start [I], start [I + 1]) | (check (start [I], start [I + 1]) & chec K (start [I-1], start [I + 1]) sum ++, I ++; if (! Check (start [I], start [I + 1]) | I = n-1) I ++; ans = max (ans, sum );} printf ("% d \ n", ans);} return 0 ;}

  

 


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.