Codeforces Beta Round #87 (Div. 2 Only)
2011-09-16 13:06
288 查看
A:水题。。。模拟取最大。。。。
B:由于保证了每个羊最多对应一只狼,所以直接扫描一遍判定就可以了,注意同一个狼别加两次= =。
C:求所有树的最高树高。证明:每个树任意两层的节点肯定不能位于同一个集合,这样得出至少需要最高树高个集合,然后我们把所有的树画在一条线上,每一层对应一个集合,这样可以构造一个包含最高树高个集合的可行解,所以最少需要的集合数为最高树高。
D:裸贪心。。注意那种没有weed的行的处理,开始写晕了,还在pretest 8上WA了一次,无奈之下果断重写了一次好了= =。
A:
View Code
B:由于保证了每个羊最多对应一只狼,所以直接扫描一遍判定就可以了,注意同一个狼别加两次= =。
C:求所有树的最高树高。证明:每个树任意两层的节点肯定不能位于同一个集合,这样得出至少需要最高树高个集合,然后我们把所有的树画在一条线上,每一层对应一个集合,这样可以构造一个包含最高树高个集合的可行解,所以最少需要的集合数为最高树高。
D:裸贪心。。注意那种没有weed的行的处理,开始写晕了,还在pretest 8上WA了一次,无奈之下果断重写了一次好了= =。
A:
View Code
#include <iostream> #include <cstdio> #include <ctime> #include <cmath> #include <cstring> #include <cstdlib> #include <string> #include <queue> #include <stack> #include <vector> #include <set> #include <algorithm> using namespace std; #define MP(x, y) make_pair(x, y) #define FOR(i, x, y) for((i) = (x); (i) <= (y); (i)++) typedef long long llg; const int N = 160; int n, m, l , r , flag ; char map ; int abs(int x) { if(x < 0) x = -x; return x; } int solve() { int i, ans = 0; if(l[1] == -1) flag[1] = 0; else flag[1] = r[1]; for(i = n; i > 0; i--) if(r[i] != -1) break; n = i; if(n == 0) return 0; if(r[1] != -1) ans += r[1]; for(i = 2; i <= n; i++) { ans++; if(i%2 == 0) { if(r[i] != -1) ans += abs(r[i]-flag[i-1]); flag[i] = l[i]; } else { if(l[i] != -1) ans += abs(l[i]-flag[i-1]); flag[i] = r[i]; } if(flag[i] == -1) flag[i] = flag[i-1]; ans += (r[i]-l[i]); } return ans; } int main() { int i, j, ans; freopen("data.txt", "r", stdin); scanf("%d%d", &n, &m); for(i = 1; i <= n; i++) scanf(" %s", map[i]); memset(l, -1, sizeof(l)); memset(r, -1, sizeof(r)); for(i = 1; i <= n; i++) { for(j = 0; j < m; j++) if(map[i][j] == 'W') { l[i] = j; break; } for(j = m-1; j >= 0; j--) if(map[i][j] == 'W') { r[i] = j; break; } } ans = solve(); printf("%d\n", ans); return 0; }
相关文章推荐
- Codeforces Beta Round #83 (Div. 1 Only) E.Darts 凸多边形面积交
- Codeforces Beta Round #9 (Div. 2 Only) D. How many trees? dp
- Codeforces Beta Round #25 (Div. 2 Only)D. Roads not only in Berland
- Codeforces Beta Round #87 (Div. 1 Only)
- Codeforces Round #437 (Div. 2 C. Ordering Pizza 贪心 only two types of pizza
- 【CS Round #48 (Div. 2 only)】Water Volume
- 【CS Round #37 (Div. 2 only) A】Boring Number
- Codeforces Beta Round #6 (Div. 2 Only) E. Exposition
- Codeforces Beta Round #91 (Div. 1 Only) E. Lucky Array
- Codeforces Beta Round #75 (Div. 1 Only) A题
- Codeforces Round #447 (Div 2 Only) Hack+FST记
- Codeforces Beta Round #25 (Div. 2 Only) - E. Test (KMP)
- Codeforces Beta Round #75 (Div. 1 Only) B. Queue 线段树+二分
- Codeforces Beta Round #77 (Div. 2 Only)——A,B,C
- 【dfs找环】Codeforces Beta Round #80 (Div. 1 Only)——B. Cthulhu
- Codeforces Beta Round #4 (Div. 2 Only) D. Mysterious Present 记忆化搜索
- Codeforces Beta Round #83 (Div. 1 Only) E.Darts 凸多边形面积交
- Codeforces Beta Round #25 (Div. 2 Only)E. Test
- Codeforces Beta Round #4 (Div. 2 Only)
- Codeforces Round #437 (Div. 2 C. Ordering Pizza 贪心 only two types of pizza