A. K-divisible Sum
题目传送门:
题目大意:
要你使n个数相加的和是k的倍数,并使n个数中最大的数最小
(水题直接上代码)
AC Code
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,k;
scanf("%d%d",&n,&k);
int res=0;
if(k>=n)
{
res=k/n;
if(k%n) res++;
}
else
{
if(n%k) res=2;
else res=1;
}
printf("%d\n",res);
}
//system("pause");
return 0;
}
B. Inflation
题目传送门:
题目大意:
一件商品的初始价格为P0,第i天价格上涨Pi。通货膨胀率为Pi / ( P0+P1+P2+……Pi-1 )。为了使每天通货膨胀率小于k%,你可以修改pi,问最少修改多少。
思路:
我们想如果从前往后遍历到一个位置如果通货膨胀率超过了k%,那么我们肯定是要增大分母的值以减小当前的值以及后续的值,如果你减小了分母以减小当前的值,那么后续的值可能会增大。
AC Code
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL a[105];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
LL n,k;
scanf("%lld%lld",&n,&k);
for(int i=1;i<=n;i++)
scanf(