注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

东月之神

在单纯的观念里面,生命就容易变得比较深刻!

 
 
 

日志

 
 
关于我

别驻足,梦想要不停追逐,别认输,熬过黑暗才有日出,要记住,成功就在下一步,路很苦,汗水是最美的书!

网易考拉推荐

zstu An Odd Award Rule  

2010-05-14 10:30:06|  分类: ACM |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

Description

The education of primary school in China is a big problem now. A teacher must be very careful not only when he/she is criticizing the students, but also when he/she is giving awards to good students. Teacher Liu always gave the top ten students on his examination some little awards before, but some parents are a little bit angry about this now. They say that their little kids may get hurt because they will never get the awards. Teacher Liu has to change his award rule. He wants all students have a chance to win the awards, no matter their scores are good or poor. But he still wants good students to get more chance. So the new rule seems a little bit odd: anyone whose score equals to the sum of the scores of OTHER 3 or 2 students, will win the award. Now figuring out who is qualified for the awards seems a little bit hard for Teacher Liu. As the monitor of his class and a little programmer, you should help him to do this.

Input

The first line is an integer T indicating the number of test cases.
For each test case, the first line is an integer N meaning the number of students. (0 < N < = 20 ) Then N lines follows, and each line contains a student’s name and score.
A student’s name is a string made up of uppercase letters(no more than 20 letters). A student’s score is an integer between 0 and 100 (could be 0 or 100).
Every student’s name is unique and every name just appears once.

Output

For each test case, first print an integer in a line, indicating how many students win the awards. Then print the names of those who win the awards in alphabetic order, each name in a line.

Sample Input

1
5
SIKE 12
WORRY 20
LUCENT 8
KILI 3
TOM 1

Sample Output

2
SIKE
WORRY
题目意思很好理解,就是输出与其他 任意两个或者三个同学的分数相同的人。我的方法有点类似hash。

#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstring>
using namespace std;

struct STU
{
 string name;
 int score, num;
}s[500];

int hash[301], hash1[500][301];
int main()
{
 int t, i, n, k, j;
 while(scanf("%d", &t) != EOF)
 {
  while(t--)
  {
   memset(hash, 0, sizeof(hash));
   memset(hash1, 0, sizeof(hash1));
   scanf("%d", &n);
   for(i = 0; i < n; i++)
    cin >> s[i].name >> s[i].score;
   for(i = 0; i < n; i++)
   {
    for(j = 0; j < n; j++)
    {
     if(i != j)
      hash1[i][s[i].score+s[j].score]++;
     for(k = 0; k < n; k++)
     {
      if(i != j && i != k && j != k)
       hash1[i][s[i].score+s[j].score+s[k].score]++;
     }
    } 
   }
   for(i = 0; i < n - 1; i++)
   {
    for(j = i + 1; j < n; j++)
    {
     int ans = s[i].score + s[j].score;
     hash[ans]++;
     for(k = j + 1; k < n; k++)
     {
      int ans1 = s[i].score + s[j].score + s[k].score;
      hash[ans1]++;
     }
    }
   }
   string a[500];
   for(i = 0, j = 0; i < n; i++)
   {
    if(hash[s[i].score] && hash[s[i].score] > hash1[i][s[i].score])
    {
     a[j] = s[i].name;
     ++j;
    }
   }
   int m = j;
   sort(a, a + m);
   printf("%d\n", m); 
   for(i = 0; i < m; i++)
    cout << a[i] << endl;
  }
 }
return 0;
}

 

  评论这张
 
阅读(199)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017