ACMer第7天Falling Ants

简介: le-interchange-newline">6650Falling AntsAnts make up 10% of the total world animal tissue. Thetotal biomass of all the ants on Earth is roughly ...
le-interchange-newline"> 6650Falling Ants
Ants make up 10% of the total world animal tissue. The
total biomass of all the ants on Earth is roughly equal to the
total biomass of all the p eople on Earth. However, unlike
the p eople on Earth when they fall from a height they do
not die for two reasons:
They have so little mass relative to their air resistance
that they fall slowly and, therefore, have little energy
to dissipate when they hit the ground.
Their b o dies are tiny deformable tanks, well designed
to absorb blows.
In general, small ob jects have less impact of gravitation
on them b ecause they have more surface area/volume compared to larger ob jects. For example consider
a (1x1x1) cub e. Its surface area is 6 and volume is 1. So the ratio is 6:1 and for a (10x10x10) cub e the
surface area is 600 and volume is 1000. So the ratio is 6:10. Given the shap e of many ants you will
have to find out which ant has the highest effect of gravitation on it.
For simplicity we will assume the following things in this
problem:
1. All ants are described as a box shaped object. A box
shaped object is described with three integersL,W,
andH which denotes the length, width and height of
the object. So the volume of the ant is (L ×W×H).
2. The density (Mass per unit volume) is 1. So the mass
of the above mentioned ant is also (L ×W×H) and so
the weight is (L ×W×H)× g(Hereg is the acceleration
caused by gravitation).
3. When an ant freely falls four sides are upright and
so the faces at the top and bottom are parallel with
the horizon. So the area of the plane facing bottom
is alwaysL ×W. For any ant the upward force put
by the air is proportional to the area of the of the
bottom face. To be specific it isL ×W2× g. After some
manipulation it can be proved that the downward accelerationf =g 2gH. So the downward acceleration actually depends solely on the value of H
(asg is same for all ants).
Given the dimension of several ants, report the volume of the ant that has the highest downward
acceleration. If there is a tie, report the one with the largest volume.
Universidad de Valladolid OJ:6650 – Fal ling Ants 2/2
Input
The input file contains at most 500 test cases. The description of each test case is given below:
First line of each test case contains an integerT (T 100) which denotes the total number of ants
to consider. Each of the nextT lines contains three integers which denote the value ofL,W andH
(1L, W, H50) of an ant respectively.
Input is terminated by a line containing a single zero.
Output
For each set of input produce one line of output. This line contains the volume of the ant that has the
highest downward acceleration. If there is a tie report the ant with the highest volume.
Sample Input
3
3 4 5
12 1 5
20 10 4
3
3 4 5
20 30 5
1 2 4
0
Sample Output
60

3000


这道题本来是有图的,不过有图没图都是一样的,题目的大意就是求蚂蚁下落的最大加速度,所有公式都给我们了,而且题目也规定了情况也是最好的,本来应该说是一道很水的题目,然而在水题上依然可以看出差距来,小生愚钝,用的优先队列。

#include<cstdio>
#include<algorithm>
#include <queue>
#define maxn1 105
using namespace	std;
struct ants{
	int l,w,h;
	int v;
};
bool operator < (struct ants a,struct ants b){
	if(a.h == b.h){
		if(a.v < b.v)
			return	true;
		else
			return	false;
	}else{
		if(a.h < b.h)
			return	true;
		else
			return	false;
	}
}
int main(){
	int n;
	while(scanf("%d",&n) && n){
		struct ants now[maxn1];
		priority_queue<struct ants> lis;
		for(int i = 0;i < n;i++){
			scanf("%d %d %d",&now[i].l,&now[i].w,&now[i].h);
			now[i].v = now[i].h*now[i].l*now[i].w;
			lis.push(now[i]);
		}
		struct ants t = lis.top();
		printf("%d\n",t.v);
	}
	return	0;
}

然而最简单的方法也是更优美的解法应该是用类似在线算法的做法

