东大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 ...
随机推荐
- [译] 企业级 OpenStack 的六大需求(第 2 部分):开放架构和混合云兼容
全文包括三部分: 第一部分:API 高可用和管理以及安全模型 第二部分:开放架构和混合云兼容 第三部分:弹性架构和全球交付 在本系列的第一部分,我介绍了企业级 OpenStack 的六大需求.现在,我 ...
- [转]阿里云配置mysql远程连接
默认是不能用客户端远程连接的,阿里云提供的help.docx里面做了设置说明,mysql密码默认存放在/alidata/account.log 首先登录: mysql -u root -h local ...
- 第10章 同步设备I/O和异步设备I/O(1)_常见设备及CreateFile函数
10.1 打开和关闭设备 10.1.1 设备的定义——在Windows中可以与之进行通信的任何东西. (1)常见设备及用途 设备 用途 用来打开设备的函数 文件 永久存储任何数据 CreateFile ...
- Java中的单例模式
单例模式: public class Person{ public static Person per; //定义一个静态变量,用来存储当前类的对象 private Person() //构造一个私有 ...
- win7旗舰版 中文64位 产品密钥(序列号)
无需破解即可激活Windows 7旗舰版的"神Key". 第一枚"神Key":TFP9Y-VCY3P-VVH3T-8XXCC-MF4YK: 第二枚"神 ...
- date时间函数
时间函数: date();和time();的相互转换 time(); 在PHP中单位是秒,在js中是毫秒. microtime(); 毫秒 date('Y-m-d H:i:s',time()); ...
- java 25 - 3 网络编程之 Socket套接字
Socket Socket套接字: 网络上具有唯一标识的IP地址和端口号组合在一起才能构成唯一能识别的标识符套接字. Socket原理机制: 通信的两端都有Socket. 网络通信其实就是Socket ...
- 转: YAML 语言教程 from(阮一峰)
YAML 语言教程 from: http://www.ruanyifeng.com/blog/2016/07/yaml.html
- python-数据类型补充及文件处理操作
___数据类型____ 一.列表的复制 浅复制和深复制 浅复制只复制一层,深复制完全克隆,慎用 1.实现浅复制的三种方式: name=['song','xiao','nan'] import copy ...
- ajax设置自定义请求头信息
客户端请求 $.ajax({ type:"post", url:urlstr, dataType:'json', async:true, headers:{token:'abck' ...