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 ...
随机推荐
- js数字转金额,ajax调用接口,后台返回html(完整页面),打开新窗口并写入html
一.转换成金额形式 function toMoney(num){ if(num){ if(isNaN(num)) { alert("金额中含有不能识别的字符"); return; ...
- PHP23 AJAX分页
模型代码设计 以留言信息管理为例. 获取根据条件查询记录总数和分页数据. <?php namespace application\admin\models; use core\mybase\Mo ...
- Linux-03 Linux下的tar命令
功能说明 用来建立,还原备份文件的工具程序,它可以加入,解开备份文件内的文件 参数 -c: 建立压缩档案 -x:解压 -t:查看内容 -r:向压缩归档文件末尾追加文件 -u:更新原压缩包中的文件 这五 ...
- Perl: hash散列转换为Json报错集, perl.c,v $$Revision: 4.0.1.8 $$Date: 1993/02/05 19:39:30 $
bash-2.03$ ./u_json.pl Can't locate object method "encode" via package "JSON" at ...
- Spring框架 (log4j :WARN No appenders could be found for logger log4j:WARN Please initialize the log4j system properly.)问题解决
Spring框架需要的jar包 1.Spring压缩包中的四个核心JAR包 beans .context.core 和expression 下载地址: https://pan.baidu.com/s/ ...
- [IOS初学]ios 第一篇 storyboard 与viewcontroller的关系 - Zoe_J
时间 2014-07-27 16:08:00 博客园-所有随笔区 原文 http://www.cnblogs.com/zoe-j/p/3871501.html 主题 StoryBoard 学习了一 ...
- 遇到的django问题
问题1: No migrations to apply 删除了migrations中0001_initial.py文件,重新执行 python manage.py makemigrations pyt ...
- 10MongoDB
一. 介绍MongoDB 1. NoSQL 1)“NoSQL”⼀词最早于1998年被⽤于⼀个轻量级的关系数据库的名字 随着web2.0的快速发展, NoSQL概念在2009年被提了出来 2)NoSQ ...
- Mysql数据库事件使用与示例
1 事件简介 事件(event)是MySQL在相应的时刻调用的过程式数据库对象.一个事件可调用一次,也可周期性的启动,它由一个特定的线程来管理的,也就是所谓的“事件调度器”. 事件和触发器类似,都是在 ...
- mysql 报错:ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA
解决办法:设置临时环境变量 ;