usaco6.4.3 Wisconsin Squares

usaco题解+程序 里面有usaco前几节的程序和代码,欢迎使用,希望对你有所帮主。 立即下载

一 原题

Wisconsin Squares

It's spring in Wisconsin and time to move the yearling calves to the yearling pasture and last year's yearlings to the greener pastures of the north 40.

Farmer John has five kinds of cows on his farm (abbreviations are shown in parentheses): Guernseys (A), Jerseys (B), Herefords (C), Black Angus (D), and Longhorns (E). These herds are arranged on the 16 acre pasture, one acre for each small herd, on a 4 x 4 grid (labeled with rows and columns) like this:

              1 2 3 4
             +-------
            1|A B A C
            2|D C D E
            3|B E B C
            4|C A D E

In the initial pasture layout, the herds total 3 A's, 3 B's, 4 C's, 3 D's, and 3 E's. This year's calves have one more D herd and one fewer C herd, for a total of 3 A's, 3 B's, 3 C's, 4 D's, and 3 E's.

FJ is extremely careful in his placement of herds onto his pasture grid. This is because when herds of the same types of cows are too close together, they misbehave: they gather near the fence and smoke cigarettes and drink milk. Herds are too close together when they are on the same square or in any of the eight adjacent squares.

Farmer John must move his old herd out of the field and his new herd into the field using his old brown Ford pickup truck, which holds one small herd at a time. He picks up a new herd, drives to a square in the yearling pasture, unloads the new herd, loads up the old herd, and drives the old herd to the north 40 where he unloads it. He repeats this operation 16 times and then drives to Zack's for low-fat yogurt treats and familiar wall decor.

Help Farmer John. He must choose just exactly the correct order to replace the herds so that he never puts a new herd in a square currently occupied by the same type of herd or adjacent to a square occupied by the same type of herd. Of course, once the old cows are gone and the new cows are in place, he must be careful in the future to separate herds based on the new arrangement.

Very important hint: Farmer John knows from past experience that he must move a herd of D cows first.

Find a way for Farmer John to move the yearlings to their new pasture. Print the 16 sequential herd-type/row/column movements that lead to a safe moving experience for the cows.

Calculate the total number of possible final arrangements for the 4x4 pasture and calculate the total number of ways those arrangements can be created.

PROGRAM NAME: wissqu

TIME LIMIT: 5 seconds

INPUT FORMAT

Four lines, each with four letters that denote herds.

SAMPLE INPUT (file wissqu.in)

ABAC
DCDE
BEBC
CADE

OUTPUT FORMAT

16 lines, each with a herd-type, row and column. If there are multiple solutions (and there are), you should output the solution for which the concatenated string ("D41C42A31 ... D34") of the answers is first in lexicographic order.

One more line with the total number of ways these arrangements can be created.

SAMPLE OUTPUT (file wissqu.out)

D 4 1
C 4 2
A 3 1
A 3 3
B 2 4
B 3 2
B 4 4
E 2 1
E 2 3
D 1 4
D 2 2
C 1 1
C 1 3
A 1 2
E 4 3
D 3 4
14925


二 分析

给定一张4*4的地图,地图上每一格只能是A-E的字母,初始数量分别为{3,3,4,3,3},要求每次修改一格,使得最终数量为{3,3,3,4,3},修改要求有两个:

1)第一次必须写入一个D;

2)每次在(i,j)写入字母c时,需保证(i,j)自身以及相邻的8格内都不含有c;

输出字典序的修改序列以及全部修改序列的数量。

挺无聊的一道搜索题,也不需要什么剪枝。只有一组测试样例。


三 代码

运行结果:

USER: Qi Shen [maxkibb3]
TASK: wissqu
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [1.708 secs, 4300 KB]

All tests OK.

Your program ('wissqu') produced all correct answers! This is yoursubmission #3 for this problem. Congratulations!


AC代码:

/*
ID:maxkibb3
LANG:C++
PROB:wissqu
*/

#include<iostream>
#include<fstream>
#include<vector>

using namespace std;

#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int dx[9][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {0, 0},
				{-1, -1}, {-1, 1}, {1, -1}, {1, 1}};

ifstream fin("wissqu.in");
ofstream fout("wissqu.out");
string s[4];
bool vis[4][4];
int tot, num[5] = {3, 3, 3, 4, 3};
vector<pair<char, pii> > trace;

