0
点赞
收藏
分享

微信扫一扫

A. Copy-paste(贪心算法)Codeforces Round #673 (Div. 2)

王老师说 2022-06-24 阅读 57

原题链接: ​​https://codeforces.com/contest/1417/problems​​

A. Copy-paste(贪心算法)Codeforces Round #673 (Div. 2)_ios
测试样例

input
3
2 2
1 1
3 5
1 2 3
3 7
3 2 2
output
1
5
4

Note

In the first test case we get either a=[1,2] or a=[2,1] after casting the spell for the first time, and it is impossible to cast it again.

题意: 给你一个数组和一个限定值A. Copy-paste(贪心算法)Codeforces Round #673 (Div. 2)_#define_02,你可以进行法术使得:
A. Copy-paste(贪心算法)Codeforces Round #673 (Div. 2)_数组_03 and A. Copy-paste(贪心算法)Codeforces Round #673 (Div. 2)_#define_04 ,让A. Copy-paste(贪心算法)Codeforces Round #673 (Div. 2)_数组_05

当进行法术操作使得其中有一个元素超过限定值A. Copy-paste(贪心算法)Codeforces Round #673 (Div. 2)_#define_02时,你都将失去该法术能力,即法术无效。问你最多能使用多少次法术。

解题思路: 一道简单的贪心问题,我们想要让法术使用次数达到最多,就要尽可能的使用小数去加,那么我们可以对该数组进行排序,以最小的数作为加数赋给其余元素。这样即可最优。

AC代码

/*

*
*/
#include<bits/stdc++.h> //POJ不支持

#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair

using namespace std;

const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//

int t,n,k;
int a[maxn];
int main(){
//freopen("in.txt", "r", stdin);//提交的时候要注释掉
IOS;
while(cin>>t){
while(t--){
cin>>n>>k;
rep(i,0,n-1){
cin>>a[i];
}
sort(a,a+n);
ll cnt=0;
rep(i,1,n-1){
if((k-a[i])/a[0]==0){
break;
}
cnt+=(k-a[i])/a[0];
}
cout<<cnt<<endl;
}
}
return 0;
}


举报

相关推荐

0 条评论