<pre name="code" class="cpp"><pre>USER: Kevin Samuel [kevin_s1]
TASK: castle
LANG: C++ Compiling...
Compile: OK Executing...
Test 1: TEST OK [0.003 secs, 3688 KB]
Test 2: TEST OK [0.005 secs, 3688 KB]
Test 3: TEST OK [0.008 secs, 3688 KB]
Test 4: TEST OK [0.008 secs, 3688 KB]
Test 5: TEST OK [0.003 secs, 3688 KB]
Test 6: TEST OK [0.005 secs, 3688 KB]
Test 7: TEST OK [0.014 secs, 3688 KB]
Test 8: TEST OK [0.005 secs, 3688 KB] All tests OK.
<p>Your program ('castle') produced all correct answers! This is your
submission #4 for this problem. <strong>Congratulations!</strong></p>


/*
ID:kevin_s1
PROG:castle
LANG:C++
*/ #include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <list>
#include <queue>
#include <cmath> using namespace std; #define MAXM 100 //gobal variable====
int M,N;
int direct[4][2] = {{-1, 0},{1, 0},{0, 1},{0, -1}};
//north, south, east, west
int castle[MAXM][MAXM];
int visited[MAXM][MAXM];
int visited2[MAXM][MAXM];
int visited3[MAXM][MAXM];
int hasWall[MAXM][MAXM][4];
int cnt, maxarea;
int _count;
//================== //function========== void Dec(){
for(int i = 1; i <= N; i++){
for(int j = 1; j <= M; j++){
int wall = castle[i][j];
if(wall >= 8){
hasWall[i][j][1] = 1;
wall = wall - 8;
}
if(wall >= 4){
hasWall[i][j][2] = 1;
wall = wall - 4;
}
if(wall >= 2){
hasWall[i][j][0] = 1;
wall = wall - 2;
}
if(wall >= 1){
hasWall[i][j][3] = 1;
wall = wall - 1;
}
}
}
} void DFS(int x, int y, int type){
if(x < 1 || x > N || y < 1 || y > M)
return;
if(visited[x][y] != 0)
return;
visited[x][y] = type;
visited2[x][y] = type;
_count++;
if(_count > maxarea){
maxarea = _count;
}
for(int d = 0; d < 4; d++){
if(hasWall[x][y][d] == 0){
int xx = x + direct[d][0];
int yy = y + direct[d][1];
DFS(xx, yy, type);
}
}
return;
} void DFS1(int x, int y, int type, int color){
if(x < 1 || x > N || y < 1 || y > M)
return;
if(visited[x][y] != type)
return;
if(visited3[x][y] == 1)
return;
visited[x][y] = color;
visited3[x][y] = 1;
for(int d = 0; d < 4; d++){
if(hasWall[x][y][d] == 0){
int xx = x + direct[d][0];
int yy = y + direct[d][1];
DFS1(xx, yy, type, color);
}
}
return;
} void print(){
for(int i = 1; i <= N; i++){
for(int j = 1; j <= M; j++){
cout<<visited[i][j]<<" ";
}
cout<<endl;
}
} void print2(){
for(int i = 1; i <= N; i++){
for(int j = 1; j <= M; j++){
cout<<visited2[i][j]<<" ";
}
cout<<endl;
}
}
//================== int main(){
freopen("castle.in","r",stdin);
freopen("castle.out","w",stdout);
cin>>M>>N;
for(int i = 1; i <= N; i++){
for(int j = 1; j <= M; j++){
cin>>castle[i][j];
}
}
memset(hasWall, 0, sizeof(hasWall));
memset(visited, 0, sizeof(visited));
memset(visited2, 0, sizeof(visited2));
memset(visited3, 0, sizeof(visited3));
Dec();
cnt = 0;
maxarea = 0;
int type = 1;
for(int i = 1; i <= N; i++){
for(int j = 1; j <= M; j++){
if(visited[i][j] == 0){
_count = 0;
DFS(i, j, type);
cnt++;
DFS1(i, j, type, _count);
type++;
}
}
}
cout<<cnt<<endl;
cout<<maxarea<<endl;
//print2();
//print();
//enum the wall
int mmaxarea = 0;
int tx = 0, ty = 0, dir = 0;
for(int x = 1; x <= N; x++){
for(int y = M; y >= 1; y--){
for(int d = 0; d < 4; d++){
if(hasWall[x][y][d] == 1){
int xx = x + direct[d][0];
int yy = y + direct[d][1];
if(xx >= 1 && xx <= N && yy >= 1 && yy <= M){
if((visited[x][y] + visited[xx][yy]) > mmaxarea && (visited2[x][y] != visited2[xx][yy])){
mmaxarea = visited[x][y] + visited[xx][yy];
tx = x;
ty = y;
dir = d;
}
if((visited[x][y] + visited[xx][yy]) == mmaxarea && (visited2[x][y] != visited2[xx][yy])){
if(y < ty){
tx = x;
ty = y;
dir = d;
}
if(y == ty && x > tx){
tx = x;
ty = y;
dir = d;
}
}
}
}
}
}
}
cout<<mmaxarea<<endl;
if(dir == 1){
tx = tx + 1;
dir = 0;
}
if(dir == 3){
ty = ty - 1;
dir = 2;
}
cout<<tx<<" "<<ty<<" ";
if(dir == 0)
cout<<"N"<<endl;
if(dir == 2)
cout<<"E"<<endl;
return 0;
}