inline bool legal(int x, int y) {
	return (x >= 0 && x < 4 && y >= 0 && y < 4);
}

inline bool check(char c, int x, int y) {
	if(vis[x][y] || num[c - 'A'] == 0) {
		return false;
	}
	for(int i = 0; i < 9; i++) {
		int nx = x + dx[i][0], ny = y + dx[i][1];
		if(legal(nx, ny) && c == s[nx][ny]) {
			return false;
		}
	}
	return true;
}

void dfs(char c) {
    if(trace.size() == 16) {
        tot++;
        if(tot == 1) {
            for(int i = 0; i < 16; i++) {
                pair<char, pii> item = trace[i];
                fout << item.fi << " " << item.se.fi + 1 << " " << item.se.se + 1 << endl;
            }
        }
        return;
    }
    for(int i = 0; i < 4; i++) {
        for(int j = 0; j < 4; j++) {
            if(check(c, i, j)) {
                char ori = s[i][j];
                s[i][j] = c;
                num[c - 'A']--;
                vis[i][j] = true;
                trace.pb(mp(c, mp(i, j)));
                for(int k = 0; k < 5; k++) {
                    if(num[k] > 0) {
                        dfs('A' + k);
                    }
                }
                if(trace.size() == 16) {
                    dfs('A');
                }
                trace.pop_back();
                vis[i][j] = false;
                num[c - 'A']++;
                s[i][j] = ori;
            }
        }
    }
}

int main() {
	for(int i = 0; i < 4; i++) {
		fin >> s[i];
	}
	dfs('D');
	fout << tot << endl;
	return 0;
}


NTFS分区变成RAW别乱修!正确数据恢复与修复方法详解 文件系统是操作系统管理存储数据的核心机制,NTFS作为Windows主流文件系统,一旦分区识别异常,常会显示为RAW格式。分区变RAW通常意味着文件系统入口信息损坏,而非数据物理消失,但若采用错误的修复方式,如直接对RAW分区执行chkdsk /f,可能因系统无法正确识别文件系统结构,导致写入操作落在错误偏移位置,二次破坏本可恢复的数据。正确的处理思路是:先停止一切写入操作,通过扇区级镜像备份保留原始现场,再分析DBR、分区表及$MFT状态,依据诊断结果选择修复或深度扫描恢复。实际排查中,常见问题如DBR记 阅读详情

相关推荐

3D IC中Memory-on-Logic堆叠测试的DFT解决方案与工程实践

在半导体行业,随着摩尔定律逼近物理极限,3D IC技术通过芯片垂直堆叠实现性能提升和异构集成,已成为重要发展方向。其核心原理是利用硅通孔(TSV)或微凸块实现芯片间电气互连,将多个不同功能的芯片(如逻辑芯片与存储芯片)集成在一个封装内。这项技术的核心价值在于能大幅提升系统性能、降低功耗并实现更小的封装尺寸。然而,芯片堆叠后,传统的测试方法面临巨大挑战,尤其是测试访问存在物理屏障,无法直接探测被覆盖的芯片接口。为此,可测试性设计(DFT)成为确保3D IC可靠性与量产可行性的关键技术。它通过在设计阶段植入专用

weixin_42521058的博客 631

USACO 6.4 Wisconsin Squares

Wisconsin Squares It's spring in Wisconsin and time to move the yearling calves to the yearling pasture and last year's yearlings to the greener pastures of the north 40. Farmer John has five k...

weixin_30408739的博客 174

Mplus实战:三变量随机截距交叉滞后模型(RI-CLPM)语法详解与扩展

本文详细解析了Mplus中三变量随机截距交叉滞后模型(RI-CLPM)的构建原理与语法实现。通过将变量分解为稳定的个体间差异与动态的个体内波动,模型能更纯净地揭示多变量间的纵向交互影响。文章以工作压力、睡眠质量与工作满意度为例,提供了完整的语法模板、关键参数设置(如NOCOV命令、残差相关)及结果解读指南,帮助研究者避开常见误区,稳健分析复杂动态关系。

wdx0123456的博客 926

USACO Section 5.2 Wisconsin Squares - 按要求DFS就行了..

这题真搞~就一组数据....囧~~~ 按他的要求枚举搜索就ok了..当然要输出字典序最小的解~~~那就按字典序来搜索..除了最开始是确定D..后面的都是先确定较小的A,B,C,D,E..再确定较小的Y..再确定较小的X...如此搜出的第一个解就是字典序最小的答案... 开始还想着Hash...结果写完了样例过了...一交就A了...似乎这题不需要Hash.. P...

