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 ——————————————————————————————————————————————————————————题解
这是一道不需要任何优化的题
然而我不断的T
是因为我没读题……
题目中不止说了八连块,还说了当前要放置小奶牛的块不能有同种类的大奶牛
所以要不要放是九个块共同决定的……
【只有一组数据点还是样例!不走心!】
 /*
ID: ivorysi
LANG: C++
PROG: wissqu
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <set>
#include <vector>
#include <algorithm>
#define siji(i,x,y) for(int i=(x);i<=(y);++i)
#define gongzi(j,x,y) for(int j=(x);j>=(y);--j)
#define xiaosiji(i,x,y) for(int i=(x);i<(y);++i)
#define sigongzi(j,x,y) for(int j=(x);j>(y);--j)
#define inf 0x5f5f5f5f
#define ivorysi
#define mo 97797977
#define hash 974711
#define base 47
#define fi first
#define se second
#define pii pair<int,int>
#define esp 1e-10
typedef long long ll;
using namespace std;
char c[][];
int calc[][][];
int dirx[]={-,,,,,-,-,,};
int diry[]={,,-,,,-,,-,};
int num[]; bool used[][];
char tempchange[];
int row[],col[];
int ans;
bool flag;
void init() {
siji(i,,) {scanf("%s",c[i]+);}
siji(i,,) {
siji(j,,) {
siji(z,,) {
int xx=i+dirx[z],yy=j+diry[z];
if(xx>= && xx<= && yy>= && yy<=) {
++calc[xx][yy][c[i][j]-'A'+];
}
}
}
}
siji(i,,) num[i]=;
++num[];
}
void PRINT() {
siji(i,,) {
printf("%c %d %d\n",tempchange[i],row[i],col[i]);
}
}
void dfs(int dep) {
if(dep>) {
++ans;
if(!flag) {PRINT();flag=;}
return;
}
siji(z,,) {
if(num[z]==) continue;
siji(i,,) {
siji(j,,){
if(used[i][j]) continue;
if(calc[i][j][z]==) {
used[i][j]=;
--num[z];
siji(k,,) {
int xx=i+dirx[k],yy=j+diry[k];
if(xx>= && xx<= && yy>= && yy<=) {
--calc[xx][yy][c[i][j]-'A'+];
++calc[xx][yy][z];
}
}
if(!flag) {
tempchange[dep]='A'+z-;
row[dep]=i;
col[dep]=j;
} dfs(dep+);
used[i][j]=;
++num[z];
siji(k,,) {
int xx=i+dirx[k],yy=j+diry[k];
if(xx>= && xx<= && yy>= && yy<=) {
++calc[xx][yy][c[i][j]-'A'+];
--calc[xx][yy][z];
}
}
}
}
}
} }
void solve() {
init();
siji(i,,) {
siji(j,,) {
if(calc[i][j][]==) {
used[i][j]=;
--num[];
siji(k,,) {
int xx=i+dirx[k],yy=j+diry[k];
if(xx>= && xx<= && yy>= && yy<=) {
--calc[xx][yy][c[i][j]-'A'+];
++calc[xx][yy][];
}
}
if(!flag) {
tempchange[]='D';
row[]=i;
col[]=j;
}
dfs();
used[i][j]=;
++num[];
siji(k,,) {
int xx=i+dirx[k],yy=j+diry[k];
if(xx>= && xx<= && yy>= && yy<=) {
++calc[xx][yy][c[i][j]-'A'+];
--calc[xx][yy][];
}
}
}
}
}
printf("%d\n",ans);
}
int main(int argc, char const *argv[])
{
#ifdef ivorysi
freopen("wissqu.in","r",stdin);
freopen("wissqu.out","w",stdout);
#else
freopen("f1.in","r",stdin);
#endif
solve();
return ;
}
 

USACO 6.4 Wisconsin Squares的更多相关文章

  1. USACO 3.2 Magic Squares

    Magic SquaresIOI'96 Following the success of the magic cube, Mr. Rubik invented its planar version, ...

  2. USACO Section1.2 Palindromic Squares 解题报告

    palsquare解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------ ...

  3. USACO 1.2 Palindromic Squares (进制转换,回文)

    /* ID:twd30651 PROG:palsquare LANG:C++ */ #include<iostream> #include<fstream> #include& ...

  4. [hash-bfs]USACO 3.2 Magic Squares 魔板

    魔 板 魔板 魔板 题目描述 在成功地发明了魔方之后,拉比克先生发明了它的二维版本,称作魔板.这是一张有8个大小相同的格子的魔板: 1 2 3 4 8 7 6 5 我们知道魔板的每一个方格都有一种颜色 ...

  5. USACO 6.4 章节

    The Primes 题目大意 5*5矩阵,给定左上角 要所有行,列,从左向右看对角线为质数,没有前导零,且这些质数数位和相等(题目给和) 按字典序输出所有方案... 题解 看上去就是个 无脑暴搜 题 ...

  6. USACO6.4-Wisconsin Squares:搜索

    Wisconsin Squares It's spring in Wisconsin and time to move the yearling calves to the yearling past ...

  7. USACO 完结的一些感想

    其实日期没有那么近啦……只是我偶尔还点进去造成的,导致我没有每一章刷完的纪念日了 但是全刷完是今天啦 讲真,题很锻炼思维能力,USACO保持着一贯猎奇的题目描述,以及尽量不用高级算法就完成的题解……例 ...

  8. USACO 6.5 All Latin Squares

    All Latin Squares A square arrangement of numbers 1 2 3 4 5 2 1 4 5 3 3 4 5 1 2 4 5 2 3 1 5 3 1 2 4 ...

  9. 【USACO 3.2】Magic Squares

    题意 4*2个格子分别为 1234 8765 的魔板有3种操作,A:上下两排互换,B:最后一列放到第一列前面,C:中间四个顺时针旋转1格. 现在给出目标状态,找出最少步数可从原始状态到达目标状态,且输 ...

