POJ2137——Cowties

Cowties
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2870 Accepted: 961

Description

N cows (3 <= N <= 100) are eating grass in the middle of a field. So that they don't get lost, Farmer John wants to tie them together in a loop so that cow i is attached to cows i-1 and i+1. Note that cow N will be tied to cow 1 to complete the loop.

Each cow has a number of grazing spots she likes and will only be happy if she ends up situated at one of these spots. Given that Farmer John must ensure the happiness of his cows when placing them, compute the shortest length of rope he needs to tie them all in a loop. It is possible for different parts of the loop to cross each other.

Input

* Line 1: The integer N.

* Lines 2..N+1: Each line describes one cow using several space-separated integers. The first integer is the number of locations S (1 <= S <= 40) which are preferred by that cow. This is followed by 2*S integers giving the (x,y) coordinates of these locations respectively. The coordinates lie in the range -100..100.

Output

A single line containing a single integer, 100 times the minimum length of rope needed (do not perform special rounding for this result).

Sample Input

4
1 0 0
2 1 0 2 0
3 -1 -1 1 1 2 2
2 0 1 0 2

Sample Output

400

Hint

[Cow 1 is located at (0,0); cow 2 at (1,0); cow 3 at (1,1); and cow 4 at (0,1).]

Source

USACO 2003 February Orange


n头牛,每头牛都有其限制的放牧区域,求给n头牛安排好放牧区域以后,他们之间的最短距离(形成一个环)

很明显的dp,但是由于头尾相接,所以不能单纯的从1枚举到n,一开始我是这么做的,然后wa了2次,晚上睡觉的时候在想这个,然后就想到了枚举1这头牛的可放牧区域,然后从2枚举到n,求出最小值即可,最后注意答案*100之后不要用%.0f输出,直接强制类型转换成int输出就可以了

#include <map>  
#include <set>  
#include <list>  
#include <stack>  
#include <vector>  
#include <queue>  
#include <cmath>  
#include <cstdio>  
#include <cstring>  
#include <iostream>  
#include <algorithm>  

using namespace std;

double dp[110][50];

vector<pair<int, int> >pp[110];

double dist(int x1, int y1, int x2, int y2)
{
	return sqrt((double)((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) );
}

int main()
{
	int n;
	while (~scanf("%d", &n))
	{
		int cnt, x, y;
		for (int i = 1; i <= n; ++i)
		{
			scanf("%d", &cnt);
			for (int j = 0; j < cnt; ++j)
			{
				scanf("%d%d", &x, &y);
				pp[i].push_back( make_pair(x, y) );
			}
		}
		memset (dp, 0, sizeof(dp) );
		double ans = 0x3f3f3f3f;
		int fc = pp[1].size();
		for (int i = 0; i < fc; ++i) // 枚举第一行
		{
			int sc = pp[2].size();
			for (int p = 0; p < sc; ++p)
			{
				dp[2][p] = dist(pp[1][i].first, pp[1][i].second, pp[2][p].first, pp[2][p].second);
			}
			for (int j = 3; j <= n; ++j)
			{
				int tc = pp[j].size();
				for (int k = 0; k < tc; ++k)
				{
					int ffc = pp[j - 1].size();
					double mins = 0x3f3f3f3f;
					 for (int q = 0; q < ffc; ++q)
					 {
					 	mins = min(mins, dp[j - 1][q] + dist(pp[j - 1][q].first, pp[j - 1][q].second, pp[j][k].first, pp[j][k].second));
					 }
					 dp[j][k] = mins;
					 if (j == n)
					{
						ans = min(ans, dp[n][k] + dist(pp[n][k].first, pp[n][k].second, pp[1][i].first, pp[1][i].second));	
					}
				}
			}
		}
		printf("%d\n", int(ans * 100));
	}
	return 0;
}


下载方式:https://pan.quark.cn/s/c9b9b647468b ### 初级JSP程序设计教程核心内容解析#### 一、JSP基础概述JSP(JavaServer Pages)是由Sun Microsystems公司创建的一种动态网页技术规范,主要应用于构建动态网站及Web应用。JSP技术使得开发者能够将动态数据与静态HTML文档整合,从而实现网页内容的灵活性和可变性。##### JSP的显著特性:1. **动态与静态内容的分离**:JSP技术支持将动态数据(例如数据库查询结果、实时时间等)嵌入到静态HTML文档中。这种设计方法增强了网页的适应性和可维护性。2. **易用性**:开发者可以利用常规的HTML编辑工具来编写静态部分,并通过简化的标签技术将动态内容集成到页面中。3. **跨平台兼容性**:基于Java平台的JSP具有优良的跨操作系统运行能力,能够在多种不同的系统环境中稳定工作。4. **强大的后台支持**:JSP能够通过JavaBean组件访问后端数据库及其他资源,以实现复杂的数据处理逻辑。5. **执行效率高**:JSP页面在初次被请求时会被转换为Servlet,随后的请求可以直接执行编译后的Servlet代码,从而提升了服务响应的效率。#### 二、JSP指令的运用JSP指令用于设定整个JSP页面的行为规范。这些指令通常放置在页面的顶部,向JSP容器提供处理页面的相关指导信息。##### 主要的指令类型:1. **Page指令**: - **语法结构**:`<%@ page attribute="value" %>` - **功能**:定义整个JSP页面的运行特性,如设定页面编码格式、错误处理机制等。 - **实例**: ...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值