东大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 ...
随机推荐
- Keil代码中for循环延时问题
- ORACLE之ASM概念
一. ASM(自动存储管理)的来由: ASM是Oracle 10g R2中为了简化Oracle数据库的管理而推出来的一项新功能,这是Oracle自己提供的卷管理器,主要用于替代操作系统所提供的 ...
- Java基础-super关键字与this关键字
用super调用父类构造方法 类如果没有显式声明构造方法,则自动生成无参数的默认构造方法. 1.先用一个无参数的父类构造方法验证一下, 执行子类构造方法会自动调用父类的构造方法.测试代码: class ...
- [cocos2d-x]深入--几个代表性的类
摘要: 此文对cocos2d-x引擎中最具代表性,最能体现框架结构的几个类做了简单的介绍, 包括Director,Application, Renderer, EventDispatcher, Sch ...
- Codeforces Round #285 (Div.1 B & Div.2 D) Misha and Permutations Summation --二分+树状数组
题意:给出两个排列,求出每个排列在全排列的排行,相加,模上n!(全排列个数)得出一个数k,求出排行为k的排列. 解法:首先要得出定位方法,即知道某个排列是第几个排列.比如 (0, 1, 2), (0, ...
- 2016"百度之星" - 初赛(Astar Round2B)
Problem Description 中位数定义为所有值从小到大排序后排在正中间的那个数,如果值有偶数个,通常取最中间的两个数值的平均数作为中位数. 现在有n个数,每个数都是独一无二的,求出每个数在 ...
- POJ3255Roadblocks[次短路]
Roadblocks Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 12697 Accepted: 4491 Descr ...
- 云计算之路-阿里云上:RDS用户的烦恼
http://www.cnblogs.com/cmt/p/3586029.html *博主注:阿里云数据库真的这么可笑?
- idea常用快捷键
十大Intellij IDEA快捷键 2015-01-16 21:31 122307人阅读 评论(38) 收藏 举报 本文章已收录于: .embody { padding: 10px 10px 10p ...
- nmap脚本扫描使用总结
nmap的脚本默认目录为:/usr/share/nmap/scripts/ Nmap提供的命令行参数如下 -sC: 等价于--script=default,使用默认类别的脚本进行扫描 可更换其他类别 ...