栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 1046 Double Vision

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 1046 Double Vision

#include <stdio.h>#include <iostream>using namespace std;char a[10][81];int n, r, c;int upper_bound;bool search(int x){    int begin = x * (c + 1);    int end = begin + c - 1;    for(int i = 0; i < r; i++){        for(int j = begin; j <= end; j++){ if(a[i][j] == 'o'){     int k = j;     while(k >= c + 1){         k -= (c + 1);     }     for(; k <= upper_bound; k += c + 1){         if(a[i][k] != '.' && k != j){  break;         }     }     if(k <= upper_bound){         continue;     }else{         a[i][j] = '#';         return true;     } }        }    }    for(int i = 0; i < r; i++){        for(int j = begin; j <= end; j++){ if(a[i][j] != 'o'){     continue; } for(int s = i; s < r; s++){     for(int t = (s == i ? j + 1: begin);   t <= end; t++){         if(a[s][t] != 'o'){  continue;         }         int k1 = j, k2 = t;         while(k1 >= c + 1){  k1 -= (c + 1);  k2 -= (c + 1);         }         for(; k1 <= upper_bound;       k1 += c + 1, k2 += c + 1){  if(a[i][k1] != '.' && a[s][k2] != '.'&& k1 != j){      break;  }         }         if(k1 <= upper_bound){  continue;         }else{  a[i][j] = '#';  a[s][t] = '#';  return true;         }     } }        }    }    return false;}int main(){    int i;    int cnt = 1;    while(scanf("%d%d%dn", &n, &r, &c) != EOF && n != 0){        printf("Test %dn", cnt++);        upper_bound = (c + 1) * (n - 1) + c - 1;        for(i = 0; i < r; i++){ fgets(a[i], 81, stdin);        }        for(i = 0; i < n; i++){ if(!search(i)){     printf("impossiblen");     break; }        }        if(i == n){ for(i = 0; i < r; i++){     printf("%s", a[i]); }        }    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/375837.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号