poj-1295--- I hate SPAM, but some people love it (模拟)

来源:互联网 发布:厦门大学网络教学平台 编辑:程序博客网 时间:2024/06/16 11:38
I hate SPAM, but some people love it
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 328 Accepted: 147

Description

Nowadays, unfortunately, SPAM messages are becoming more and more common. Some of them may have a multiplicative effect since they ask you to forward them to all your friends. Some SPAM messages wish good luck, others promise you will become rich, and others just remind you how important it is to tell your friends that you care for their friendship. Here is an example of a SPAM:
From: AliceTo: Bob, Mary, Julia, PaulHi, this is a good luck email. I wish you become a millionaire, butthat is up to you. If you* send this email to 10 or more people you will be a millionaire* send this email to 5 or more people you will be rich* send this email to less than 5 people you will be poorAs I said, it is up to you. Write your email and be rich! :-)Alice

People usually react in two different ways when they receive a SPAM:
1.They discard the message immediately without even reading it (they hate SPAM);
2.They forward the message to everyone they know (they love SPAM).
For this problem, we will assume everyone loves SPAM, but one never forwards the same message twice. Each SPAM message has a different effect based on the number of friends you forward the message to. For example: a SPAM message could tell that you will be poor if you send the message to 5 friends, but you will be the rich if you send to 10, and you will be the richest man in the world if you send it to 20 friends, and so on.
We will consider only SPAM messages similar to the example above. More specifically, a SPAM message will define two threshold values T1 and T2 and three attributes A1, A2 and A3. A person acquires one of the three attributes depending on the number of messages forwarded for that specific SPAM. If a person forwards T messages and T < T1 then her/his attribute is A1, if T1 <= T < T2 then her/his attribute is A2, otherwise her/his attribute is A3.
You will be given the names of a group of people, and for each person in the group, the set of friends she/he knows the email address. You will also be given a set of distinct SPAM messages, and for each SPAM message its threshold values and attributes, and the information about which person started it.
You have to write a program that determines, for each person in the given group, which attributes she/he acquired, based on all the SPAM they forward.

You may assume that the SPAM originator will have at least one friend (in other words, she/he will send at least one message), and a person will not send messages to herself.

Input

Your program should process several test cases. The first line of a test case contains an integer N indicating the number of persons in the group (2 <= N <= 20). In the input, a person is identified by an integer from 1 to N. The following N lines contain each a list of friends of each person (the i-th line contains the list of friends of person number i). The list of friends of person i describes the friends person i knows the email address, and consists of a list of integers Fi (1 <= Fi <= N, Fi != i) terminated by the value 0 (zero). Following the list of friends comes the description of the SPAM messages (there will be at most 100 messages). Each description appears in a different line. The description consists of an integer P identifying the person who is the SPAM originator (2 <= P <= N); two integers T1 and T2 representing the threshold values; and the three attributes A1, A2 and A3 (each attribute is a word of no more than 20 letters). The SPAM list ends with a line containing only the value 0 (zero). The following N lines contain each a name, which is single word with no more than 20 letters. The name in the ith line is the name of person number i. The end of input is indicated by N = 0.

Output

For each test case your program should output a list of names followed by the attributes they acquired.Your program should write the persons names in the order they appear in the input, followed by ':' and by a space, followed by their attributes according to the SPAM they sent. Attributes should be written in the order they appear in the input; each attribute should be followed by a space.

Sample Input

52 3 01 3 5 4 05 004 1 01 2 4 poor rich millionaire5 3 10 sad normal happy0BobPaulMaryAliceJulia62 01 3 01 2 4 01 2 3 5 01 2 3 4 01 3 4 01 2 4 red green blue1 2 4 dumb normal smart6 3 5 ugly bad good0PeterPaulVictoriaJohnJuliaAnne0 0

Sample Output

Bob: rich sadPaul: millionaire normalMary: poor sadAlice: poor sadJulia: rich sadPeter: red dumb uglyPaul: green normal uglyVictoria: green normal badJohn: blue smart badJulia: blue smart badAnne: red dumb bad

Source

South America 2002


这题就是题目太长太长,像英语阅读理解额。。。但是是个很简单的题
大致说一下题意:给出n个人,然后下面n行输入每个人的朋友,0表示结束;然后输入广告,每个广告前三个数a,b,c分别表示 a:第一个发出该广告的人,b,c表示每个人发出的短信数量num<b,num>=b&&num<c,num<=c分别对应广告后面的三个字符串,我在代码中用level表示,最后输入每个人的名字。每个人收到短信后都会把短信发送给他所有的朋友,但是同一个人不会发送同一封信息。最后输出每个人每种广告对应的状态吧(就是对印的字符串)
思路:这题就是按照题意来,由于变量会很多,建议用结构体保存,细心一点然后搞搞就出来了。(开始数组开小了re了,然后就在数组里面都加了一个0.。。。)
ac代码:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include<queue>using namespace std;struct node{    char name[2000];//名字    int peng[1000];//朋友    char level[1000][200];//level[i][j]:第i个广告为第j种状态    int num;//朋友的数量};node p[250];//人struct enen{    int s;//广告的第一个发送人    int xx;    int dd;    char level[5][200];};enen adv[2500];//广告int n;queue<int> que;int main(){    int flag=0,kk;    while(~scanf("%d",&n))    {        if(n==0)flag=1;        if(flag){scanf("%d",&kk);}        if(n==0&&kk==0)break;        int cnt;        for(int i=1;i<=n;i++)        {            cnt=1;            while(1)            {                int x;                scanf("%d",&x);                if(x==0)                    break;                p[i].peng[cnt++]=x;            }            p[i].num=cnt-1;        }        cnt=1;        while(1)        {            int x;            scanf("%d",&x);            if(x==0)break;            adv[cnt].s=x;            scanf("%d%d%s%s%s",&adv[cnt].xx,&adv[cnt].dd,adv[cnt].level[1],adv[cnt].level[2],adv[cnt].level[3]);            cnt++;        }        for(int i=1;i<=n;i++)            scanf("%s",p[i].name);        int book[100];        for(int i=1;i<cnt;i++)//循环每个短信        {            memset(book,0,sizeof(book));//标记数组            que.push(adv[i].s);//将起始人入队            while(que.size())            {                int q=que.front();                if(book[q]==0)//该人没有发过当前短信                {                    for(int j=1;j<=p[q].num;j++)                        que.push(p[q].peng[j]);//将他的朋友入队                    if(p[q].num<adv[i].xx)strcpy(p[q].level[i],adv[i].level[1]);                    else if(p[q].num>=adv[i].xx&&p[q].num<adv[i].dd)strcpy(p[q].level[i],adv[i].level[2]);                    else strcpy(p[q].level[i],adv[i].level[3]);                    book[q]=1;//标记                }                que.pop();            }            for(int j=1;j<=n;j++)//如果当前广告有人没接收到过                if(book[j]==0)                    strcpy(p[j].level[i],adv[i].level[1]);        }        for(int i=1;i<=n;i++)        {            printf("%s:",p[i].name);            for(int j=1;j<cnt;j++)                printf(" %s",p[i].level[j]);            printf("\n");        }    }    return 0;}


原创粉丝点击