In computer security, Capture the Flag (CTF) is a computer security competition. CTF contests are usually designed to serve as an educational exercise to give participants experience in securing a machine, as well as conducting and reacting to the sort of attacks found in the real world. Reverse-engineering, network sniffing, protocol analysis, system administration, programming, and cryptanalysis are all skills which have been required by prior CTF contests at DEF CON. There are two main styles of capture the flag competitions: attack/defense and jeopardy.

In an attack/defense style competition, each team is given a machine (or a small network) to defend on an isolated network. Teams are scored on both their success in defending their assigned machine and on their success in attacking other team's machines. Depending on the nature of the particular CTF game, teams may either be attempting to take an opponent's flag from their machine or teams may be attempting to plant their own flag on their opponent's machine.

Recently, an attack/defense style competition called MCTF held by Marjar University is coming, and there are <var>N</var> teams which participate in the competition. In the beginning, each team has <var>S</var> points as initial score; during the competition, there are some checkpoints which will renew scores for all teams. The rules of the competition are as follows:

  • If a team has been attacked for a service <var>P</var>, they will lose <var>N - 1</var> points. The lost points will be split equally and be added to the team(s) which attacks successfully. For example, there are 4 teams and Team A has been attacked by Team B and Team C, so Team A will lose 3 points, while Team B and Team C each will get 1.5 points.
  • If a team cannot maintain their service well, they will lose <var>N - 1</var> points, which will be split equally too and be added to the team(s) which maintains the service well.

The score will be calculated at the checkpoints and then all attacks will be re-calculated. Edward is the organizer of the competition and he needs to write a program to display the scoreboard so the teams can see their scores instantly. But he doesn't know how to write. Please help him!

Input

There are multiple test cases. The first line of input contains an integer <var>T</var>indicating the number of test cases. For each test case:

The first line contains four integers <var>N</var> (2 <= <var>N</var> <= 100) - the number of teams, <var>Q</var> - the number of services (1 <= <var>Q</var> <= 10), <var>S</var> - the initial points (0 <= <var>S</var> <= 100000) and <var>C</var> - the number of checkpoints (1 <= <var>C</var> <= 100).

For each checkpoint, there are several parts:

  • The first line contains an integer <var>A</var> - the number of the successful attacks. Then <var>A</var> lines follow and each line contains a message:
    [The No. of the attacker] [The No. of the defender] [The No. of the service]
    For example, "1 2 3" means the 1st team attacks the 2nd team in service 3 successfully. The No. of teams and services are indexed from 1. You should notice that duplicate messages are invalid because of the rules. Just ignore them.
  • Then there are <var>Q</var> lines and each line contains <var>N</var> integers. The <var>jth</var> number of the <var>ith</var> line indicating the <var>jth</var> team's maintaining status of the <var>ith</var> service, where 1 means well and 0 means not well.
  • Finally there is an integer <var>U</var> (0 <= <var>U</var> <= 100), which describing the number of the queries. The following line contains <var>U</var> integers, which means Edward wants to know the score and the ranking of these teams.

 

Output

For each query <var>L</var>, output the score and the ranking of the <var>Lth</var> team. The relative error or absolute error of the score should be less than 10-5. The team with higher score gets higher rank; the teams with the same scores should have the same rank. It is guaranteed that the scores of any two teams are either the same or with a difference greater than 10-5.

Sample Input

1
4 2 2500 5
0
1 1 1 1
1 1 1 1
4
1 2 3 4
2
1 2 1
3 2 1
1 1 1 1
1 1 1 1
4
1 2 3 4
1
1 2 2
1 1 1 1
1 1 1 0
4
1 2 3 4
0
0 0 0 0
0 0 0 0
4
1 2 3 4
0
1 1 1 1
1 1 1 1
2
1 4

Sample Output

