东大OJ-Max Area
1034: Max Area
时间限制: 1 Sec 内存限制: 128 MB
提交: 40 解决: 6
[提交][状态][讨论版]
题目描述
输入
输出
样例输入
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 */
东大OJ-Max Area的更多相关文章
- [转][Swust OJ 24]--Max Area(画图分析)
转载自:http://www.cnblogs.com/hate13/p/4160751.html Max Area 题目描述:(链接:http://acm.swust.edu.cn/problem/2 ...
- [Swustoj 24] Max Area
Max Area 题目描述: 又是这道题,请不要惊讶,也许你已经见过了,那就请你再来做一遍吧.这可是wolf最骄傲的题目哦.在笛卡尔坐标系正半轴(x>=0,y>=0)上有n个点,给出了这些 ...
- leetcode 200. Number of Islands 、694 Number of Distinct Islands 、695. Max Area of Island 、130. Surrounded Regions
两种方式处理已经访问过的节点:一种是用visited存储已经访问过的1:另一种是通过改变原始数值的值,比如将1改成-1,这样小于等于0的都会停止. Number of Islands 用了第一种方式, ...
- LintCode 383: Max Area
LintCode 383: Max Area 题目描述 给定 n 个非负整数 a1, a2, ..., an, 每个数代表了坐标中的一个点 (i, ai).画 n 条垂直线,使得 i 垂直线的两个端点 ...
- [leetcode]python 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 ...
- Leetcode之深度优先搜索(DFS)专题-695. 岛屿的最大面积(Max Area of Island)
Leetcode之深度优先搜索(DFS)专题-695. 岛屿的最大面积(Max Area of Island) 深度优先搜索的解题详细介绍,点击 给定一个包含了一些 0 和 1的非空二维数组 grid ...
- C#LeetCode刷题之#695-岛屿的最大面积( Max Area of Island)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3736 访问. 给定一个包含了一些 0 和 1的非空二维数组 gr ...
- 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 ...
- [LeetCode] 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 ...
- [Swift]LeetCode695. 岛屿的最大面积 | 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 ...
随机推荐
- linux下创建用户
linux下创建用户(一) Linux 系统是一个多用户多任务的分时操作系统,任何一个要使用系统资源的用户,都必须首先向系统管理员申请一个账号,然后以这个账号的身份进入系统.用户的账号一方面可以帮助系 ...
- Windows批处理:自动检查网络连通性
检测网络连通性我用的是丛远到近的方法,即“外网——网关——内网——本机”,脚本的实现也是根据这个顺序用ping来检测,为提高检测速度,这里我只ping了2次,各位可以根据自己的需要进行修改. 使用方法 ...
- Ubuntu14.04桌面版基本配置
最近公司需要用Ubuntu测试一些功能,安装好后绚丽的桌面环境很是吸引人,但切换到字符界面后,发现不少地方与RHEL不一样,连ssh.vim都没有,字符界面玩得不开心. 搜了不少文章,才将基本的功能配 ...
- C中的数组与指针问题
反复在数组名与指针上犯错误,特记录下. ,,,,}; int *p, *q; p = (); q = (); *(p+1)? *(q-1) ? 答案是 3, 5.这里主要涉及的问题就是指针参与运算 ...
- ImageMagick Remote Command Execute
CVE ID: CVE-2016-3714 我挺纠结应该用中文写博客还是应该用英文写博客.英文吧作用挺明显的,可以锻炼自己的英语表达能力,但是可能会阻碍和一些英文不好的朋友交流. It's upset ...
- 三维网格去噪算法(L0 Minimization)
[He et al. 2013]文章提出了一种基于L0范数最小化的三角网格去噪算法.该思想最初是由[Xu et al. 2011]提出并应用于图像平滑,假设c为图像像素的颜色向量,▽c为颜色向量的梯度 ...
- ArrayList如何实现线程安全
一:使用synchronized关键字,这个大家应该都很熟悉了,不解释了: 二:使用Collections.synchronizedList();使用方法如下: 假如你创建的代码如下:List< ...
- Unity Camera的两种模式
http://www.cnblogs.com/zhaoqingqing/p/3302484.html
- django复习笔记3:实战
1.初始化 2.配置后台,增加测试数据 3.测试urls/views/templates 4.增加静态资源 5.修改样式 6.模版继承 7.增加博文主页 8.增加表单 9.完善新增页面和编辑页面的表单 ...
- win7 远程桌面关机
在任务管理器中, 打开运行窗口, 执行 shutdown -s 命令, 将在30秒后关闭win7, 如果需要更快, 加上 -t 10 参数 关于 shutdown 的命令行说明: C:\Users\R ...