Codeforces Round #200(Div.2) E. Read Time(2점)

7572 단어 codeforces
제목 링크
이 문제의 관건은 2분이 아니라 t의 시간 안에 n개의 머리를 이 m개의 디스크에 칠하는 것이다.
문제풀이를 보니 도무지 어떻게 해야 할지 모르겠다.포인터로pre, 매거 m에서 토론을 해 봅시다.단지 모든 디스크가 오른쪽 머리에서 튀어나온 것을 고려할 뿐이다. (왼쪽에서 오기 전에 닦았다.)
사유는 경상이다.
 1 #include <iostream>

 2 #include <cstdio>

 3 #include <cstring>

 4 #include <vector>

 5 #include <cmath>

 6 #include <algorithm>

 7 using namespace std;

 8 #define LL __int64

 9 LL p[100001],h[100001];

10 int n,m;

11 int judge(LL x)

12 {

13     int pre = 0;

14     LL temp;

15     int i;

16     for(i = 0;i < n;i ++)

17     {

18         if(abs(p[pre]-h[i]) > x) continue;

19         if(p[pre] < h[i])

20         temp = h[i] + max((x-(h[i]-p[pre]))/2,x-2*(h[i]-p[pre]));

21         else

22         temp = h[i] + x;

23         while(p[pre] <= temp&&pre < m)pre ++;

24     }

25     if(pre == m)

26     return 1;

27     else

28     return 0;

29 }

30 LL bin()

31 {

32     LL str,end,mid;

33     str = 0;

34     end = 100000000000000ll;

35     while(str < end)

36     {

37         mid = (str + end)/2;

38         if(judge(mid))

39         end = mid;

40         else

41         str = mid + 1;

42     }

43     return str;

44 }

45 int main()

46 {

47     int i;

48     scanf("%d%d",&n,&m);

49     for(i = 0;i < n;i ++)

50     {

51         scanf("%I64d",&h[i]);

52     }

53     for(i = 0;i < m;i ++)

54     {

55         scanf("%I64d",&p[i]);

56     }

57     printf("%I64d
",bin()); 58 return 0; 59 }

좋은 웹페이지 즐겨찾기