HDU 6002 Game Leader 【贪心】


传送门:HDU 6002


Game Leader
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)


Problem Description
Recently Tom is playing an interesting game. The game contains a social network, so players can make friends with each other. The friend relation is symmetric, which means if A is a friend of B, B is also a friend of A.
Players’ ratings are distinct from each other, which means there are no two players sharing a same rating. Each player owns a ranklist containing all his friends’ rating (including himself) and there is one leader who has the highest rating in each player’s ranklist.
Tom has N friends. During the communications with these friends, he knows some pairs of friends are also friends. But he doesn’t know all the such pairs. In other words, some friends maybe are friends but Tom doesn’t know it.
One day, Tom noticed that the system started showing the number of leaders for every friend.
E.g. the system may says Peter is leader on 3 players’ ranklist.
Now Tom can see the number of leaders for every friend. He would like to know the least number of strangers’ ranklist leader are his friends.

Input
The first line of the input gives the number of test cases, T. T test cases follow. Each test case starts with a line consists of 3 integers, N, M and R representing the number of people on Tom’s ranklist(including Tom), the number of friendships Tom knows and the rank of Tom in his ranklist(1-indexed). The next line consists of N integers, the ith integer Ci represents the number of leaders for the friend on rank i. The following M lines each consists of 2 integers Xi , Yi , means that the friend on rank Xi is a friend of friend on rank Yi.

Output
For each test case, output one line containing “Case #x: y”, where x is the test case number (starting from 1) and y is the least number of ranklists that not owned by Tom’s friend but the leader is Tom’s friend.
limits
·1≤T≤100.
∙1≤N,M≤105.
∙1≤Xi≤N.
∙1≤Yi≤N.
∙1≤R≤N.
∙R≠Xi.
∙R≠Yi.
∙Xi≠Yi.
∙0≤Ci≤109.
∙ It’s guaranteed that the data is valid.

Sample Input
2
4 0 3
1 0 0 2
4 1 4
1 0 2 0
1 3

Sample Output
Case #1: 2
Case #2: 2



这题别的先不说,光是题目的意思我就看了一个多小时才看邱明白= _ = 。换了几个翻译软件,翻译都没看明白,有些时候这些翻译软件翻译的是真的水 ,最后自己翻译了一边,加上翻译软件的翻译一起看,才把样例看明白 ,= _ =|| 。理解是硬伤啊


题意:
每个人有一个排行榜,目前已知tom的排行榜,以及一部分的朋友关系,以及每个人在排行榜中排第一的次数。问tom的朋友最少在多少个陌生人的榜单中排第一。


题解
每个朋友在游戏榜单中为第一名的个数已经告诉你了,这个时候我们考虑到,为第一名的总数是一定的,而当第一名的总数中分为两个部分,一部分是在和Tom也是朋友的榜单中是第一名,另外一部分是和Tom是陌生人,在Tom的陌生人的榜单中是第一名。我们要使在和Tom是陌生人的榜单中为第一名的人数最少,就是要另一部分的人数多。

那么结果就是:每个朋友当第一的总次数 - 最多在朋友列表里当第一的次数 = 最少在陌生人列表里当第一的次数,然后累加求和就可以了,如果结果小于0,则取0(long long型)。

我们用一个数组leader,leader[i]=x表示编号为i的朋友他的列表第一至少应该是编号为x的人,leader[i]我们优先取Tom的朋友。第一次和Tom比较,谁小选谁。第二次输入朋友关系时,两者比较,选小的(即在Tom的榜单中排名高的)。
num[i]表示i最多在朋友列表里当第一的次数



AC代码:

 #include<iostream>
 #include<cstring>
 #include<algorithm>
 #include<cstdio>
 #include<vector>
 #include<cmath>
 #define ll long long
 #define inf 0x3f3f3f3f
 using namespace std;
 const int N=110000;
 int t,n,m,r;
 ll c[N];
 bool vis[N];
 int leader[N];
 int num[N];
 int main()
 {
   int x,y;
   int ca=0;
   scanf("%d",&t);
   while(t--)
   {
     ll ans=0;
     memset(leader,0,sizeof(leader));
     memset(num,0,sizeof(num));
     scanf("%d%d%d",&n,&m,&r);
     for(int i=1;i<=n;i++)
     {
       scanf("%lld",&c[i]);
       leader[i]=min(i,r);
     }
     leader[r]=1;//Tom的榜单第一名至少是1
     for(int i=0;i<m;i++)
     {
       scanf("%d%d",&x,&y);
       leader[x]=min(leader[x],y);
       leader[y]=min(leader[y],x);
     }
     /*for(int i=1;i<=n;i++) printf("%d\n",leader[i]);
     printf("\n");*/
     for(int i=1;i<=n;i++) num[leader[i]]++;
     /*for(int i=1;i<=n;i++) printf("%d\n",num[i]);*/
     for(int i=1;i<=n;i++)
     {
       ans+=max(c[i]-num[i],0LL);//0LL 表示long long型的0
     }
     printf("Case #%d: %lld\n",++ca,ans);
   }
   return 0;
 }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值