poj1245解题报告

//题目意思比较容易看懂,在这里不说了//不明白的是为什么用sort排序不行,而用qsort好使呢?想不同啊~~~//一开始我的输出听复杂的,后来看了他们(就是代码中的),感觉比我的好,就用了//感觉这里没啥好解释的,一看就能看明白,所以这次没加注释了!

#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;

int testcase;
struct Problem{
 char teamName[15];
 int p[7],total_time,sum,g_m;

}problem[20];

int cmp(const void *_a, const void *_b)
{
 struct Problem *a, *b;

 a = (struct Problem *)_a;
 b = (struct Problem *)_b;

 if (a->sum != b->sum)
  return b->sum - a->sum;
 if (b->total_time != a->total_time)
  return a->total_time - b->total_time;
 if (b->g_m != a->g_m)
  return a->g_m - b->g_m;
 return strcmp(a->teamName, b->teamName);
}
void solve()
{
 int i,j;
 for(i = 0;i < testcase;i++)
 {
  int count = 0;
  int total = 0;
  double gm = 1;
  for(j = 0;j < 7;j++)
  {
   if(problem[i].p[j] != 0)
   {
    count++;
    total += problem[i].p[j];
    gm *= problem[i].p[j];
   }
  }
  problem[i].sum = count;
  problem[i].total_time = total;
  if(count)
      problem[i].g_m = (int)(pow(gm,1.0/count) + 0.5);
  else
   problem[i].g_m = 0;

 }
 qsort(problem, testcase, sizeof(problem[0]), cmp);

}
void output()
{
 int i,j,r;
 for(i = 0,r = 0;i < testcase;i++)
 {
  if(i && (problem[i].sum != problem[i-1].sum) || (problem[i].total_time != problem[i-1].total_time) || (problem[i].g_m != problem[i-1].g_m))
   r = i;
  printf("%.2d %-10s%2d%5d%4d",r+1,problem[i].teamName,problem[i].sum,problem[i].total_time,problem[i].g_m);
  for(j = 0;j < 7;j ++)
   printf("%4d",problem[i].p[j]);
  printf("\n");
 }
}
int main()
{
 int i,j;
 int account = 0;
 while(cin>>testcase && testcase)
 {
  for(i = 0;i < testcase;i++)
  {
   cin>>problem[i].teamName;
   for(j = 0;j < 7;j++)
   {
    cin>>problem[i].p[j];
   }
  }
  solve();
  printf("CONTEST %d\n", ++account);
  output();
 }
 return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值