HDU 3412 杭州省赛 An Odd Award Rule

An Odd Award Rule

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 96    Accepted Submission(s): 44

Problem 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
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.
 

 

Output
For each test case, print one line containing an integer which equals to the formula’s value mod P.
 

 

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

 

Sample Output
  
  
2 SIKE WORRY
 

 

Source
 

 

Recommend
wxl

 

 

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct T
{
    string name;
    int s;
}t[200];
string stu[200];
bool flag;
int n;
bool cmp(T a,T b)
{
    return a.s>b.s;
}
bool cmp2(string a,string b)
{
    return a<b;
}
void dfs(int x,int sum,int step)
{
    if(sum==0)
    {
        if(step==2||step==3)  flag=true;
        return;
    }
    if(step==3&&sum!=0)   return;
    if(sum<t[n-1].s)  return;
    if(x+1>=n)   return;
    for(int i=x+1;i<n;i++)
    {
        if(flag)   return;
        if(sum-t[i].s>=0&&step+1<=3)   dfs(i,sum-t[i].s,step+1);
    }
    return;
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        for(int i=0;i<n;i++)   cin>>t[i].name>>t[i].s;
        sort(t,t+n,cmp);
        int k=0;
        for(int i=n-3;i>=0;i--)
        {
            flag=false;
            dfs(i,t[i].s,0);
            if(flag)  stu[k]=t[i].name,k++;
        }
        sort(stu,stu+k,cmp2);
        cout<<k<<endl;
        for(int i=0;i<k;i++)
        cout<<stu[i]<<endl;
    }
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值