2500.00000000 1
2500.00000000 1
2500.00000000 1
2500.00000000 1
2501.50000000 1
2497.00000000 4
2501.50000000 1
2500.00000000 3
2505.50000000 1
2495.00000000 4
2502.50000000 2
2497.00000000 3
2499.50000000 1
2489.00000000 4
2496.50000000 2
2491.00000000 3
2499.50000000 1
2491.00000000 3

题意:首先给你四个数,n,q,s,c,代表着队伍的个数,服务器的个数,最初的分数,以及检查点的个数;

然后以下c行:

对于每一个检查点c:

1、首先有一个A,代表有A次攻击,对于每次攻击,有三个数a,b,c,a攻击了c服务器上的b;

对于每个服务器上的队伍,受攻击的会减少(n-1)分,并且会平均分配给攻击这个队伍的那些队伍;

还有一点就是重复的消息无效。(这点很坑)。

2、然后有q行01串,一行n位,代表每个服务器上的每个队伍的状态,如果为0,就代表处于失分状态,就会失去(n-1)分,然后平均分配给这一行上状态是1的那些队伍

3、最后有k个数字,为询问的队伍的个数,然后k个数字,代表要你输出这k个人的分数以及排名,分数相同的排名也一样。

 

总之题目比较长比较丑,不过理解了之后,还是一个比较水的模拟题;

 

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cmath>
 6 using namespace std;
 7 const double eps=1e-5;
 8 int t,n,q,c,u;
 9 double s;
10 bool vis[105][105][15];
11 int a,x,y,z,ser[105][15],book[105],cnt,p[105];
12 struct team{
13     int i;
14     double s;
15 }te[105];
16 
17 inline bool cmp1(team a,team b){
18     return a.s>b.s;
19 }
20 
21 inline bool cmp2(team a,team b){
22     return a.i<b.i;
23 }
24 
25 
26 int main(){
27     scanf("%d",&t);
28     while(t--){
29         scanf("%d%d%lf%d",&n,&q,&s,&c);
30         for(int i=1;i<=n;i++) te[i].s=s,te[i].i=i;
31         while(c--){
32             scanf("%d",&a);
33             for(int i=1;i<=n;++i){
34                 for(int j=1;j<=n;++j){
35                     for(int k=1;k<=q;++k) 
36                     {
37                         vis[i][j][k]=0;
38                         ser[j][k]=0;
39                     }
40                 }
41             }
42             for(int i=1;i<=a;++i){
43                 scanf("%d%d%d",&x,&y,&z);
44                 if(!vis[x][y][z])
45                 {
46                     vis[x][y][z]=1;
47                     ser[y][z]++;
48                 }
49                  
50             }
51             for(int j=1;j<=n;++j)
52                 for(int k=1;k<=q;++k)
53                     if(ser[j][k])
54                     {
55                         te[j].s-=(n-1);
56                         for(int i=1;i<=n;++i)
57                             if(vis[i][j][k])
58                                 te[i].s+=(n-1)/(double)ser[j][k];
59                     }
60             for(int j=1;j<=q;++j)
61             {
62                 cnt=0;
63                 for(int i=1;i<=n;++i)
64                 {
65                     scanf("%d",&book[i]);
66                     if(!book[i]){
67                         cnt++;
68                         te[i].s-=(n-1);
69                     }
70                 }
71                 for(int i=1;i<=n;++i)
72                     if(book[i]) te[i].s+=(double)(n-1)*cnt/(n-cnt);
73             }
74             sort(te+1,te+n+1,cmp1);
75             for(int i=1;i<=n;++i)
76             {
77                 if(i==1||fabs(te[i].s-te[i-1].s)>eps)
78                     p[te[i].i]=i;
79                 else
80                     p[te[i].i]=p[te[i-1].i];
81             }
82             sort(te+1,te+n+1,cmp2);
83             scanf("%d",&u);
84             while(u--){
85                 int temp;
86                 scanf("%d",&temp);
87                 printf("%.8f %d\n",te[temp].s,p[temp]);
88             }
89         }
90     }
91     return 0;
92 }