Bzoj 3969 Low Power Problem Solving report

Source: Internet
Author: User

We first sort all the batteries, then we can find a set of optimal schemes, so that the difference in energy of one machine is the difference of energy between two adjacent cells.

Then we have two points of the answer, the former greedy to choose the number of pairs, and then see whether all the pairs are satisfied with the conditions.

Assuming that the number pair is i-1, I, and is the number of J pairs, then we call the satisfying condition:

2nk-i + 2 >= 2k (n-j + 1)

It means that you can get enough batteries to make a robot.

Then pay attention to the special sentence: If you cannot select enough number pairs to return false, I am here WA to die ...

After all, Gromah is too weak to do water problems.

1#include <cmath>2#include <cstdio>3#include <cstring>4#include <iostream>5#include <algorithm>6 using namespacestd;7 #defineN 1000000 + 58   9 intN, k, size, Max, a[n];Ten    OneInlineintGetint () A { -     CharCH ='\ n'; -      for(; CH >'9'|| Ch <'0'; CH =GetChar ()); the     intres = CH-'0'; -      for(ch = getchar (); Ch >='0'&& CH <='9'; CH =GetChar ()) -res = (Res <<3) + (res <<1) + CH-'0'; -     returnRes; + } -    +InlineBOOLJudge (intm) A { at     intCNT =N; -      for(inti =2; CNT && i <= size; i + +) -         if(A[i]-a[i-1] <=m) -         { -             if(Size-i +2<2* CNT * k)return 0; -CNT--, i + +; in         } -     return!CNT; to } +    - intMain () the { * #ifndef Online_judge $Freopen ("3969.in","R", stdin);Panax NotoginsengFreopen ("3969.out","W", stdout); -     #endif the        +n = Getint (), k =getint (); ASize = (n * k) <<1; the      for(inti =1; I <= size; i + +) +     { -A[i] =getint (); $Max =Max (max, a[i]); $     } -Sort (A +1, A + size +1); -     intL = a[2]-a[1], R =Max; the      while(L <R) -     {Wuyi         intMid = (L + r) >>1; the         if(Judge (mid)) R =mid; -             ElseL = mid +1; Wu     } -printf"%d\n", L); About        $ #ifndef Online_judge - fclose (stdin); - fclose (stdout); -     #endif A     return 0; +}

Bzoj 3969 Low Power Problem Solving report

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.