CodeForces 919C(DFS)
2018-02-26 17:29
387 查看
题目链接:点击打开链接
题目大意:输入n,m,k表示n*m的教室,.是空位,让你找连着的k个位置的情况。 题目思路:打这场CF的时候这题本来很早就过了..结果刚过完这题就被一个美国人hack了...然后debug一个小时都没找出错误...去上了个厕所想起来是不是可能没朋友..(题意是说帮自己和朋友占座以为至少需要2个位置啊啊啊)回来一看k的范围果然可以等于1...很难受..不过那次没掉分,还加了几分美滋滋...回到正题..这题咋写呢..其实比普通的dfs还简单点,都不用递归..直接横着找满足的个数,竖着找满足的个数,只不过k是1的时候需要特判,把结果除以二就行了.. 以下是代码:#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char map[2005][2005];
int main(){
int n,m,k,num,temp,y;
while(~scanf("%d%d%d",&n,&m,&k)){
memset(map,'0',sizeof(map));
num=0;
for(int i=1;i<=n;i++){
scanf("%s",map[i]+1);
}
for(int i=1;i<=n;i++){
temp=0;
for(int j=1;j<=m;j++){
if(map[i][j]=='.'){
if(j>m-k+1){
continue;
}
else{
y=j;
while(map[i][y]=='.'&&y<=m){
temp++;
y++;
}
if(temp>=k){
num+=temp-k+1;
}
temp=0;
j=y;
}
}
}
}
for(int j=1;j<=m;j++){
temp=0;
for(int i=1;i<=n;i++){
if(map[i][j]=='.'){
if(i>n-k+1){
continue;
}
else{
y=i;
while(map[y][j]=='.'&&y<=n){
temp++;
y++;
}
if(temp>=k){
num+=temp-k+1;
}
temp=0;
i=y;
}
}
}
}
if(k==1){
printf("%d\n",num/2);
}
else{
printf("%d\n",num);
}
}
return 0;
}
题目大意:输入n,m,k表示n*m的教室,.是空位,让你找连着的k个位置的情况。 题目思路:打这场CF的时候这题本来很早就过了..结果刚过完这题就被一个美国人hack了...然后debug一个小时都没找出错误...去上了个厕所想起来是不是可能没朋友..(题意是说帮自己和朋友占座以为至少需要2个位置啊啊啊)回来一看k的范围果然可以等于1...很难受..不过那次没掉分,还加了几分美滋滋...回到正题..这题咋写呢..其实比普通的dfs还简单点,都不用递归..直接横着找满足的个数,竖着找满足的个数,只不过k是1的时候需要特判,把结果除以二就行了.. 以下是代码:#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char map[2005][2005];
int main(){
int n,m,k,num,temp,y;
while(~scanf("%d%d%d",&n,&m,&k)){
memset(map,'0',sizeof(map));
num=0;
for(int i=1;i<=n;i++){
scanf("%s",map[i]+1);
}
for(int i=1;i<=n;i++){
temp=0;
for(int j=1;j<=m;j++){
if(map[i][j]=='.'){
if(j>m-k+1){
continue;
}
else{
y=j;
while(map[i][y]=='.'&&y<=m){
temp++;
y++;
}
if(temp>=k){
num+=temp-k+1;
}
temp=0;
j=y;
}
}
}
}
for(int j=1;j<=m;j++){
temp=0;
for(int i=1;i<=n;i++){
if(map[i][j]=='.'){
if(i>n-k+1){
continue;
}
else{
y=i;
while(map[y][j]=='.'&&y<=n){
temp++;
y++;
}
if(temp>=k){
num+=temp-k+1;
}
temp=0;
i=y;
}
}
}
}
if(k==1){
printf("%d\n",num/2);
}
else{
printf("%d\n",num);
}
}
return 0;
}
相关文章推荐
- CodeForces 616 C. The Labyrinth(dfs)
- codeforces 27E - Number With The Given Amount Of Divisors (数论 dfs)
- CodeForces 285 D.Permutation Sum(dfs)
- Codeforces_764_C. Timofey and a tree_(并查集)(dfs)
- codeforces 348B B. Apple Tree(dfs+数论)
- Codeforces 765E - Tree Folding 【树,dfs/bfs】
- codeforces 915 C. Permute Digits【DFS + 离散化】
- codeforces 915C Permute Digits (DFS)
- codeforces 862B Mahmoud and Ehab and the bipartiteness (DFS或带权并查集)
- 【codeforces 723D】【DFS (Floodfill)】D. Lakes in Berland【把多于k的连通块填起来,最外面的连通块直接忽视】
- 【CodeForces 149D】 【dp+dfs好题】D. Coloring Brackets【在限制条件下括号染色问题】
- codeforces 29C Mail Stamps(dfs)
- codeforces 731C(DFS)
- codeforces 395 D <思维,DFS想了半天超时>
- CodeForces - 510B Fox And Two Dots(DFS)
- Codeforces 780C Andryusha and Colored Balloons 搜索dfs
- CODEFORCES 430E Guess the Tree <dfs搜索建树>
- Codeforces 732F Tourist Reform【思维+边双联通+Dfs处理后继问题】好题!
- CodeForces - 327D Block Tower (dfs)
- CodeForces - 711D Directed Roads(dfs判环)