Codeforces Round #621 (Div. 1 + Div. 2)
[codeforces 1304B] Cow and Friend 除+模
总目录详见https://blog.csdn.net/mrcrack/article/details/103564004
在线测评地址https://codeforces.ml/contest/1307/problem/B
Problem | Lang | Verdict | Time | Memory |
---|---|---|---|---|
B - Cow and Friend | GNU C++11 | Accepted | 46 ms | 200 KB |
举个例子
Input3:
1
1 10
3
Output3:
4
构图如下
再多举几个例子,弄明白了,算法也就基本明白了。
提一句,题中的思路是给手工算算的,要给计算机 算,还得读者自己再归纳。
Input1:
1
1 10
1
Output1:
10
Input2:
1
1 10
2
Output2:
5
Input3:
1
1 10
3
Output3:
4
Input4:
1
1 10
4
Output4:
3
Input5:
1
1 10
5
Output5:
2
Input6:
1
1 10
6
Output6:
2
Input7:
1
1 10
7
Output7:
2
Input8:
1
1 10
8
Output8:
2
Input9:
1
1 10
9
Output9:
2
Input10:
1
1 10
10
Output10:
1
Input11:
1
1 10
11
Output11:
2
Input12:
1
1 10
12
Output12:
2
Input13:
1
1 10
100
Output13:
2
AC代码如下
#include <stdio.h>
int a[100010];
int min(int a,int b){
return a<b?a:b;
}
int main(){
int t,n,x,i,mn;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&x),mn=1000000010;
for(i=1;i<=n;i++)scanf("%d",&a[i]);
for(i=1;i<=n;i++){
if(a[i]<=x)a[i]=x/a[i]+(x%a[i]>0);
else a[i]=2;//a[i]>x
mn=min(mn,a[i]);
}
printf("%d\n",mn);
}
return 0;
}