<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. C++内联函数的使用

    1.为什么要用内联函数? 在C++中我们通常定义以下函数来求两个整数的最大值: int max(int a, int b) { return a > b ? a : b; } 为这么一个小的操作 ...

  2. OPENCV3 命名空间等变化

    CV_VERSION 表示的opencv的版本号 命名空间变化:  可以通过增加 #include <cv.h> 解决 1 直接去掉CV_ 前缀 1) nameWindow 函数    C ...

  3. MFC模态框关闭时出现断言报错!

    我尝试一个老的主对话框上创建另一个新的模态对话框并结束对话框,然后包含创建模态对话框的函数体执行结束时,我出现了这个断言失败! 原因:使用PostQuitMessage(1),导致出现上述问题:或者别 ...

  4. 洛谷P1035 级数求和

    #include <iostream> using namespace std; int main(){ long k,i; cin >> k; double s=0.0; ; ...

  5. IDEA ctrl+alt+L 格式化快捷键无效时解决

    这几天发现自己Intellij IDEA ctrl+alt+L格式化代码无效 设置里面按照快捷键搜索 按了 ctrl+alt+L 也没反应 但是我设置的确实是默认的 ctrl+alt+L 最后终于找到 ...

  6. python 06 8/28-8/30

    六 函数的返回值,使用return返回数据,可以同时返回多个数据,将会以元组的形式返回到函数的调用处.return 具有返回数据和中止程序的作用! return 后不加任何数据则返回None ,判定为 ...

  7. 计蒜客 Overlapping Rectangles (离散化)

    题意: 给定一个坐标系, 给出n个矩形的左下角坐标(bx,by)和右上角坐标(tx,ty) , 求矩形覆盖的面积, 有些区域会被多个矩形覆盖, 但只用算一次. n <= 1000,  0 < ...

  8. NYOJ-487月老的烦恼(1)类似于素数筛法一样的打表及一种筛法核心代码。。

    月老的烦恼(1) 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 月老最近遇到了一个很棘手的问题,就是"剩男""剩女"急速增长,而 ...

  9. Personal Recommendation Using Deep Recurrent Neural Networks in NetEase读书笔记

    一.文章综述 1.研究目的:实现网易考拉电商平台的商品高效实时个性化推荐.缩短用户与目标商品的距离,让用户点击最少的页面就可以得到想要的商品 2.研究背景:基于用户和基于物品的协同过滤(Collabo ...

  10. 【概率dp】D. Card Collector

    https://www.bnuoj.com/v3/contest_show.php?cid=9147#problem/D [题意] 为了集齐n张卡片,必须要买多少袋零食?题目给定每种卡片出现在零食中的 ...