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 ...
随机推荐
- No-5.远程管理常用命令
远程管理常用命令 目标 关机/重启 shutdown 查看或配置网卡信息 ifconfig ping 远程登录和复制文件 ssh scp 01. 关机/重启 序号 命令 对应英文 作用 01 shut ...
- 获得Dictionary所有key和value值
Dictionary<string, string> dc = new Dictionary<string, string>(); dc.Add("code" ...
- avalon转成Vue
需求: 旧项目中有部分页面是用avalon写的,avalon存在页面刷新,会出现重复行的问题,数组渲染出现重复行bug, 需要转成vue 总结 记录了一下大概需要改的地方 1. avalon中的ms- ...
- canvas使用自定义字体没有效果
字体样式没有显示主要是因为字体还没有加载完成~ css @font-face { font-family: myFont; src: local('sen.ttf'), url("sen.t ...
- 数的计数(noip2001,动态规划递推)
题目链接: 普通版: https://www.luogu.org/problemnew/show/P1028 数据加强版: https://www.luogu.org/problemnew/show/ ...
- linux 作为web应用服务器内核参数/etc/sysctl.conf
# Kernel sysctl configuration file for Red Hat Linux## For binary values, 0 is disabled, 1 is enable ...
- tensorflow with gpu 环境配置
1.准备工作 1.1 确保GPU驱动已经安装 lspci | grep -i nvidia 通过此命令可以查看GPU信息,测试机已经安装GPU驱动
- C++实现链队类——合肥工业大学数据结构实验5:链式队列
实验5 5.1 实验目的 熟练掌握队列的顺序链式存储结构. 熟练掌握队列的有关算法设计,并在链队列上实现. 根据具体给定的需求,合理设计并实现相关结构和算法. 5.2 实验要求 5.2.1链队列实验要 ...
- C# Updating
闪开,这篇博文仅作笔记C#处理. 用来记录在学习/使用C#的过程中的Point,持续更新或成文后大幅删减 1,定义类,当声明类的对象后,类中的方法并不会被执行,构造函数会在声明类的对象时,被触发,没有 ...
- PL/SQL编程接触
1.认识PL/SQL 结构化查询语言(Structured Query Language,SQL)是用来访问和操作关系型数据库的一种标准通用语言,它属于第四代语言(4GL),简单易学,使用它可以很方便 ...