[zoj3627]模拟吧

思路:情况只可能是2种,两个人一直向一边走,或者有一个人折回来,对于后一种,枚举折回来的位置就行了。不过要注意两个方向都要处理下。

 1 #pragma comment(linker, "/STACK:10240000,10240000")
 2 
 3 #include <iostream>
 4 #include <cstdio>
 5 #include <algorithm>
 6 #include <cstdlib>
 7 #include <cstring>
 8 #include <map>
 9 #include <queue>
10 #include <deque>
11 #include <cmath>
12 #include <vector>
13 #include <ctime>
14 #include <cctype>
15 #include <set>
16 
17 using namespace std;
18 
19 #define mem0(a) memset(a, 0, sizeof(a))
20 #define lson l, m, rt << 1
21 #define rson m + 1, r, rt << 1 | 1
22 #define define_m int m = (l + r) >> 1
23 #define rep(a, b) for(int a = 0; a < b; a++)
24 #define rrep(a, b) for(int a = b - 1; a >= 0; a--)
25 #define all(a) (a).begin(), (a).end()
26 #define lowbit(x) ((x) & (-(x)))
27 #define constructInt4(name, a, b, c, d) name(int a = 0, int b = 0, int c = 0, int d = 0): a(a), b(b), c(c), d(d) {}
28 #define constructInt3(name, a, b, c) name(int a = 0, int b = 0, int c = 0): a(a), b(b), c(c) {}
29 #define constructInt2(name, a, b) name(int a = 0, int b = 0): a(a), b(b) {}
30 #define pc(a) putchar(a)
31 #define ps(a) printf("%s", a)
32 #define pd(a) printf("%d", a)
33 #define sd(a) scanf("%d", &a)
34 
35 typedef double db;
36 typedef long long LL;
37 typedef pair<int, int> pii;
38 typedef multiset<int> msi;
39 typedef set<int> si;
40 typedef vector<int> vi;
41 typedef map<int, int> mii;
42 
43 const int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
44 const int dy[8] = {1, 0, -1, 0, -1, 1, 1, -1};
45 const int maxn = 1e5 + 7;
46 const int maxm = 1e5 + 7;
47 const int maxv = 1e7 + 7;
48 const int max_val = 1e6 + 7;
49 const int MD = 1e9 +7;
50 const int INF = 1e9 + 7;
51 const double PI = acos(-1.0);
52 const double eps = 1e-10;
53 
54 template<class T> T gcd(T a, T b) { return b == 0? a : gcd(b, a % b); }
55 
56 LL sum[maxn], sum2[maxn];
57 int a[maxn];
58 int n, p, m ,t, x;
59 
60 LL work() {
61     LL ans = 0;
62     int l = max(0, p - t), r = min(n - 1, p + t);
63     for (int i = l; i < p; i++) {
64         int pos1 = p + min(m / 2, p - i), pos2 = min(m + i, p + p - i), pos = max(pos1, pos2 + t - (p - i));
65         pos = min(r, pos);
66         ans = max(ans, sum[pos] - (i? sum[i - 1] : 0));
67     }
68     ans = max(ans, sum[r] - (p? sum[p - 1] : 0));
69     return ans;
70 }
71 
72 int main() {
73     //freopen("in.txt", "r", stdin);
74 
75     while (cin >> n >> p) {
76         p--;
77         sum[0] = 0;
78         rep(i, n) {
79             sd(a[i]);
80             if (i) sum[i] = sum[i - 1];
81             sum[i] += a[i];
82         }
83         sum2[0] = a[n - 1];
84         rrep(i, n - 1) sum2[n - i - 1] = sum2[n - i - 2] + a[i];
85         cin >> m >> t;
86 
87         LL ans = work();
88         memcpy(sum, sum2, sizeof(sum));
89         p = n - p - 1;
90         ans = max(ans, work());
91         cout << ans << endl;
92     }
93     return 0;
94 }
View Code
原文地址:https://www.cnblogs.com/jklongint/p/4419002.html