TZOJ:1415: 无限的路

描述

甜甜从小就喜欢画图画,最近他买了一支智能画笔,由于刚刚接触,所以甜甜只会用它来画直线,于是他就在平面直角坐标系中画出如下的图形:
 


甜甜的好朋友蜜蜜发现上面的图还是有点规则的,于是他问甜甜:在你画的图中,我给你两个点,请你算一算连接两点的折线长度(即沿折线走的路线长度)吧。

输入

第一个数是正整数N(≤100)。代表数据的组数。
每组数据由四个非负整数组成x1,y1,x2,y2;所有的数都不会大于100。

输出

对于每组数据,输出两点(x1,y1),(x2,y2)之间的折线距离。注意输出结果精确到小数点后3位。

样例输入

5
0 0 0 1
0 0 1 0
2 3 3 1
99 99 9 9
5 5 5 5

样例输出

1.000
2.414
10.646
54985.047
0.000

建议画图自己演算一遍

#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cctype>
#include <stack>
#include <map>
using namespace std;

int main()
{
	int n;
	cin >> n;
	int x1,x2,y1,y2;
	int i;
	for(i = 0;i < n;i ++)
	{
		double sum = 0;
		cin >> x1 >> y1 >> x2 >> y2; // 读入坐标 
		if(x1 == 0 && y1 == 0 && y2 == 0 && x2 == 0) // 如果坐标都为0直接输出 
		{
			cout << "0.000" << endl;
			continue; // 跳过该循环 
		}
		if(x1 == 0 && y1 == 0) // 讨论在原点的情况 
		{
			sum += 1;
			y1 += 1;
		}
		/* 讨论是否是同一条线上 */ 
		if(x1 + y1 != x2 + y2)
		{
			if(x1 + y1 > x2 + y2)
				sum += (x1 + y2) * sqrt(2);
			else
				sum += (x2 + y1) * sqrt(2);
		}
		else 
			sum += fabs(y1 - y2) * sqrt(2); 
		int j;
		for(j = x1 + y1 + 1;j < x2 + y2;j ++)
		{
			sum += j * sqrt(2);
		}
		for(j = x2 + y2 + 1;j < x1 + y1;j ++)
		{
			sum += j * sqrt(2);
		}
		for(j = x1 + y1;j < x2 + y2;j ++)
		{
			sum += sqrt(j * j + (j + 1) * (j + 1));
		}
		for(j = x2 + y2;j < x1 + y1;j ++)
		{
			sum += sqrt(j * j + (j + 1) * (j + 1));
		}
		printf("%.3lf\n" , sum); // 注意输出三位小数以及换行(^-^) 
	} 
	return 0;
}

  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
由于提供的引用内容中没有与"矩阵游戏"相关的信息,无法给出专业、客观的回答。建议提供更多的引用内容或提供更详细的问题描述,以便我能够为您提供准确的答案。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [TZOJ 4954:矩阵游戏](https://blog.csdn.net/m0_62187903/article/details/132239441)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [TZOJ——4954:矩阵游戏(快速幂+费马小定理+指数循环节+逆元)](https://blog.csdn.net/qq_62089682/article/details/132239372)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [自然语言处理(NLP):08-05 TextCNN短文本分类案例分享](https://blog.csdn.net/shenfuli/article/details/108436612)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值