huobengle 240

标准工时精益化管理:理论、方法与技巧

ECRS工时分析软件是一款综合性软件,包含了IE软件、IE改善软件、工业工程软件、作业改善/业务改善软件、动作分析软件、作业分析软件、ECRS分析法、ECRS改善手法、时间测量软件、工时测量软件、标准工时计算软件等功能。理论上,标准工时是指在标准的工作环境下,完成一道加工工序所需要花费的人工时间。不同企业、不同工序需要的辅助作业时间和损耗时间各不相同,因此企业需要灵活运用标准工时公式进行计算。总之,标准工时的制定需要综合考虑多种因素,企业可以灵活运用本文介绍的方法和技巧来优化制定流程。

VIOOVI_ECRS的博客 847

【Windows】 解决联想为主的所有自带摄像头(integrate camera)打不开的毛病(特别点名小新、thinkbook、thinkpad、y7000...)

解决联想系列电脑打不开自带摄像头的问题

Iamruzi的csdn博客 3万+

usaco 5.2 Wisconsin Squares(DFS)

Wisconsin Squares It's spring in Wisconsin and time to move the yearling calves to the yearling pasture and last year's yearlings to the greener pastures of the north 40. Farmer John has five kind

志当存高远 1116

【AUTOSAR OS】调度表管理模块深度解析

本文深入解析AUTOSAR OS调度表的实现机制。调度表通过预定义到期点序列控制任务激活时序,支持周期性执行、多核协同和容错处理。核心数据结构包括调度表控制块(STCB)、配置结构和到期点动作。关键函数涵盖初始化、启动、到期点处理及链表管理,采用O(n)时间复杂度。以发动机控制为例展示配置与使用方式,并探讨显式同步、时间容错等高级特性。最后提出EP数量控制、链表优化等性能建议,为汽车ECU时间触发系统开发提供参考。

1605

USACO2020DEC第五题(Rectangular Pasture)题解

题目 题目描述 Farmer John 最大的牧草地可以被看作是一个由方格组成的巨大的二维方阵(想象一个巨大的棋盘)。现在,有 N 头奶牛正占据某些方格(1≤N≤2500)。 Farmer John 想要建造一个可以包围一块矩形区域的栅栏;这个矩形必须四边与 x 轴和 y 轴平行,最少包含一个方格。请帮助他求出他可以包围在这样的区域内的不同的奶牛子集的数量。注意空集应当被计算为答案之一。 输入格式 输入的第一行包含一个整数 N。以下 N 行每行包含两个空格分隔的整数,表示一头奶牛所在方格的坐标 (x,y)。

风斯在下 2089

2022年12月机器人技术等级考试试卷(三级实操) 试题解析

2022年12月机器人技术等级考试试卷(三级实操) 试题解析

http://www.cierobot.com 1522

MySQL——cost成本计算之MySQL如何选择使用索引(trace)

文章目录前言trace工具分析执行计划 前言 在之前博客中,根据测试案例,发现同样的sql语句,因为传入的条件值的不同,导致MySQL有时候选择使用索引,有时候又不适用索引。 如下所示sql的执行计划: EXPLAIN SELECT * FROM employees WHERE name > 'aaa'; EXPLAIN SELECT * FROM employees WHERE name > 'zzzz'; 在MySQL中,为什么会出现上述这种玄乎的现象呢? 本篇博客重点说明原因。 在说

专注写bug 679

Wisconsin Squares [USACO]

这个也不记得了,反正不难 /* ID: zhangyc1 LANG: C++ TASK: wissqu */ #include <string> #include <cstring> #include <cstdlib> #include <cstdio> #include <cmath> using na...

weixin_30521161的博客 242

Apifox接口测试+自动化测试

Apifox 接口测试+自动化测试快速入门!

程序员小杨哥的博客 1万+

[USACO 6.4.3]Wisconsin Squares

题解   暴搜即可. 代码 /* TASK:wissqu LANG:C++ */ #include <cstdio> #include <cstring> using namespace std; char matrix[8][8], path[16][10]; bool v[4][4], flag; int ans, num[5] = ...

weixin_30933531的博客 146

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

USACO6.4.3 Wisconsin Squares(wissqu)

