0
点赞
收藏
分享

微信扫一扫

B. Preparation for International Women‘s Day(思维)Codeforces Round #544 (Div. 3)

原题链接: ​​https://codeforces.com/problemset/problem/1133/A​​

B. Preparation for International Women‘s Day(思维)Codeforces Round #544 (Div. 3)_i++
测试样例

Input
7 2
1 2 2 3 2 4 10
Output
6
Input
8 2
1 2 2 3 2 4 6 10
Output
8
Input
7 3
1 2 2 3 2 4 5
Output
4

Note

In the first example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
(2,3);
(5,6);
(1,4).
So the answer is 6.
In the second example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
(6,8);
(2,3);
(1,4);
(5,7).
So the answer is 8.
In the third example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):
(1,2);
(6,7).
So the answer is 4.

题意: 让你找出最多有多少个礼物可以被送出去,送出去的条件为礼物对的数量总和需要能整除B. Preparation for International Women‘s Day(思维)Codeforces Round #544 (Div. 3)_i++_02

解题思路: 我们这个题很容易发现,我们并不在乎礼物的大小,我们只在乎礼物对B. Preparation for International Women‘s Day(思维)Codeforces Round #544 (Div. 3)_#define_03取余的结果,若为B. Preparation for International Women‘s Day(思维)Codeforces Round #544 (Div. 3)_整除_04,则能整除,则再与一个这样的组合即可送出去,若为B. Preparation for International Women‘s Day(思维)Codeforces Round #544 (Div. 3)_整除_05,则我们需要找到一个礼物对B. Preparation for International Women‘s Day(思维)Codeforces Round #544 (Div. 3)_#define_03取余为B. Preparation for International Women‘s Day(思维)Codeforces Round #544 (Div. 3)_#define_07的即可组合送出去。 故我们的目的所在其实就是寻找组合数量,我们可以先利用B. Preparation for International Women‘s Day(思维)Codeforces Round #544 (Div. 3)_整除_08记录余数的个数,最后遍历即可解决,要注意我们并不是求对的数量,而是求礼物的数量。

AC代码

/*

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

#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=a;i>=n;i--)

using namespace std;

const int inf=0x3f3f3f3f;//无穷大。
const int maxn=2e5+10;//限定值。
typedef long long ll;

int n,k;
int a[maxn];
int main(){
while(cin>>n>>k){
map<int,int> p;
rep(i,1,n){
cin>>a[i];
p[a[i]%k]++;
}
int ans=p[0]/2*2;
for(int i=1;i*2<=k;i++){
if(i==k-i){
ans+=p[i]/2*2;
}
else{
ans+=min(p[i],p[k-i])*2;
}
}
cout<<ans<<endl;
}
return 0;
}


举报

相关推荐

0 条评论