由于第一天在博客园开博客,我随便写个解题报告吧,以前很少写

codeforces160A,题目链接:http://codeforces.com/problemset/problem/160/A

A题一般都是水题啦,第一次还是选个最简单的吧。

你和另一个人分硬币,题目的规则:you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins;

这个题目算法思想就是贪心,我感觉一般贪心里面,排序是要经常用的,简单排下序,然后计算硬币数就ok了

贴代码:

//by hust_archer

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
int cmp(int a,int b)
{
return a>b;
}
using namespace std;
int main()
{
int n,sum=0;
int ans=0;
int tmp=0;
int a[105];
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
sort(a,a+n,cmp);
while(tmp<=sum-tmp)
tmp+=a[ans++];
printf("%d ",ans);
return 0;
}

原文地址:https://www.cnblogs.com/ruixingw/p/3633079.html