码迷,mamicode.com
首页 > 其他好文 > 详细

各种沙茶错误

时间:2018-07-26 21:13:58      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:names   als   const   for   long   lib   统计   tar   bug   

P3088 [USACO13NOV]挤奶牛Crowded Cows

%%%%%%%%%%%%%%%%%%%%%%%

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cstdlib>
 4 #include <iostream>
 5 #include <algorithm>
 6 using namespace std;
 7 
 8 const int MAXN = 50010;
 9 int N, D;
10 bool lef[MAXN], rig[MAXN];
11 
12 struct Cow {
13     int x, h;
14     bool operator < (const Cow &c) const {
15         return x < c.x;
16     }
17 }e[MAXN], ql[MAXN], qr[MAXN];
18 
19 int main() {
20     memset(lef, false, sizeof(lef));
21     memset(rig, false, sizeof(rig));
22     scanf("%d%d", &N, &D);
23     for (int i = 1; i <= N; ++ i) 
24         scanf("%d%d", &e[i].x, &e[i].h);
25     sort(e + 1, e + N + 1);
26     int head = 1, tail = 0;
27     for (int i = 1; i <= N; ++ i) {
28         while (ql[head].x < e[i].x - D && head <= tail) head++;
29         while (ql[tail].h < e[i].h && head <= tail) tail--;
30         ql[++tail] = e[i];
31         if (ql[head].h >= e[i].h * 2) lef[i] = true;
32     } 
33     head = 1, tail = 0;
34     for (int i = N; i >= 1; -- i) {
35         while (qr[head].x > e[i].x + D && head <= tail) head++;
36         while (qr[tail].h < e[i].h && head <= tail) tail--;
37         qr[++tail] = e[i];
38         if (qr[head].h >= e[i].h * 2) rig[i] = true;  
39     }
40     int ans = 0;
41     for (int i = 1; i <= N; ++ i) if (lef[i] && rig[i]) ans++;
42     cout << ans << endl;
43     return 0;
44 }

单调队列head敲成tail Debug了十分钟

P1896 [SCOI2005]互不侵犯

%%%%%%%%%%%%%%%%%%%%%%%

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define f(i, x, n) for(int i=x;i<=n;++i)
using namespace std;

typedef long long LL;
const int MAXX = 110;
int N, K;
int tot, s0, s[MAXX], num[MAXX];
LL ans, dp[10][MAXX][MAXX];

int main() {
    cin >> N >> K;
    f(i, 0, (1<<N)-1) { //枚举每行状态
        if (i & (i<<1)) continue; //判断是否冲突
        tot = 0;
        f(j, 0, N-1) 
            if (i & (1<<j)) tot++; //统计放置数量
        s[++s0] = i; //标记可行方案
        num[s0] = tot; 
    }
    dp[0][1][0] = 1;
    f(i, 1, N) f(j, 1, s0) f(k, 0, K) 
        if (k >= num[j]) f(t, 1, s0) 
            if (!(s[t]&s[j])&&!(s[t]&(s[j]<<1))&&!(s[t]&s[j]>>1))
                dp[i][j][k] += dp[i - 1][t][k - num[j]];
    f(i, 1, s0) ans += dp[N][i][K];
    cout << ans << endl;
    return 0;
}

没开long long 70分。看题解秒A。

 

各种沙茶错误

标签:names   als   const   for   long   lib   统计   tar   bug   

原文地址:https://www.cnblogs.com/hkttg/p/9373908.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!