#include<iostream>
using namespace std;
int main(){
	int n;
	while(cin>>n&&n){
		int l,w,h,maxs=0,maxh=0;
		for(int i=1;i<=n&&cin>>l>>w>>h;i++){
			if(h>maxh){maxh=h;maxs=l*w;}
	        if(h==maxh&&l*w>maxs)maxs=l*w;
	    }
	    cout<<maxs*maxh<<'\n';
	}
}

简单易懂又简洁明了.

相关文章
|
存储 OLAP OLTP
漫谈OceanBase 列式存储
列式存储主要的目的有两个: 大部分OLAP查询只需要读取部分列而不是全部列数据,列式存储可以避免读取无用数据; 将同一列的数据在物理上存放在一起,能够极大地提高数据压缩率。 OLAP和OLTP OLAP,也叫联机分析处理(Online Analytical Processing)系统,有的时候也叫DSS决策支持系统,就是我们说的数据仓库。
6669 0
|
供应链 算法 数据挖掘
一文看懂:销售数据分析怎么做?
今天跟大家分享数据分析里最高频的一个工作:销售分析。不管是实打实挣钱的公司,还是指望上市圈钱的公司,销售业绩都是领导们最看重的指标。 很多人从事数据分析工作,也是从基础的“销售统计专员”做起的。今天就简单分享下,销售分析该如何做。
1108 0
一文看懂:销售数据分析怎么做?
|
机器学习/深度学习 算法 计算机视觉
基于多注意力融合的抗遮挡目标跟踪算法综述
基于多注意力融合的抗遮挡目标跟踪算法综述
910 0
基于多注意力融合的抗遮挡目标跟踪算法综述
|
存储 机器学习/深度学习 弹性计算
云服务器ECS选购指南及省钱法宝(强烈建议收藏)
云服务器ECS怎么选,怎样更省钱?这一篇就够了
云服务器ECS选购指南及省钱法宝(强烈建议收藏)
|
前端开发 Java uml
Spring官网阅读(十五)Spring中的格式化(Formatter)
在上篇文章中,我们已经学习过了Spring中的类型转换机制。现在我们考虑这样一个需求:在我们web应用中,我们经常需要将前端传入的字符串类型的数据转换成指定格式或者指定数据类型来满足我们调用需求,同样的,后端开发也需要将返回数据调整成指定格式或者指定类型返回到前端页面。这种情况下,Converter已经没法直接支撑我们的需求了。这个时候,格式化的作用就很明显了,这篇文章我们就来介绍Spring中格式化的一套体系。本文主要涉及官网中的3.5及3.6小结
476 0
Spring官网阅读(十五)Spring中的格式化(Formatter)
|
存储 NoSQL Java
【Docker】笔记小结
【Docker】笔记小结
1142 0
【Docker】笔记小结
|
Python Windows
Python批量将MP3音频转为WAV格式(附代码) | Python工具
Python批量将MP3音频转为WAV格式(附代码) | Python工具
Python批量将MP3音频转为WAV格式(附代码) | Python工具
|
云安全 安全 druid
5 分钟复现 log4J 漏洞,手把手实现
5 分钟复现 log4J 漏洞,手把手实现
2109 0
5 分钟复现 log4J 漏洞,手把手实现
|
存储 Java 视频直播
OSS 解决方案篇-OSS 结合 视频直播使用
OSS 作为多媒体的使用,不仅能结合媒体处理使用,也可以结合视频直播,作为 录制、截图的存储原站;
3279 0
OSS 解决方案篇-OSS 结合 视频直播使用
|
SQL 监控 关系型数据库
八大案例,带你参透SQL Server优化
在本文中,石沫针对用户遇到的各种实际问题,从实例层次到架构,通过8个SQL Server优化案例,分享了如何用最简单快捷的方式解决用户使用SQL Server数据库过程中的典型问题,使SQL Server能够稳定地提供持续服务。
14124 0