USACO section 2.4 The Tamworth Two(算模拟吧)

库存管理基于Excel的多商品组合订单需求拆解模型:SKU级供需预测与四情景压力测试系统设计 Excel 多商品组合订单的需求拆解|Excel模型与模拟数据 内容概要:本文档围绕Excel中多商品组合订单的基础SKU需求拆解,构建从订单行、组合用量表到仓库周需求、期初可供、计划到货及欠交结转的完整计算链条。通过四种组合、六种SKU、两座仓库和八个业务周的模拟数据,演示如何将组合套数准确转换为SKU件数,防止重复扣减与错误状态纳入,并按周递推供需覆盖与欠交变化。文档提供结构化输入校验、公式体系、守恒检查与四情景复算机制,确保结果可追溯、可核对。全部数据为基于固定随机种子生成的原创模拟记录,配套可编辑Excel工作簿与独立Python程序实现双向验证。 适合人群:适用于负责订单汇总、组合商品管理、库存分析、仓配协同、需求计划及业务分析文档编制的相关人员。日常使用者需掌握Excel基本操作如单元格引用、筛选与求和;具备Python基础者可配合标准库运行程序进行批量验证或数据重生成。业务管理岗可重点阅读结果与风险章节,结合工作表索引追踪数值来源。 使用场景及目标:适用于活动套单、同单含组合与单品、多仓备货、到货周期偏移及需求波动等场景。目标是实现组合订单向基础SKU的精准拆解,按周粒度完成供需匹配与欠交递推,识别输入冲突与窗口外到货影响,支持需求增幅、到货延期等多情景模拟分析,所有结论均可从源订单、BOM、Excel公式或独立程序追溯验证。 其他说明:项目交付包含A4文档、可编辑Excel、完整Python代码、CSV输入表、计算快照、四情景结果、测试记录、README指引及作者验收记录。采用固定随机种子确保数据一致性,强调输入有效性校验与双守恒(供给与需求)原则。Excel工作簿采用三层结构(源输入—公式计算—结果展示),支持手动编辑与自动重算,但扩容需重新生成网格。独立Python程序可用于交叉验证,保障模型可靠性。 立即下载
The Tamworth Two
BIO '98 - Richard Forster

A pair of cows is loose somewhere in the forest. Farmer John is lending his expertise to their capture. Your task is to model their behavior.

The chase takes place on a 10 by 10 planar grid. Squares can be empty or they can contain:

  • an obstacle,
  • the cows (who always travel together), or
  • Farmer John.

