东大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 ...
随机推荐
- C++学习笔记【转载】
转载自:http://www.cnblogs.com/maowang1991/p/3290321.html 1.struct成员默认访问方式是public,而 class默认访问方式是private! ...
- [转][业界动态] 5G为何采纳华为力挺的Polar码?一个通信工程师的大实话
本文转自:http://xinsheng.huawei.com/cn/index.php?app=forum&mod=Detail&act=index&id=3264791 P ...
- Lucene TF-IDF 相关性算分公式(转)
Lucene在进行关键词查询的时候,默认用TF-IDF算法来计算关键词和文档的相关性,用这个数据排序 TF:词频,IDF:逆向文档频率,TF-IDF是一种统计方法,或者被称为向量空间模型,名字听起来很 ...
- 【原】ZenCoding中常用的CSS3样式
用ZenCoding这么久了,总结下常用CSS3的写法,方便以后查找: Property Alias @media print {} @m box-sizing:border-box; bxz:bb ...
- 树网的核[树 floyd]
描述 设T=(V, E, W) 是一个无圈且连通的无向图(也称为无根树),每条边到有正整数的权,我们称T为树网(treebetwork),其中V,E分别表示结点与边的集合,W表示各边长度的集合,并设T ...
- jdk8-日期
今天遇到了日期问题,看了下jdk8新特性 http://www.ibm.com/developerworks/cn/java/j-lo-jdk8newfeature/index.html Java 的 ...
- u3d_小游戏_拼图_1_生成碎片(非随机)
http://blog.csdn.net/cube454517408/article/details/7907247 首先是参考此文: main.cs作用:1.大图的拆分 2.判断是否成功 3.对碎 ...
- [No000048]程序员的成长过程中,有哪些阶段?
有人在 Quora 提问,并补充: 有木有朋友能根据你们自身经历,清晰地划分各个阶段?比如:学习第一门编程语言.第一份工作.职业决策.理解 IT 公司的目标,等等. Quincy Larson 的回复 ...
- [No000017]单词拼写记不住?试试这俩方法-单词拼写,怎么记又快又好?
- gnuplot 的安装
需要同时安装gnuplot和gnuplot-x11才能画出图 sudo apt-get install gnuplot gnuplot-x11 gnuplot not showing the grap ...