• AtCoder Beginner Contest 113 B


    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 Tx×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≤AT
    • 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

    Copy

    2
    12 5
    1000 2000
    

    Sample Output 1

    Copy

    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.


    Sample Input 2

    Copy

    3
    21 -11
    81234 94124 52141
    

    Sample Output 2

    Copy

    3
    #include<iostream>
    #include<cmath>
    using namespace std;
    
    double s[100000];
    
    int main()
    {
    	int n,m,j,k,i,t,ans,T,a,b;
    	cin>>n;
    	cin>>a>>b;		
    	for (i=0;i<n;i++)
    	{
    		cin>>s[i];
    		s[i]  = a - 0.006*s[i];
    	}
    	double min = 1000000000.0;
    	for (i=0;i<n;i++)
    	{
    		if (fabs(s[i] - b)<= min)
    		{
    			min = fabs(s[i]-b);
    			ans = i; 
    		}
    	}
    	cout<<ans+1<<endl;
    	return 0;
    } 
  • 相关阅读:
    添加远程库
    远程仓库
    删除url中某个参数
    html2canvas.js——HTML转Canvas工具
    vue-cli3与vue-cli2的区别和vue-cli 怎么修改配置
    vue打包后出现一些map文件的解决方法
    微信app右上角自带分享功能
    微信授权获取用户openId的方法和步骤
    支付宝小程序webview里的h5跳转回小程序
    new Date
  • 原文地址:https://www.cnblogs.com/Romantic-Chopin/p/12451232.html
Copyright © 2020-2023  润新知