USACO castle的更多相关文章

  1. USACO Section2.1 The Castle 解题报告

    castle解题报告 —— icedream61 博客园(转载请注明出处)--------------------------------------------------------------- ...

  2. 【USACO 2.1】The Castle

    /* TASK: castle LANG: C++ SOLVE: 深搜,注意每个方向对应值.枚举去掉的墙,然后再dfs,注意墙要复原,并且dfs里要判断是否超出边界. */ #include<c ...

  3. USACO The Castle

    首先看一下题目. The CastleIOI'94 - Day 1 In a stroke of luck almost beyond imagination, Farmer John was sen ...

  4. USACO Section 2.1 The Castle

    /* ID: lucien23 PROG: castle LANG: C++ */ /********************************************************* ...

  5. USACO Section 2.1 The Castle 解题报告

    题目 题目描述 有一个城堡,城堡中有若干个房间,房间与房间之间用墙来进行分隔.现在我们需要统计这个城堡有多少个房间,并且还要找出最大的房间的面积是多少(一个单元格就代表一个单元面积).城堡的主人现在想 ...

  6. USACO 2.1 The Castle

    题目大意:给你一个城堡让你求有多少房间,最大房间有多大,敲掉一堵墙后最大的房间有多大,敲掉那座墙 思路:比较恶心的bfs题,反正就是bfs使劲敲 /*{ ID:a4298442 PROB:castle ...

  7. [USACO Section 2.1]城堡 The Castle (搜索)

    题目链接 Solution 比较恶心的搜索,思路很简单,直接广搜找联通块即可. 但是细节很多,要注意的地方很多.所以直接看代码吧... Code #include<bits/stdc++.h&g ...

  8. Usaco Training [2.1] The Castle 搜索

    传送门 题目的输出的4个信息 前两个很容易,dfs,bfs都可以,图怎么建都可以 后两个在搜索的时候记录belong[i][j]和已有的size即可 代码应该比不少题解清晰吧 #include < ...

  9. 洛谷P1457 城堡 The Castle

    P1457 城堡 The Castle 137通过 279提交 题目提供者该用户不存在 标签USACO 难度提高+/省选- 提交  讨论  题解 最新讨论 暂时没有讨论 题目描述 我们憨厚的USACO ...

随机推荐

  1. Selenium3+python自动化008-操作浏览器基本方法

    一.打开网站1.第一步:从selenium里面导入webdriver模块2.打开Firefox浏览器(Ie和Chrome对应下面的)3.打开百度网址二.页面刷新1.有时候页面操作后,数据可能没及时同步 ...

  2. spring中bean的配置详解--定义parent

    在工作中碰到了好多的配置文件,具体来说是spring 中bean配置的parent的配置,搞的我一头雾水,仔细看一下spring中有关bean的配置,剖析一下,具体什么含义! 一.Spring IoC ...

  3. RTSP详解

    关于 RTSP. RTSP协议是一个非常类似HTTP协议的流控制协议.它们都使用纯文本来发送信息,而且rtsp协议的语法也和HTTP类似.Rtsp一开始这样设计,也是为了能够兼容使用以前写的HTTP协 ...

  4. 洛谷——P3939 数颜色(暴力vecotr+二分)

    P3939 数颜色 $vecotr$里二分就是好用,全是$STL$ 颜色数目比较少,可以对每一种颜色弄一个$vector$记录一下,查找$l,r$内颜色数为$x$的兔子数,直接在$G[x]$这个$ve ...

  5. 如何让线程A等待B执行结束后执行?

    1. 使用条件变量 判断是否任务B已经做完,然后再执行任务A. 测试代码可看:https://blog.csdn.net/guochao6531/article/details/78075882 2. ...

  6. 3. COLLATIONS

    3. COLLATIONS 表COLLATIONS提供有关每个字符集排序规则的信息.下表中SHOW Name对应SHOW COLLATION. INFORMATION_SCHEMA Name SHOW ...

  7. oslo.messaging

    oslo.messaging oslo.messaging库为OpenStack各个项目使用RPC和事件通知(Event Notification)提供了一套统一的接口.代码库位于https://gi ...

  8. c++_包子凑数

    标题:包子凑数 小明几乎每天早晨都会在一家包子铺吃早餐.他发现这家包子铺有N种蒸笼,其中第i种蒸笼恰好能放Ai个包子.每种蒸笼都有非常多笼,可以认为是无限笼. 每当有顾客想买X个包子,卖包子的大叔就会 ...

  9. qt 线程简单学习

    QThread线程,只需继承QThread类,并重载run方法,之后就可以使用了. #ifndef THREAD_H #define THREAD_H #include <QThread> ...

  10. Tiny4412 U-BOOT移植(转)

    http://blog.csdn.net/eshing/article/details/37520291(转) 一.移植前说明: 1.  特别声明:此文档是我的学习文档,里面肯定有错误地方,仅供参考! ...