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
(1≤ L, W, H≤50) 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';
	}
}

简单易懂又简洁明了.

相关文章
|
1天前
|
监控 网络协议 算法
2026年起SSL证书有效期逐年缩短:企业如何避免“续期风暴”!
SSL证书有效期将从2026年起分三阶段逐步缩短至47天,人工续期难以为继。阿里云“WoSign SSL证书+自动化服务”,支持域名监控、自动托管、云产品/服务器一键部署及智能提醒,助力企业高效应对高频续期挑战。
8045 0
|
10天前
|
域名解析 人工智能 Linux
|
20天前
|
Linux Go 开发工具
手机上跑 DeepSeek 智能体:开源安卓客户端 DSH Go 安装与使用指南
DSH Go 是一款开源安卓客户端,将 DeepSeek Harness 智能体引擎装进手机:免 Root、免 Termux,一键安装即用;支持本机运行(内置 Ubuntu+Node.js)或远程接管电脑会话;具备插话打断、过程折叠、屏幕操控、端到端加密分享等特色功能,真正实现智能体“口袋化”。
17945 63
|
18天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
|
4天前
|
人工智能 安全 网络安全
|
1天前
|
人工智能 弹性计算 安全
阿里云 码上2027 AI coding 嘉年华
阿里云“码上2027”AI Coding嘉年华于2026年12月2—3日在上海西岸艺术中心举行,聚焦AI Coding从单点提效迈向企业级研发体系升级。发布Qwen4-max模型、QBot智能协作、AgentCore平台等重磅成果,并推出ECS云服务器特惠(200Mbps流量月付40元起)。
753 0
|
7天前
|
云安全 数据采集 人工智能
|
9天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是 DeepSeek AI 开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、执行命令、处理表格等自动化任务;免费开源,兼容 Win/macOS,需配 API 密钥使用。(239字)
1445 5
|
15天前
|
人工智能 开发工具 开发者
2026最新codex下载安装保姆级使用教程(下载+安装+登录+使用,含所有历史版本)
Codex 是 OpenAI 推出的开源 AI 编程智能体,跑在本地终端和桌面客户端里,能读懂整个代码仓库,一句自然语言就能让它改代码、执行命令、跑测试、修 Bug,支持 Windows、macOS、Linux 三大平台。本文把 Codex下载、安装、登录、汉化、基础使用一次讲全,并整理了国内用户最常踩的坑,跟着做 10 分钟就能跑起来。
2539 8
|
20天前
|
弹性计算 人工智能 API
Codex超详细入门指南(下载·安装·登录·上手,全版本覆盖,2026最新版)
建议收藏本教程,2026 全年各版本更新随时回来查阅。如果你在搭建过程中遇到任何问题,欢迎结合 阿里云工单系统 提交技术支持请求,或在 阿里云开发者社区 搜索 Codex 相关话题交流。 祝你编码愉快,效率翻倍!
4041 22