按题目的要求搜索就好了,时限5s,基本用不着优化吧 (但是奇怪的是只有一个测试点,并且0.54s就过了) 既然要求字典序最小,除了第一位是d,后续的就是按字典序来枚举搜索咯 /* ID: xsy97051 PROG: wissqu LANG: C++ */ #include #include #include using namespace std; const int dx

xsy_victory的专栏 411

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

USACO 6.4.1 Wisconsin Squares 暴力

http://train.usaco.org/usacoprob2?a=VNPgIbuqM60&amp;S=wissqu题目大意:一个4*4的牧场有ABCDE五种奶牛,其中C4个别的各3个,现在要用另一批奶牛替换这一批,其中D4个别的各3个,要求用来替换的奶牛种类和当前种类不同并且和周围八个格子的种类也不同(原本的奶牛分布同样满足这个条件),并且第一个用于替换的是D种类,要求输出字典序最小的替换顺...

Frontier_Setter的博客 338

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

USACO SECTION 5.2 Wisconsin Squares

Wisconsin Squares It's spring in Wisconsin and time to move the yearling calves to the yearling pasture and last year's yearlings to the greener pastures of the north 40. Farmer John has five kind

457

USACO6.4-Wisconsin Squares:搜索

Wisconsin Squares It's spring in Wisconsin and time to move the yearling calves to the yearling pasture and last year's yearlings to the greener pastures of the north 40. Farmer John has ...

weixin_30655219的博客 135

USACO 5.2 Wisconsin Squares(DFS)

好扯淡。。。 1 /* 2 ID: cuizhe 3 LANG: C++ 4 TASK: wissqu 5 */ 6 #include <iostream> 7 #include <cstdio> 8 #include <cstring> 9 #include <queue> 10 ...

weixin_30371875的博客 103

USACO Section 1.2 Name That Number

在一个名为“dict.txt”的文件中提供了牛的可接受的名称,其中包含少于5,000个可接受的牛名称(所有字母大写)的列表。拿一个牛的品牌号码,并报告该数字地图在给定字典中的所有可能字词,该字典在分级环境中以dict.txt提供(并按升序排序)。牛手不喜欢这个档案系统的优点,而且希望以一个愉快的名字叫他们的牧群,而不是说:“#4734,相处”。编写一个给定牛的品牌编号的程序,并打印可以从该品牌编号生成的所有有效名称,如果没有有效名称,则打印“NONE”。长度为1至12位数字的单行。

YanLucyqi的博客 501

Wisconsin Squares

题意:摘自NOCOW翻译(http://www.nocow.cn/index.php/Translate:USACO/fence3) 描述 农夫约翰已经决定建造电网。他已经把他的农田围成一些奇怪的形状,现在必须找出安放电源的最佳位置。 对于每段电网都必须从电源拉出一条电线。电线可以穿过其他电网或者跨过其他电线。电线能够以任意角度铺设,从电源连接到一段电网的任意一点上(也就是,这段

原味 1495

洛谷——P2912 [USACO08OCT]牧场散步Pasture Walking(lca)

题目描述 The N cows (2 <= N <= 1,000) conveniently numbered 1..N are grazing among the N pastures also conveniently numbered 1..N. Most conveniently of all, cow i is grazing in pasture i. Some pai...

weixin_34124651的博客 218

USACO Wisconsin Squares 解题报告

USER: chen chen [thestor1] TASK: wissqu LANG: C++ Compiling... Compile: OK Executing... Test 1: TEST OK [2.206 secs, 3504 KB] All tests OK. YOUR PROGRAM ('wissqu') WORKED FIRST TIME! That's fan

thestoryofsnow的专栏 757

#Leetcode# 633. Sum of Square Numbers

https://leetcode.com/problems/sum-of-square-numbers/ Given a non-negative integerc, your task is to decide whether there're two integersaandbsuch that a2+ b2= c. Example 1: Input: 5 Outp...

weixin_30265103的博客 144

洛谷P2202 [USACO13JAN]方块重叠Square Overlap

题目描述 Farmer John is planning to build N (2 <= N <= 50,000) square fenced-in pastures on his farm, each of size exactly K x K (1 <= K <= 1,000,000). Pasture i is centered at point (x_i, y_...

weixin_30698297的博客 220

B. Black Square(字符串)

B. Black Square time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Polycarp has a checkered sheet of paper of...

weixin_33815613的博客 179
上一篇: cf 906A Shockers
下一篇: usaco6.5.1 All Latin Squares
max_kibble
博客等级 码龄11年 2粉丝 110原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值