USACO castle
<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的更多相关文章
- USACO Section2.1 The Castle 解题报告
castle解题报告 —— icedream61 博客园(转载请注明出处)--------------------------------------------------------------- ...
- 【USACO 2.1】The Castle
/* TASK: castle LANG: C++ SOLVE: 深搜,注意每个方向对应值.枚举去掉的墙,然后再dfs,注意墙要复原,并且dfs里要判断是否超出边界. */ #include<c ...
- USACO The Castle
首先看一下题目. The CastleIOI'94 - Day 1 In a stroke of luck almost beyond imagination, Farmer John was sen ...
- USACO Section 2.1 The Castle
/* ID: lucien23 PROG: castle LANG: C++ */ /********************************************************* ...
- USACO Section 2.1 The Castle 解题报告
题目 题目描述 有一个城堡,城堡中有若干个房间,房间与房间之间用墙来进行分隔.现在我们需要统计这个城堡有多少个房间,并且还要找出最大的房间的面积是多少(一个单元格就代表一个单元面积).城堡的主人现在想 ...
- USACO 2.1 The Castle
题目大意:给你一个城堡让你求有多少房间,最大房间有多大,敲掉一堵墙后最大的房间有多大,敲掉那座墙 思路:比较恶心的bfs题,反正就是bfs使劲敲 /*{ ID:a4298442 PROB:castle ...
- [USACO Section 2.1]城堡 The Castle (搜索)
题目链接 Solution 比较恶心的搜索,思路很简单,直接广搜找联通块即可. 但是细节很多,要注意的地方很多.所以直接看代码吧... Code #include<bits/stdc++.h&g ...
- Usaco Training [2.1] The Castle 搜索
传送门 题目的输出的4个信息 前两个很容易,dfs,bfs都可以,图怎么建都可以 后两个在搜索的时候记录belong[i][j]和已有的size即可 代码应该比不少题解清晰吧 #include < ...
- 洛谷P1457 城堡 The Castle
P1457 城堡 The Castle 137通过 279提交 题目提供者该用户不存在 标签USACO 难度提高+/省选- 提交 讨论 题解 最新讨论 暂时没有讨论 题目描述 我们憨厚的USACO ...
随机推荐
- 通俗理解 模糊自适应PID
模糊自适应PID算法就是在经典的PID的基础上添加模糊控制规则库,建立这个库的目的就是算法能够自己来进行改变P.I.D的值. 就拿温度的上升过程控制来说,刚开始的时候,希望温度能够快速的升到终点温度, ...
- JavaSE-04 Java循环结构
学习要点 while循环 do-while循环 for循环 循环 什么是循环 循环的要素 while循环 语法分析 案例 老师每天检查小强的学习任务是否合格,如果不合格,则继续进行. 老师给小强安排的 ...
- linux 搜索文本
find -type f -name '*.php'|xargs grep '127.0.0.1' 搜索所有.php 内容 127.0.0.1 转自:http://www.cnblogs.com/w ...
- Exploded location overlaps an existing deployment解决办法
项目->properties->MyEclipse->Web->Web Context-root的名字为重命名之后的名字即可
- html5新增的定时器requestAnimationFrame
在requestAnimationFrame出现之前,我们一般都用setTimeout和setInterval,那么html5为什么新增一个requestAnimationFrame,他的出现是为了解 ...
- Java中的事务——全局事务与本地事务
转载,原文来源 http://www.hollischuang.com Java事务的类型有三种:JDBC事务.JTA(Java Transaction API)事务.容器事务.这是从事务的实现角度区 ...
- NYOJ448寻找最大数,贪心~~
寻找最大数 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 请在整数 n 中删除m个数字, 使得余下的数字按原次序组成的新数最大, 比如当n=92081346718538 ...
- POJ1780 Code
KEY公司开发出一种新的保险箱.要打开保险箱,不需要钥匙,但需要输入一个正确的.由n位数字组成的编码.这种保险箱有几种类型,从给小孩子玩的玩具(2位数字编码)到军用型的保险箱(6位数字编码).当正确地 ...
- PHP统计目录中文件个数和文件大小
<meta charset="utf-8"><?php $dirn = 0; //目录数 $filen = 0; //文件数 //用来统计一个目录下的文件和目录的 ...
- android GET 请求在5.0版本的取不到数据,报IO异常兼容问题解决
使用lib类库xUtils-2.6.10.jar作为数据请求的框架,在android的5.0版会有兼容问题,取不到GET请求的数据. 但是POST没有问题,难取到数据. public static R ...