随机推荐

  1. 关于JSON的解析方式

    借鉴:站在巨人的肩膀上 一.json-lib json-lib最开始的也是应用最广泛的json解析工具,json-lib 不好的地方确实是依赖于很多第三方包,在Json.org网站上,Java可以使用 ...

  2. 新建springboot项目启动出错 Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

    错误信息入下: 2018-06-23 01:48:05.275 INFO 7104 --- [ main] o.apache.catalina.core.StandardService : Stopp ...

  3. Java并发编程原理与实战十七:AQS实现重入锁

    一.什么是重入锁 可重入锁就是当前持有锁的线程能够多次获取该锁,无需等待 二.什么是AQS AQS是JDK1.5提供的一个基于FIFO等待队列实现的一个用于实现同步器的基础框架,这个基础框架的重要性可 ...

  4. js封装Cookie操作

    var CookieUtil = { // 设置cookie set : function (name, value, expires, domain, path, secure) { var coo ...

  5. 网页制作中最有用的免费Ajax和JavaScript代码库

    网上看到的一篇小文,挺有用的,收藏在这. 本文中,我整理了12个免费的Ajax和JavaScript代码库,可以帮助Web开发人员将应用程序提升到一个新水平. Ajax Instant Messeng ...

  6. #error#优化#Model#理解下面这句话错误所导致的错误:"传入一个对象,那么你就拥有了对象的属性"2

    CHENYILONG Blog #error#优化#Model#理解下面这句话错误所导致的错误:"传入一个对象,那么你就拥有了对象的属性"2 © chenyilong. Power ...

  7. 【方法】jQuery无插件实现 鼠标拖动切换图片/内容 功能

    前言 我就想随便叨逼叨几句,爱看就看几句,不爱看就直接跳过看正文就好啦~ 这个方法是仿写页面时我自己研究出来,可能有比我更简单的方法. 但我不管,因为我没查我不知道,我就觉得我的最好啦,耶耶耶~ 效果 ...

  8. 【多视图几何】TUM 课程 第3章 透视投影

    课程的 YouTube 地址为:https://www.youtube.com/playlist?list=PLTBdjV_4f-EJn6udZ34tht9EVIW7lbeo4 .视频评论区可以找到课 ...

  9. 简单对象List自定义属性排序

    <body> <div> sort()对数组排序,不开辟新的内存,对原有数组元素进行调换 </div> <div id="showBox" ...

  10. Dream------Java--ant zip 对压缩文件进行指定位置的修改

    ant zip 对压缩文件进行指定位置的修改 实现功能: 对2中文件进行修改: 需求: 在XX文件中,从二进制流的200字节位置开始,往后的30位字节数量.插入一个值 由于涉及到公司内部,不方便写太多 ...