The cows and Farmer John can occupy the same square (when they `meet') but neither the cows nor Farmer John can share a square with an obstacle.

 

Each square is
represented
as follows:

  • . Empty square
  • * Obstacle
  • C Cows
  • F Farmer

Here is a sample grid:
*...*.....
......*...
...*...*..
..........
...*.F....
*.....*...
...*......
..C......*
...*.*....
.*.*......

The cows wander around the grid in a fixed way. Each minute, they either move forward or rotate. Normally, they move one square in the direction they are facing. If there is an obstacle in the way or they would leave the board by walking `forward', then they spend the entire minute rotating 90 degrees clockwise.

Farmer John, wise in the ways of cows, moves in exactly the same way.

The farmer and the cows can be considered to move simultaneously during each minute. If the farmer and the cows pass each other while moving, they are not considered to have met. The chase ends when Farmer John and the cows occupy the same square at the end of a minute.

Read a ten-line grid that represents the initial state of the cows, Farmer John, and obstacles. Each of the ten lines contains exactly ten characters using the coding above. There is guaranteed to be only one farmer and one pair of cows. The cows and Farmer John will not initially be on the same square.

Calculate the number of minutes until the cows and Farmer John meet. Assume both the cows and farmer begin the simulation facing in the `north' direction. Print 0 if they will never meet.

PROGRAM NAME: ttwo

INPUT FORMAT

 

Lines 1-10:Ten lines of ten characters each, as explained above

SAMPLE INPUT (file ttwo.in)

*...*.....
......*...
...*...*..
..........
...*.F....
*.....*...
...*......
..C......*
...*.*....
.*.*......

OUTPUT FORMAT

A single line with the integer number of minutes until Farmer John and the cows meet. Print 0 if they will never meet.

SAMPLE OUTPUT (file ttwo.out)

49

就是模拟它的行进路线即可,只要能遇到必定在4*10*10*4*10*10(图为10*10,4个方向,一牛一人)的步骤内相遇否则永远不相遇,因此只要判断比这大就输0;

原先做踩雷了,用了深搜,后来发现不用。

 

/*
 ID:nealgav1
 LANG:C++
 PROG:ttwo
*/
#include<fstream>
using namespace std;
ifstream cin("ttwo.in");
ofstream cout("ttwo.out");
char map[12][12];
bool s[12][12][4];
const int oo=1000000;
const int dx[]={0,-1,0,1};
const int dy[]={-1,0,1,0};//左上右下
int step;
int xx[3],yy[3];
void dfs(int a,int b,int c,int x,int y,int z)
{  while(1)
  { int nx,ny,na,nb;
  na=a+dx[c];nb=b+dy[c];
  nx=x+dx[z];ny=y+dy[z];
  if(a==x&&b==y)break;
  else
  {
     if(step>oo)break;
    if(na<0||nb<0||na>9||nb>9||map[na][nb]=='*')
    {
      na=a;nb=b;c=(c+1)%4;
    }
    if(nx<0||ny<0||nx>9||ny>9||map[nx][ny]=='*')
    {
      nx=x;ny=y;z=(z+1)%4;
    }
    a=na;b=nb;x=nx;y=ny;
    step++;
   // if(step==32534)cout<<na<<" "<<nb<<" "<<c<<" "<<nx<<" "<<ny<<" "<<z<<endl;
    //cout<<step<<endl;
    //dfs(na,nb,c,nx,ny,z);
  }
  }
  if(step>oo)step=0;
}
int main()
{
  for(int i=0;i<10;i++)
  cin>>map[i];
  for(int i=0;i<10;i++)
  for(int j=0;j<10;j++)
  if(map[i][j]=='C')xx[0]=i,yy[0]=j;
  else if(map[i][j]=='F')xx[1]=i,yy[1]=j;
  step=0;
  dfs(xx[0],yy[0],1,xx[1],yy[1],1);
  cout<<step<<"\n";
}


 

 

 

USER: Neal Gavin Gavin [nealgav1]
TASK: ttwo
LANG: C++

Compiling...
Compile: OK

Executing...
   Test 1: TEST OK [0.000 secs, 3344 KB]
   Test 2: TEST OK [0.000 secs, 3344 KB]
   Test 3: TEST OK [0.011 secs, 3344 KB]
   Test 4: TEST OK [0.000 secs, 3344 KB]
   Test 5: TEST OK [0.000 secs, 3344 KB]
   Test 6: TEST OK [0.011 secs, 3344 KB]
   Test 7: TEST OK [0.000 secs, 3344 KB]
   Test 8: TEST OK [0.011 secs, 3344 KB]
   Test 9: TEST OK [0.000 secs, 3344 KB]

All tests OK.

YOUR PROGRAM ('ttwo') WORKED FIRST TIME! That's fantastic -- and a rare thing. Please accept these special automated congratulations.

Here are the test data inputs:

------- test 1 ----
.****...*.
..*......*
*.........
..........
*........*
*.**.*..**
F..*......
***....*.*
.C.......*
.......*.*
------- test 2 ----
..........
..........
..........
....*.....
....F.....
....C.....
..........
..........
..........
..........
------- test 3 ----
..........
.********.
.********.
.********.
.********.
.********.
.********.
C********.
.********.
F.........
------- test 4 ----
..........
.*........
........*.
...*......
......*...
....*.*...
F....*....
..*.......
C......*..
*.........
------- test 5 ----
...*.....*
**.......*
.....*..*.
*.*.......
.........*
F.....*.*.
**.*C....*
.......**.
.....*....
....*.*...
------- test 6 ----
..........
.......C..
..........
****..****
...*..*...
...*..*...
****..****
..........
..F.......
..........
------- test 7 ----
*...*....*
.......*..
.*...*.F..
.*........
....*..**.
*.......*.
......**..
*..C......
..*...*..*
*.....*.*.
------- test 8 ----
*..C.**...
..**...*.*
**......*.
.....**.*.
......*.**
.......**.
**..**...*
.**.......
*...*....*
*...F.*...
------- test 9 ----
*.*.**..*.
*.*.*..*.*
*.*.**.***
*.*.C*.*.*
***.**.*.*
..........
F***...**.
*.....*..*
*.....*..*
.***...**.
Keep up the good work!
The Tamworth Two
Russ Cox

We can simply simulate the movement of Farmer John and the two cows, but we need to find a way to detect loops. There are only 100 places where the cows can be, and 4 directions they can face. The same goes for Farmer John. This multiplies out to 400*400 = 160,000 different (place, direction) configurations for Farmer John and the cows. If we ever happen upon a configuration we have been in before, we are in an infinite loop, and John and the cows will never meet.

In fact, we don't even need to keep track of which configurations we've seen. If they're going to meet, they're going to meet in fewer than 160,000 steps. Otherwise, they have to repeat some configuration, in which case they'll never meet.

We take care of the simulation by keeping track of the position and direction of each. Direction is a number from 0 to 3, 0 = north, 1 = east, 2 = south, 3 = west. So turning clockwise is incrementing one. We calculate how to move given the direction by looking up offsets in the deltax and deltay arrays.

/*
PROG: ttwo
ID: rsc001
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

char grid[10][10];

/* delta x, delta y position for moving north, east, south, west */
int deltax[] = { 0, 1, 0, -1 };
int deltay[] = { -1, 0, 1, 0 };

void
move(int *x, int *y, int *dir)
{
	int nx, ny;

	nx = *x+deltax[*dir];
	ny = *y+deltay[*dir];

	if(nx < 0 || nx >= 10 || ny < 0 || ny >= 10 || grid[ny][nx] == '*')
		*dir = (*dir + 1) % 4;
	else {
		*x = nx;
		*y = ny;
	}
}

void
main(void)
{
	FILE *fin, *fout;
	char buf[100];
	int i, x, y;
	int cowx, cowy, johnx, johny, cowdir, johndir;


	fin = fopen("ttwo.in", "r");
	fout = fopen("ttwo.out", "w");
	assert(fin != NULL && fout != NULL);

	cowx = cowy = johnx = johny = -1;

	for(y=0; y<10; y++) {
		fgets(buf, sizeof buf, fin);
		for(x=0; x<10; x++) {
			grid[y][x] = buf[x];
			if(buf[x] == 'C') {
				cowx = x;
				cowy = y;
				grid[y][x] = '.';
			}
			if(buf[x] == 'F') {
				johnx = x;
				johny = y;
				grid[y][x] = '.';
			}
		}
	}

	assert(cowx >= 0 && cowy >= 0 && johnx >= 0 && johny >= 0);

	cowdir = johndir = 0;	/* north */

	for(i=0; i<160000 && (cowx != johnx || cowy != johny); i++) {
		move(&cowx, &cowy, &cowdir);
		move(&johnx, &johny, &johndir);
	}

	if(cowx == johnx && cowy == johny)
		fprintf(fout, "%d\n", i);
	else
		fprintf(fout, "0\n");
	exit(0);
}
USACO Gateway

 

东汉AD35年世界历史地图矢量文件SHP格式.zip 本资源为《东汉AD35年世界历史地图矢量文件SHP格式》压缩包,文件大小约 29.99 MB,便于集中下载、整理和使用。具体内容请结合压缩包内的实际文件与说明查看。 在当前可读取的目录中,可见JSON 文件、属性表(.dbf)、投影说明文件(.prj)、Shapefile 主文件(.shp)、Shapefile 索引(.shx)。建议解压后保持原有目录结构,先浏览文件清单与说明,再选择需要的资料进行加载或整理。 应用方面,可根据实际资料用于学习练习、资料检索、研究整理或项目参考。使用时可先确定所需内容,建立清晰的文件分类,再按项目要求进行筛选、转换与汇总。 使用 Shapefile 数据时,请把实际配套的 .shp、.shx、.dbf 等文件保存在同一目录,并保持同名关联;加载后再检查坐标系与中文字段显示。如需叠加其它数据,请先统一坐标与字段口径。 数据来源、时间范围、坐标系、字段定义、精度和使用条件,请以实际文件及原始说明为准。本介绍不对文件名之外尚未核实的信息作额外承诺。 立即下载

相关推荐

基于FastAPI Vue3 TypeScript的企业级全栈底座:类型共享、权限完整,三端同源 一套代码交付Web/H5/小程序,AI代码生成 RBAC Docker开箱即用一套开源的快速开发平台

基于FastAPI Vue3 TypeScript的企业级全栈底座:类型共享、权限完整,三端同源。一套完全开源的快速开发平台,提供免费使用。它结合了现代、高性能的技术栈,后端采用Fastapi + SQLAlchemy,前端采用基于 vue3 + typescript + vite + pinia + Element-Plus。

C++——USACO Section 2.4 题解

The Tamworth Two BIO '98 - Richard Forster A pair of cows is loose somewhere in the forest. Farmer John is lending his expertise to their capture. Your task is to model their behavior. The chase

McDonnell_Douglas的博客 1436

AI第三篇:ScaBench-用真实审计竞赛数据构建可复现的 AI 审计评测集

AI第三篇:ScaBench-用真实审计竞赛数据构建可复现的 AI 审计评测集

USACO2.4.1 The Tamworth Two 两只塔姆沃斯牛 解题报告(模拟)

2.4.1 The Tamworth Two 两只塔姆沃斯牛 Time Limit:1 SecMemory Limit:64 MB Submit:18Solved:14 [Submit][Status][Discuss] Description 两只牛在森林里故意走丢了。农民John开始用他的专家技术追捕这两头牛。你的任务是模拟他们的行为(牛...

weixin_30709635的博客 241

量化交易——量化选股(多因子选股)

就是用过去的股票的收益率对多因子进行回归,得到一个回归方程,然后再把最新的因子值代入回归方程得到一个对未来股票收益的预判,然后再以此为依据进行选股。的方法是建立在市场无效或弱有效的前提之下,随着使用多因子选股模型的投资者数量的不断增加,有的因子会逐渐失效,而。就是根据各个因子的大小对股票进行打分,然后按照一定的权重加权得到一个总分,根据总分再对股票进行筛选。另一方面,一些因子可能在过去的市场环境下比较有效,而随着市场风格的改变,这些。波动的影响,避免在市场极度狂热或悲观的情况下作出非理性的。

jiucaixiuyang的博客 1813

拖动无标题栏的cef3窗口

拖动嵌入了cef3的无标题栏win32窗口,本质上就是拖动子窗口移动父窗口这么个事情,这个在自己创建窗口的程序上处理非常简单,cef封装较多,想修改的完善点步骤较多。         cef所用版本3.2623。         就用cefclient来做测试工程,首先建议在cefclient_win.cc的RunMain函数中的app = new ClientAppRenderer();前面

loveyong1990的专栏 6171

洛谷 P1518 两只塔姆沃斯牛

题目描述两只牛逃跑到了森林里。农夫John开始用他的专家技术追捕这两头牛。你的任务是模拟他们的行为(牛和John)。追击在10x10的平面网格内进行。一个格子可以是:一个障碍物, 两头牛(它们总在一起), 或者 农民John. 两头牛和农民John可以在同一个格子内(当他们相遇时),但是他们都不能进入有障碍的格子。一个格子可以是:. 空地星号 障碍物 C 两头牛 F 农民John 这里有一个地

Chlorineひかりのblog 1008

mysql8.0安装及配置超详细教程_mysql-8.0.15-winx64

MySQL8.0配置教程, 全网最详,同时有本地mysql和小皮系统见另一篇

小诺言的博客 2万+

USACO 2.4 The Tamworth Two 两只塔姆沃斯牛

The Tamworth Two BIO '98 - Richard Forster A pair of cows is loose somewhere in the forest. Farmer John is lending his expertise to their capture. Your task is to model their behavior. The chas...

NeWorldMaker 339

解决Word中英文混排的5个常见排版问题(含单词换行、间距调整等)

本文详细解析Word中英文混排的5大常见排版问题,包括单词换行、间距调整、标点混用等,提供专业解决方案。通过设置段落格式、调整兼容性选项和使用字体组合等技巧,帮助用户轻松解决文档排版难题,提升专业性和阅读体验。

vim8coder的博客 1379

2025华为od机试真题B卷【版本管理】Python实现

在 软件版本管理中,版本号由点分割的数字组成,例如 1.2.3 和 2.8。现在,你需要编写一个函数,计算两个版本号之间的可用版本号个数。这里的可用版本号指的是所有满足 version1<x<version2的版本号x的个数。若 version1 >=version2 返回0.,

MISAYAONE的博客 653

USACO SECTION 2.4 The Tamworth Two

The Tamworth Two BIO '98 - Richard Forster A pair of cows is loose somewhere in the forest. Farmer John is lending his expertise to their capture. Your task is to model their behavior. The chase

321

摆脱英文束缚!群晖Transmission4.0.4全新中文界面攻略

在群晖安装完官方Transmission4.0.4套件后,界面是英文状态的,不太好用。但是按照网上分享的原来4.0以前版本的方法更新UI又失败,所以自己搞了下成功了,分享给需要的朋友。

XiaoqiangClub的博客 5254

USACO Section 2.4 The Tamworth Two

The Tamworth TwoBIO '98 - Richard Forster A pair of cows is loose somewhere in the forest. Farmer John is lending his expertise to their capture. Your task is to model their behavior. The chase...

angtongyou1893的博客 195

GeoServer改造Springboot源码一(公共部分)

今天开始开启关于GeoServer的一个全新系列,主要是把改造Springboot后的详细代码粘贴出来,此文应配合《》系列共同阅读,按照前系列的时间顺序结合此系列的源码展示可以快速构建GeoServer功能的二次封装的后端系统。

龙井的专栏 1906

AMBA-CHI协议详解(三)

Write Transactions、Atomic transactions、 Stash transactions、 Dataless transactions的等各个事务的事务流。

Crazzy_M的博客 3194

USACO-Section 2.4 The Tamworth Two(模拟)

水题,模拟即可 由于地图很小,所有总共有10*10*4种状态,牛和人共有160000种状态,则若超过160000分钟还未相遇,则必有两种状态重复,即陷入循环,则不会相遇

idealism_xxm的专栏 659

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

USACO Section 2.4 The Tamworth Two (BFS模拟)

用三维数组保存运动物体第一次处于x、y坐标和某方向时所用步数,同时记录当运动物体的路径和出现循环时的周期。这一步用BFS完成。 枚举两个运动物体路径中的公共位置,根据情况分类讨论。 有3种情况。 1,人和牛都处于循环路径中。即判断A+xa=B+y+b,用拓展欧几里德求解。 2,人和牛都不在循环路径中。即判断A=B。 3,人和牛只有一个在循环路径中。即判断A+xa=B。 /* ID: k

一个码农 445

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

USACO - Chapter2 Section 2.4 - The Tamworth Two

The Tamworth Two

zhuo1ang的博客 331

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

USACO Training Section 2.4 The Tamworth Two

[url="http://ace.delos.com/usacoprob2?a=F8SQKyzbWbG&S=ttwo"]英文原题[/url] [url="http://www.wzoi.org/usaco/12%5C209.asp"]中文题译[/url] 大意:奶牛丢了,农民要找牛。牧场是一块方形区域,其中有障碍物,奶牛每分钟走一格,如不遇到障碍或者到达边界不转向,每次转向费时一分钟,且...

山中竹笋 227

USACO Section 2.4

USACO Section 2.4 The Tamworth Two/* ID: beihai2013 TASK: ttwo LANG: C++ */ /* 刚开始想复杂了,想通过记录数组然后求牛或者人经过此点的时间戳来求周期,然后求一个通项 后面发现这样的讨论不仅复杂,而且容易出现十分多的情况 然后仔细一想,假设是有人和牛周期的话,他们分别得周期不

beihai2013 287

USACO-Section2.4 The Tamworth Two【模拟法】

题目描述: 两只牛逃跑到了森林里。农夫John开始用他的专家技术追捕这两头牛。你的任务是模拟他们的行为(牛和John)。 追击在10x10的平面网格内进行。一个格子可以是: 一个障碍物, 两头牛(它们总在一起), 或者 农民John. 两头牛和农民John可以在同一个格子内(当他们相遇时),但是他们都不能进入有障碍的格子。 一个格子可以是: . 空地 * 障碍物 C 两头牛

tjj1998的博客 247

USACO section2.4 The Tamworth Two题解&代码

很简单的模拟…需要避免产生循环的情况,所以设置vis数组记录step 但是需要注意的是使用scanf(“%c”,&m[i][j])的话scanf会等到遇到第一个非可读字符的时候结束… 这样的话j就不是准确的了… 恩…看了15min才看出来…果然是该去休息了…/* ID:rainbow16 LANG:C++ TASK:ttwo */ #include<stdio.h> char m[10][10

Rainbow6174's home 695

USACO Section 2.4 The Tamworth Two - 又犯2了..又把一个简单的问题整复杂了..

做了好几个小时~~开始的做法是先找出C走的路径~~并记下循环节~~~然后再走F..走到一个点就判断下是不是能同时~~开了2个4维数组~~代码码了120多行~~结果还是没调出来...要吐了..     刚才突然开窍了~~这不同时记步数同时走~~啥时候一样就ok了~~~呃~~十分钟解决~~矮油~~ Program: /* ID: zzyzzy12 LANG: C++ TASK:

zzyzzy12 1701
上一篇: USACO section 2.3 Controlling Companies(dfs)
下一篇: USACO section 2.4 Overfencing(dfs+bfs)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址