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 }
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Codeforces Round #715 Div. 2C The Sports Festival: 구간 DP전형구간 DP의 초전형. 이하, 0-indexed. 입력을 정렬하여 어디서나 시작하고 최적으로 좌우로 계속 유지하면 좋다는 것을 알 수 있습니다. {2000})$의 주문이 된다. 우선, 입력을 소트하여 n개의 요소를 $...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.