1034: Max Area

时间限制: 1 Sec  内存限制: 128 MB
提交: 40  解决: 6
[提交][状态][讨论版]

题目描述

又是这道题,请不要惊讶,也许你已经见过了,那就请你再来做一遍吧。这可是wolf最骄傲的题目哦。在笛卡尔坐标系正半轴(x>=0,y>=0)上有n个点,给出了这些点的横坐标和纵坐标,但麻烦的是这些点的坐标没有配对好,你的任务就是将这n个点的横坐标和纵坐标配对好,使得这n个点与x轴围成的面积最大。

输入

在数据的第一行有一个正整数m,表示有m组测试实例。接下来有m行,每行表示一组测试实例。每行的第一个数n,表示给出了n个点,接着给出了n个x坐标和y坐标。(给出的x轴的数据不会重复,y轴数据也不会重复)(m<5000,1<n<50) div="" y5<="" y4="" y3="" y2="" y1="" x5="" x4="" x3="" x2="" x1="" 5="" 4="" 2="" 如:="">

输出

输出所计算的最大面积,结果保留两位小数,每组数据占一行。

样例输入

2
4 0 1 3 5 1 2 3 4
6 14 0 5 4 6 8 1 5 6 2 4 3

样例输出

15.00
59.00


#include<stdio.h>
void sort(double *a, int from, int to){if (to <= from)return;int i = from, j = to;double k = a[from];while (1){while (a[j] > k)j--;if (j == i)break;a[i] = a[j];a[j] = k;i++;while (a[i] < k)i++;if (j == i)break;a[j] = a[i];a[i] = k;j--;}sort(a, from, i - 1);sort(a, i + 1, to);
}
int main()
{//freopen("in.txt", "r", stdin);int t;scanf("%d", &t);while (t-- > 0){int n;scanf("%d", &n);double x[5001];double  y[5001];double z[5001];int i;for (i = 0; i < n; i++)scanf("%lf", &x[i]);for (i = 0; i < n; i++)scanf("%lf", &y[i]);sort(x, 0, n - 1);for (i = 1; i < n - 1; i++)z[i] = x[i + 1] - x[i - 1];z[0] = x[1] - x[0];z[n - 1] = x[n - 1] - x[n - 2];sort(z, 0, n - 1);sort(y, 0, n - 1);double ans = 0;for (i = 0; i < n; i++)ans +=  z[i] *  y[i];printf("%.2lf\n", ans / 2);}return 0;
}
/*破东大OJ题里没说清楚,点是double类型,那个m是5000可能.若问这道题怎么做,第一关,走两步,列出式子;第二关,必须知道一个不等式:顺序>乱序>逆序例如:a={1,2,3}b={4,5,6}则1*4+2*5+3*6>乱序>1*6+2*5+1*4*/

转载于:https://www.cnblogs.com/weiyinfu/p/5013902.html

东大OJ-Max Area相关推荐

  1. [Leetcode] Max Area of Island 最大岛屿面积

    Max Area of Island 最新更新请见:https://yanjia.me/zh/2019/02/... Given a non-empty 2D array grid of 0's an ...

  2. C#LeetCode刷题之#695-岛屿的最大面积( Max Area of Island)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3736 访问. 给定一个包含了一些 0 和 1的非空二维数组 gr ...

  3. [swift] LeetCode 695. Max Area of Island

    Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) conn ...

  4. [Swustoj 24] Max Area

    Max Area 题目描述: 又是这道题,请不要惊讶,也许你已经见过了,那就请你再来做一遍吧.这可是wolf最骄傲的题目哦. 在笛卡尔坐标系正半轴(x>=0,y>=0)上有n个点,给出了这 ...

  5. LeetCode 695. Max Area of Island

    LeetCode 695. Max Area of Island Given a non-empty 2D array grid of 0's and 1's, an island is a grou ...

  6. LeetCode - 695. Max Area of Island (Java)

    R.C记录矩阵行列 可以将邻接矩阵转为邻接表来做,即要将二维数组转换为一维数组: 将二维坐标转化为一维坐标: V = x * C + y 若将一维坐标转化为二维坐标: x = V / C y = V ...

  7. LeetCode 695 Max Area of Island

    题目: Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) ...

  8. leetcode 695. Max Area of Island | 695. 岛屿的最大面积(DFS)

    题目 https://leetcode.com/problems/max-area-of-island/ 题解 class Solution {int M, N;public int maxAreaO ...

  9. LeetCode 695. Max Area of Island javascript解决方案

    题意: 寻找最大岛. leetcode.com/problems/ma- 传入: [[0,0,1,0,0,0,0,1,0,0,0,0,0],  [0,0,0,0,0,0,0,1,1,1,0,0,0], ...

  10. Leetcode695.Max Area of Island岛屿的最大面积

    给定一个包含了一些 0 和 1的非空二维数组 grid , 一个 岛屿 是由四个方向 (水平或垂直) 的 1 (代表土地) 构成的组合.你可以假设二维矩阵的四个边缘都被水包围着. 找到给定的二维数组中 ...

最新文章

  1. Alpha fold: 人工智能在蛋白质结构预测上跑赢人类的启示
  2. OpenGL和D3D的区别
  3. linux安卓双系统板子,安卓迷你 PC 主机只要 109 美元,支持 Android 和 Linux 双系统...
  4. uni-app 更新包提示HTML5+Runtime缺少升级包manifest.json中配置的模块:payment
  5. NSLog中格式符列表
  6. 使用EF.Core将同一模型映射到多个表
  7. aws dynamodb_DynamoDB备忘单–您需要了解的有关2020 AWS认证开发人员助理认证的Amazon Dynamo DB的所有信息
  8. python docx 字体大小_Python操作Word的入门教程
  9. Android_自定义水波纹菜单弹出效果
  10. Insyde uefi 隐藏设置_文件隐藏工具Wise Folder Hider Pro便携版分享
  11. Kramdown 配置不当引发 GitHub Pages 多个 RCE,得 $2.5万($6.1万系列之二)
  12. 【重点 递归版】剑指offer——面试题16:反转链表
  13. Splash args 属性
  14. Flowable入门系列文章187 - 高并发性的UUID ID生成器和多租户
  15. matlab 异常,Matlab 2017b 异常信息。程序奔溃。
  16. 如何只用HTML创建一个时间计划表?
  17. html页面加载蒙版,HTML / CSS - 在图像上创建alpha蒙版
  18. 同时定位与地图创建综述
  19. 间隔层设备和过程层简介
  20. 关于树状图画法的分析

热门文章

  1. css之max-width属性
  2. 问题:动态变换video标签source的src不起作用
  3. Codeforces 319C DP 斜率优化
  4. document.write vs document.getElementById
  5. vue中的provide/inject的学习使用
  6. HDU 5895 Mathematician QSC
  7. Hbuilder开发HTML5 APP之图标和启动页制作
  8. JBoss3.0 下配置和部署EJB简介
  9. 【小型JavaFx项目】文字小冒险游戏
  10. 【计算机组成原理】第1章 计算机系统概论