HDU - 3040 - Happy Girls

先上题目:

Happy Girls

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1356    Accepted Submission(s): 233


Problem Description
These days, Hunan TV host the big concert – Happy Girls.
Long1 and xinxin like it very much, they even use their cellphones to suppose the girl who they like most. This way is easy if you have enough money then you can make a contribution toward your lover.
But sometimes, it also causes the problem of injustice. Those who has a lot of money can support their lover in every second. So now, we make a rule to restrict them – every tel-number can just support once in one minute (i.e two messages should have difference bigger or equal 60s). 
As an exerllent programer, your mission is to count every Happy girl’s result.

 

 

Input
There are many cases. 
For every case: 

The first line gives N, represents there are N happy gilrs numbered form 1 to N(N<=10) 
Then many lines follows(no more than 50000), each line gives the time one sent his/her message, the cellphone number and the number he/she support. They are sepatated by space.
The last line an message “#end”.
 

 

Output
In every case, you print “The result is : ”, then N line follows.
Each line begin with the Happy girls’ number, then a colon, then a bunch of “*” follows, the number of the “*” are Happy girls’ votes.
 

 

Sample Input
4
0:12:25 13854241556 1
0:15:52 15825422365 2
0:15:56 15825422365 3
0:18:55 13625415457 2
11:12:2 13954215455 4
5:41:55 13625415457 2
#end
 

 

Sample Output
The result is :
01 : *
02 : ***
03 :
04 : *
 
  题意:给出一系列手机号码,其发送信息的时间以及投票的对象,求最终每个被投票对象的得票数。这里有一个要求,就是对于同一个人的信息需要判断是不是在60秒以内连续发的,如果是,那当前这一次投票不计。这里可能有一点歧义,①60秒以内连续发多条短信,那是只以第一条短信为60秒的开始计时点还是每收到一条短信,都会以新的一条短信为计时的开始点。不过这里两种情况都会AC。
  做法就是先对每一个手机用户的投票情况进行排序,然后统计一遍就可以了。值得注意的是对于同一个用户连续两条短信的间距只要大于等于60秒就可以了。
  还有就是,这一题用C++交可能会WA,用G++交的话才会AC。
 
上代码:
 
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 #define MAX 50004
 6 #define LL long long
 7 using namespace std;
 8 
 9 typedef struct{
10     LL ti;
11     LL num;
12     int p;
13 }vote;
14 
15 vote v[MAX];
16 int tot;
17 int girl[11];
18 
19 typedef struct{
20     LL la;
21     LL num;
22 }user;
23 
24 user u[MAX];
25 int o;
26 
27 void check(int t){
28     if(u[o].num==v[t].num){
29         if(u[o].la>=0 && v[t].ti-u[o].la<60){
30                 u[o].la=v[t].ti;
31                 return;
32         }
33     }else{
34        o++;
35        u[o].num=v[t].num;
36     }
37     u[o].la=v[t].ti;
38     girl[v[t].p]++;
39 }
40 
41 bool cmp(vote x,vote y){
42     if(x.num<y.num) return 1;
43     else if(x.num==y.num && x.ti<y.ti) return 1;
44     return 0;
45 }
46 
47 
48 
49 int main()
50 {
51     int t,k,t_[3];
52     char a[50];
53     //freopen("data.txt","r",stdin);
54     while(scanf("%d",&t)!=EOF){
55         getchar();
56         tot=0;
57         memset(girl,0,sizeof(girl));
58         memset(u,-1,sizeof(u));
59         o=0;
60         while(scanf("%s",a),a[0]!='#'){
61             sscanf(a,"%d:%d:%d",&t_[0],&t_[1],&t_[2]);
62             k=0;
63             for(int i=0;i<3;i++){
64                 k=k*60+t_[i];
65             }
66             v[tot].ti=k;
67             scanf("%I64d",&v[tot].num);
68             scanf("%d",&v[tot].p);
69             tot++;
70         }
71         sort(v,v+tot,cmp);
72         for(int i=0;i<tot;i++){
73             check(i);
74         }
75         printf("The result is :\n");
76         for(int i=1;i<=t;i++){
77             printf("%02d : ",i);
78             for(int j=0;j<girl[i];j++) putchar('*');
79             printf("\n");
80         }
81     }
82     return 0;
83 }
3040

 

posted @ 2014-02-22 20:08  海拉鲁的林克  阅读(419)  评论(0编辑  收藏  举报