GYM 101606 I.I Work All Day(水~)

Description

给出 n 个整数 h i 和一整数 T ,问 T % h i 的最小值

Input

第一行一整数 n 表示整数个数,之后输入 n 个整数 h i 和一个整数 T

( 2 n 10 , 1 h i 500 , 1 T 3000 )

Output

输出使得 T % h i 最小的 h i ,如果多组解则输出 h i 的最小值

Sample Input

3
5 6 8
103

Sample Output

6

Solution

水题

Code

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=105;
int n,h[maxn],t;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&h[i]);
    scanf("%d",&t);
    int ans=1;
    for(int i=2;i<=n;i++)
        if(t%h[i]<t%h[ans])ans=i;
    printf("%d\n",h[ans]);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/v5zsq/article/details/80449920