AtCoder Beginner Contest 113 B
B - Palace
Time limit : 2sec / Memory limit : 1024MB
Score: 200 points
Problem Statement
A country decides to build a palace.
In this country, the average temperature of a point at an elevation of x meters is T−x×0.006 degrees Celsius.
There are N places proposed for the place. The elevation of Place i is Hi meters.
Among them, Princess Joisino orders you to select the place whose average temperature is the closest to A degrees Celsius, and build the palace there.
Print the index of the place where the palace should be built.
It is guaranteed that the solution is unique.
Constraints
- 1≤N≤1000
- 0≤T≤50
- −60≤A≤T
- 0≤Hi≤105
- All values in input are integers.
- The solution is unique.
Input
Input is given from Standard Input in the following format:
N T A H1 H2 … HN
Output
Print the index of the place where the palace should be built.
Sample Input 1
2 12 5 1000 2000
Sample Output 1
1
- The average temperature of Place 1 is 12−1000×0.006=6 degrees Celsius.
- The average temperature of Place 2 is 12−2000×0.006=0 degrees Celsius.
Thus, the palace should be built at Place 1.
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <queue> #include <stack> #include <cstdlib> #include <iomanip> #include <cmath> #include <cassert> #include <ctime> #include <cstdlib> #include <map> #include <set> using namespace std; #pragma comment(linker, "/stck:1024000000,1024000000") #define lowbit(x) (x&(-x)) #define max(x,y) (x>=y?x:y) #define min(x,y) (x<=y?x:y) //#define MAX 100000000000000000 #define MOD 1000000007 #define pi acos(-1.0) #define ei exp(1) #define PI 3.1415926535897932384626433832 #define ios() ios::sync_with_stdio(true) #define INF (1<<31)-1; #define mem(a) (memset(a,0,sizeof(a))) int main() { double MAX = INF; int N,T,A; int pre; int deg; double result; cin>>N; cin>>T>>A; for(int i=1;i<=N;i++){ cin>>deg; result = abs(A - (T-deg*0.006)); if(result < MAX){ MAX = result; pre = i; //cout<<MAX<<endl; } } cout<<pre<<endl; return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~