POJ 3778 An Odd Award Rule简单暴力

原题:http://poj.org/problem?id=3778

An Odd Award Rule
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 585 Accepted: 213

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


重点在这句anyone whose score equals to the sum of the scores of OTHER 3 or 2 students,也就是说找出成绩是另外2个或3个同学成绩之和的同学

先输出有几个这样的同学,再按照字典排序枚举这些同学(Then print the names of those who win the awards in alphabetic order)。

这道题用暴力的方法更简单。

AC代码如下:


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;
/*
author:YangSir
time:2014/5/2
*/

struct node
{
	string a;//这样写简单点
	int b;
}p[100];

string s[100];

int main()
{
	int n,i,j,t,flag,y,k,r;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		for(i=0;i<n;i++)
		{
			cin>>p[i].a>>p[i].b;
		}
		r=0;
		for(i=0;i<n;i++)
		{
			flag=0;
			for(j=0;j<n;j++)
			{
				if(i==j)
					continue;
				for(k=0;k<n;k++)
				{
					if(i==k||j==k)
						continue;
					if(p[i].b==p[j].b+p[k].b)
					{
						s[r++]=p[i].a;
						flag=1;
						break;
					}
					for(y=0;y<n;y++)
					{
						if(i==y||j==y||k==y)
							continue;
						if(p[i].b==p[j].b+p[k].b+p[y].b)
						{
							s[r++]=p[i].a;
							flag=1;
							break;
						}
					}
					if(flag)
						break;
				}
				if(flag)
					break;
			}
		}
		sort(s,s+r);//按照字典方式排序
		printf("%d\n",r);
		for(i=0;i<r;i++)
		{
			cout<<s[i]<<endl;
		}
	}
	return 0;
}




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值