Round 2 B
来源:互联网 发布:优酷for mac 编辑:程序博客网 时间:2024/06/07 06:42
题目链接:
http://codeforces.com/problemset/problem/225/B
大意:
地图上分布有小猪和狼,狼只能吃相邻的小猪且只能吃一个,求最多有多少小猪被吃。
思路:
遍历一遍就行,题目是很水的。。。但是自己图论太差,题目做太少看见图论专题都被吓死。
#include<bits/stdc++.h>#define mem(s,t) memset(s,t,sizeof(s))typedef long long ll;using namespace std;//#define LOCALint n,m;const int MAXN =15;char g[MAXN][MAXN];int vis[MAXN][MAXN];int cnt=0,row,col;int main(){#ifdef LOCAL freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);#endif cin>>row>>col; for(int i=0;i<row;i++){ for(int j=0;j<col;j++){ cin>>g[i][j]; vis[i][j]=1; } } for(int i=0;i<row;i++){ for(int j=0;j<col;j++){ if(vis[i][j] && g[i][j]=='W'){ if(i<row-1 && g[i+1][j]=='P') cnt++,vis[i+1][j]=0; else if(i>=1 && g[i-1][j]=='P') cnt++,vis[i-1][j]=0; else if(j<col-1 && g[i][j+1]=='P') cnt++,vis[i][j+1]=0; else if(j>=1 && g[i][j-1]=='P') cnt++,vis[i][j-1]=0; } } } cout<<cnt<<endl; return 0;}
阅读全文
0 0
- Round 2 B
- Codeforces Beta Round #2 B
- Codeforces Round #227 (Div. 2)B. George and Round
- Codeforces Round #227 (Div. 2) B. George and Round
- Codeforces Beta Round #2B. The least round way
- Codeforces Beta Round #2 B. The least round way
- Codeforces Round #317 [AimFund Thanks-Round] (Div. 2)(A,B)
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) B 暴力
- 【Codeforces Round #351 Div. 2】 673B Problems for Round
- 【dp】Codeforces Beta Round #2 B
- Codeforces Round #131 (Div. 2) A B
- Codeforces Round #134 (Div. 2)B. Airport
- codefroces 2B The least round way
- codeforces 2B The least round way
- Codeforces Round #170 (Div. 2) problem B
- Codeforces Round #173 (Div. 2) Problem B
- Codeforces Beta Round #2--B题 (DP)
- Codeforces Round #181 (Div. 2) B. Coach
- 机器学习25-主题模型LDA(一)
- android 事件监听方法大全
- Android之百度地图(一)申请秘钥
- sql注入总结
- Visual Studio 2013+FFMPEG开发环境配置
- Round 2 B
- python2.7 编码问题解析(一)
- JSP中的include的两种使用方法法
- sybase 主键自动增长
- 2017十大网络黑客攻击事件丨阿里云河南
- 合天网安实验室:CTF-MISC练习
- Windows系统版本判断
- QT 中使用 Windows API----SendMessage() 进行窗体间消息传递
- LeetCode