东大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 ...
随机推荐
- iNeedle日志下载功能问题
问题: iNeedle系统本身包含日志下载功能,主要是将web服务器中的用户访问日志按照一定条件进行筛选并下载,提供管理者分析.但是这次的测试中发现iNeedle日志下载一直会卡住,web界面显示正在 ...
- (转)yii流程,入口文件下的准备工作
yii流程 一 目录文件 |-framework 框架核心库 |--base 底层类库文件夹,包含CApplication(应用类,负责全局的用户请求处理,它管理的应用组件集, ...
- android viewpager 图片翻页例子
使用ViewPager这个类可以轻松实现多个页面的滑动功能 viewpager默认在工具界面上是找不到的,需求添加android-support-v4.jar包: 如果没有找到,需要打开Android ...
- android 滑动滚动条调节音量
利用滚动条滑动控制音量: 定义: private SeekBar mseekBarvolume: 以下实现代码: //调节音量--begin------------------------- //音量 ...
- linux线程同步(4)-自旋锁
自旋锁与互斥量功能一样,唯一一点不同的就是互斥量阻塞后休眠让出cpu,而自旋锁阻塞后不会让出cpu,会一直忙等待,直到得到锁!!! 自旋锁在用户态使用的比较少,在内核使用的比较多!自旋锁的使用场景:锁 ...
- Tomcat免安装配置2
Tomcat 是一款优秀的JSP/Servlet容器,最初由SUN开发,后来被贡献给了Apache社区.Tomcat现在的版本已到6.Tomcat6实现了Servlet2.5和JSP2.1规范.针对w ...
- shell流程控制
if语句 判断条件用[]包裹起来 if [ $a > $b ] then echo ‘a > b’ elif [ $a < $b ] then echo ‘a < b’ els ...
- [转]ANDROID NOTIFICATIONS USING CORDOVA AND IONIC
本文转自:http://intown.biz/2014/04/11/android-notifications/ ANDROID NOTIFICATIONS USING CORDOVA AND ION ...
- POJ3666Making the Grade[DP 离散化 LIS相关]
Making the Grade Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6445 Accepted: 2994 ...
- 关于OAUTH2.0的极品好文
Web Server Flow: web ServerFlow是把oauth1.0的三个步骤缩略为两个步骤 首先这个是适合有server的第三方使用的. 1客户端http请求authorize 2服务 ...