• 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 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.

    #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;
    }
  • 相关阅读:
    Android.02.Button
    Android.01. TextView
    Android.00.IDEA中Android开发环境搭建
    Java34.Marven
    CSS 滚动条样式
    不常用的HTML和CSS 记录
    JS 规则
    svg转化成canvas以便生成base64位的图片
    ArcGIS Server 10.1 安装教程
    ArcGis API JS 4.X 本地化部署
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/9906673.html
Copyright © 2020-2023  润新知