【Usaco2009 gold 】拯救奶牛

本文介绍了一个迷宫逃脱问题,贝希被困在一个三角形迷宫中,需要找到最快的逃脱路径。迷宫由N行组成,每行包含不同数量的三角形单元。贝希的目标是从当前位置到达任意一个出口,算法通过比较不同路径的长度来确定最优解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description

贝希被困在一个三角形的迷宫之中。这个迷宫有N行(1 <= N <= 1000000)。比如下图是一个3行的迷宫。
  在这里插入图片描述
  迷宫的第i行有2*i-1个三角形,从左到右分别编号为(i,1)、(i,2)等等。贝希每次可以从一个三角形走到任意一个一个跟当前的三角形有邻边的三角形。比如说,如果她目前处于三角形(3,3),那么,她可以走到三角形(3,2)、(3,4)和(4,4)。贝希每次需要一分钟的时间来移动到下一个三角形。
  在这里插入图片描述
  农夫约翰发现贝希被困了!于是她跟踪贝希的iPhone手机(可怜的触摸屏~),得知贝希目前处于三角形(Si,Sj)。因为约翰对贝希有着无穷无尽的浓浓爱意,所以他希望贝希能尽可能快地回到他的身边。
  在迷宫的三角形之中,有M(1 <= M <= 10000)个是出口。在任何一个出口都可以让贝希逃离迷宫。一旦贝希进入一个作为出口的三角形,她用多一分钟就可以逃离这个迷宫。
  找到一个可以让贝希逃离迷宫最小时间T,并输出她应该从哪一个出口逃离迷宫,这个出口记为(OUTi,OUTj)。如果有多个出口同时需要时间T,输出那个行的编号小的出口,如果仍然有多个出口,输出那个列的编号小的。

Input

第一行:两个由空格隔开的整数:N和M。
  第二行:两个由空格隔开的整数:Si和Sj。
  第三到第M+2行:第i+2行有两个由空格隔开的整数Ei和Ej,表示三角形(Ei,Ej)是出口。

Output

第一行:两个由空格隔开的整数:OUTi和OUTj。
  第二行:一个单独的整数:T。

Sample Input

4 2
2 1
3 5
4 4

Sample Output

4 4
4

solution

这题感觉就是乱搞搞求个答案就可以了的说。。。
可能代码你们看不懂。。。(我打的很丑**(⊙o⊙)…**)

code

#include<cstdio>
using namespace std;
int n,m,x1,y1,ansx,ansy,ans=(1<<30),s;

inline int read()
{
	int x=0; char c=getchar();
	while (c<'0' || c>'9') c=getchar();
	while (c>='0' && c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x;
}

void doit(int x,int y,int x1,int y1)
{
	int le,ri,cg=0;
	if (! (y & 1)) x--,y--,cg--;
	if (y1 & 1) x1++,y1++,cg--;
	le=y+1,ri=y+(x1-x<<1)-1;
	s=(x1-x<<1)-1+cg+1;
	if (y1<le) s+=le-y1;
	else if (y1>ri) s+=y1-ri;
}

int main()
{
	freopen("save.in","r",stdin);
	freopen("save.out","w",stdout);
	n=read(),m=read();
	x1=read(),y1=read();
	for (int i=1,x,y;i<=m;i++)
	{
		x=read(),y=read();
		if (x<x1)
		{
			doit(x,y,x1,y1);
			if (s<ans) ans=s,ansx=x,ansy=y;
			else if (s==ans && y<ansy) ansx=x,ansy=y;
		}
		else
		{
			doit(x1,y1,x,y);
			if (s<ans) ans=s,ansx=x,ansy=y;
			else if (s==ans && y<ansy) ansx=x,ansy=y;
		}
	}
	printf("%d %d\n%d\n",ansx,ansy,ans);
	return 0;
}
### USACO Competition Problem Solutions for Cow Games In the context of USACO competitions, problems involving cows often require a blend of algorithmic thinking and mathematical insight. For instance, one notable problem involves Farmer John providing hay to his cows on different days with varying quantities[^3]. This type of scenario can be modeled using dynamic programming or greedy algorithms depending on what is asked. For specific game-related challenges featuring cows within USACO contests, consider an example where cows play games that involve strategic decision-making under given constraints. These scenarios frequently test contestants' ability to apply concepts like graph theory, number manipulation, and optimization techniques effectively. A relevant exercise from similar competitive coding platforms includes dealing with round numbers which have properties making them interesting subjects for computational puzzles[^2]: ```python def count_round_numbers(n): binary_representation = bin(n)[2:] zero_count = binary_representation.count('0') return zero_count >= len(binary_representation) / 2 ``` This function checks whether a number has at least as many zeros as ones in its binary representation—a concept sometimes explored through playful contexts such as virtual cow activities designed around numerical patterns. To tackle these kinds of tasks successfully: - Understand all rules governing how elements interact. - Identify efficient ways to represent data structures involved. - Develop strategies based on observed trends or established theories applicable to the situation described.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值