Topcoder题代码

 原题:

 

    

You have a certain amount of money to give out as a bonus to employees. The trouble is, who do you pick to receive what bonus? You decide to assign a number of points to each employee, which corresponds to how much they helped the company in the last year. You are given an vector <int> points, where each element contains the points earned by the corresponding employee (i.e. points[0] is the number of points awarded to employee 0). Using this, you are to calculate the bonuses as follows:

- First, add up all the points, this is the pool of total points awarded.
- Each employee gets a percentage of the bonus money, equal to the percentage of the point pool that the employee got.
- Employees can only receive whole percentage amounts, so if an employee's cut of the bonus has a fractional percentage, truncate it.
- There may be some percentage of bonus left over (because of the fractional truncation). If n% of the bonus is left over, give the top n employees 1% of the bonus. There will be no more bonus left after this. If two or more employees with the same number of points qualify for this "extra" bonus, but not enough bonus is left to give them all an extra 1%, give it to the employees that come first in points.

The return value should be a vector <int>, one element per employee in the order they were passed in. Each element should be the percent of the bonus that the employee gets.

Definition

    
Class: Bonuses
Method: getDivision
Parameters: vector <int>
Returns: vector <int>
Method signature: vector <int> getDivision(vector <int> points)
(be sure your method is public)
    
 

Constraints

- points will have between 1 and 50 elements, inclusive.
- Each element of points will be between 1 and 500, inclusive.

Examples

0)  
    
{1,2,3,4,5}
Returns: { 6,  13,  20,  27,  34 }
The total points in the point pool is 1+2+3+4+5 = 15.
Employee 1 gets 1/15 of the total pool, or 6.66667%, Employee 2 gets 13.33333%, Employee 3 gets 20% (exactly), Employee 4 gets 26.66667%, and Employee 5 gets 33.33333%. After truncating, the percentages look like:
{6,13,20,26,33}
Adding up all the fractional percentages, we see there is 2% in extra bonuses, which go to the top two scorers. These are the employees who received 4 and 5 points.
1)  
    
{5,5,5,5,5,5}
Returns: { 17,  17,  17,  17,  16,  16 }
The pool of points is 30. Each employee got 1/6 of the total pool, which translates to 16.66667%. Truncating for all employees, we are left with 4% in extra bonuses. Because everyone got the same number of points, the extra 1% bonuses are assigned to the four that come first in the array.
2)  
    
{485, 324, 263, 143, 470, 292, 304, 188, 100, 254, 296,
 255, 360, 231, 311, 275,  93, 463, 115, 366, 197, 470}
Returns: 
{ 8,  6,  4,  2,  8,  5,  5,  3,  1,  4,  5,  4,  6,  3,  5,  4,  1,  8,
  1,  6,  3,  8 }
我的代码:
#include <iostream>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
using namespace std;
class  Bonuses{
public:
 vector <int> getDivision(vector <int> points);
};
vector <int> Bonuses::getDivision(vector<int> points)
{
 float    sum=0;
 int       leave=0,save=100,tag=0;
 vector<int> stvec,hvec;
 vector<int>::iterator    iter;
 for (iter=points.begin();iter!=points.end();++iter)
 {
  sum+=*iter;
 }
 for (int y=0;y!=points.size();++y)
 {
  leave=(int)(((float)points[y]/(float)sum)*100);
  stvec.push_back(leave);
  save-=leave;
 }
 vector<int> temvec(points);
 sort(temvec.begin(),temvec.end(),greater<int>());
 for (int k=0;k<save;++k)
 {
  hvec.push_back(temvec[k]);
 }
 for (int z=0;z<points.size();++z)
 {
  if (count(hvec.begin(),hvec.end(),points[z]))
  {
   stvec[z]++;
   tag++;
  }
  if (tag==save)
  {
   break;
  }
 }
 return    stvec;
}
int  main()
{
 int   input;
 Bonuses    A;
 vector<int>  avec,bvec;
 while (cin>>input)
 {
  avec.push_back(input);
 }
 bvec=A.getDivision(avec);
 for (int i=0;i<bvec.size();++i)
 {
  cout<<bvec[i]<<' ';
 }
 return 0;
}
 牛人代码:
#include <iostream>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <string>
#include <vector>
#include <list>
using namespace std;
class  Bonuses{
public:
 vector <int> getDivision(vector <int> points);
};
vector <int> Bonuses::getDivision(vector<int> points)
{
 vector<int>vPercent;
 int  total=accumulate(points.begin(),points.end(),0);
 vector<int>::iterator   it=points.begin();
 int  left=100;
 int  n;
 for (;it!=points.end();++it)
 {
  n=*it*100/total;
  left-=n;
  vPercent.push_back(n);
 }
 vector<int>vTmp(points);
 while(left>0)
 {
  it=max_element(vTmp.begin(),vTmp.end());
  *it=-1;
  --left;
 }
 it=vPercent.begin();
 vector<int>:: const_iterator  itTmp=vTmp.begin();
 for (;it!=vPercent.end();++it,++itTmp)
 {
  if (*itTmp==-1)
  {
   ++(*it);
  }
 }
 return  vPercent;
}
int  main()
{
 int   input;
 Bonuses    A;
 vector<int>  avec,bvec;
 while (cin>>input)
 {
  avec.push_back(input);
 }
 bvec=A.getDivision(avec);
 for (int i=0;i<bvec.size();++i)
 {
  cout<<bvec[i]<<' ';
 }
 return 0;
}
 

 

 

一、基础信息 数据集名称:Bottle Fin实例分割数据集 图片数量: 训练集:4418张图片 验证集:1104张图片 总计:5522张图片 分类类别: - 类别0: 数字0 - 类别1: 数字1 - 类别2: 数字2 - 类别3: 数字3 - 类别4: 数字4 - 类别5: 数字5 - 类别6: Bottle Fin 标注格式:YOLO格式,包含多边形坐标,适用于实例分割任务。 数据格式:图片格式常见如JPEG或PNG,具体未指定。 二、适用场景 实例分割AI模型开发:数据集支持实例分割任务,帮助构建能够精确识别和分割图像中多个对象的AI模型,适用于对象检测和分割应用。 工业自动化与质量控制:可能应用于制造、物流或零售领域,用于自动化检测和分类物体,提升生产效率。 计算机视觉研究:支持实例分割算法的学术研究,促进目标检测和分割技术的创新。 教育与实践培训:可用于高校或培训机构的计算机视觉课程,作为实例分割任务的实践资源,帮助学生理解多类别分割。 三、数据集优势 多类别设计:包含7个不同类别,涵盖数字和Bottle Fin对象,增强模型对多样对象的识别和分割能力。 高质量标注:标注采用YOLO格式的多边形坐标,确保分割边界的精确性,提升模型训练效果。 数据规模适中:拥有超过5500张图片,提供充足的样本用于模型训练和验证,支持稳健的AI开发。 即插即用兼容性:标注格式直接兼容主流深度学习框架(如YOLO),便于快速集成到各种实例分割项目中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值