http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5503
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 N teams which participate in the competition. In the beginning, each team has S 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:
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!
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first line contains four integers N (2 <= N <= 100) - the number of teams, Q - the number of services (1 <= Q <= 10), S - the initial points (0 <= S <= 100000) and C - the number of checkpoints (1 <= C <= 100).
For each checkpoint, there are several parts:
[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.
For each query L, output the score and the ranking of the Lth 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.
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
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
For C++ users, kindly use scanf to avoid TLE for huge inputs.
分析:
先输入4个数,n,q,p,c
代表有n个队伍,q个服务器,每支队伍的初始分数p,还有c次操作
对于每次操作,首先输入一个k,代表k次攻击
每次攻击有三个数,a,b,c,代表a通过c服务器成功的攻击了b
对于每次成功的攻击,b会失去n-1分,这n-1分会平分给通过同一服务器攻击b的几支队伍
然后是q行,每行n个数,分别代表1~n是否成功维护了,1为成功,0为不成功
不成功的队伍会失去n-1分,这失去的分会平分给成功维护的那些队伍
然后输入k个数,询问这k支队伍的分数
AC代码:
1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #include <stack> 5 #include <queue> 6 #include <map> 7 #include <set> 8 #include <vector> 9 #include <math.h> 10 #include <algorithm> 11 using namespace std; 12 #define ls 2*i 13 #define rs 2*i+1 14 #define up(i,x,y) for(i=x;i<=y;i++) 15 #define down(i,x,y) for(i=x;i>=y;i--) 16 #define mem(a,x) memset(a,x,sizeof(a)) 17 #define w(a) while(a) 18 #define LL long long 19 const double pi = acos(-1.0); 20 #define Len 20005 21 #define mod 19999997 22 #define exp 1e-5 23 const int INF = 0x3f3f3f3f; 24 25 struct node 26 { 27 int id,rank; 28 double score; 29 } a[105]; 30 31 int n,q,c,t; 32 double p; 33 bool vis[105][105][15],hsh[105]; 34 35 int cmp1(node a,node b) 36 { 37 return a.score>b.score; 38 } 39 40 int cmp2(node a,node b) 41 { 42 return a.id<b.id; 43 } 44 45 int main() 46 { 47 int i,j,k; 48 scanf("%d",&t); 49 w(t--) 50 { 51 scanf("%d%d%lf%d",&n,&q,&p,&c); 52 up(i,0,n) 53 { 54 a[i].id = i; 55 a[i].rank = 1; 56 a[i].score = p; 57 } 58 w(c--) 59 { 60 scanf("%d",&k); 61 mem(vis,false); 62 w(k--) 63 { 64 int atk,def,sev; 65 scanf("%d%d%d",&atk,&def,&sev); 66 if(vis[atk][def][sev]) continue; 67 vis[atk][def][sev] = true; 68 } 69 up(i,1,q)//服务器 70 { 71 up(j,1,n)//防守方 72 { 73 int cnt = 0; 74 up(k,1,n)//攻击方 75 { 76 if(vis[k][j][i])//统计攻击j的队伍有几支 77 cnt++; 78 } 79 if(!cnt) 80 continue; 81 double ss = 1.0*(n-1)/cnt;//平分 82 a[j].score-=(n-1);//防守方失去n-1 83 up(k,1,n) 84 { 85 if(vis[k][j][i])//攻击方得到分数 86 a[k].score+=ss; 87 } 88 } 89 } 90 91 up(i,1,q)//服务器 92 { 93 mem(hsh,false); 94 int cnt = 0; 95 up(j,1,n) 96 { 97 int x; 98 scanf("%d",&x); 99 if(x)//成功维护的队伍数 100 { 101 hsh[j] = true; 102 cnt++; 103 } 104 else 105 { 106 hsh[j] = false; 107 a[j].score-=(n-1); 108 } 109 } 110 if(cnt == n) continue; 111 double ss = 1.0*(n-1)/cnt; 112 ss = ss*(n-cnt); 113 up(j,1,n) 114 { 115 if(hsh[j]) 116 a[j].score+=ss; 117 } 118 } 119 120 sort(a+1,a+n+1,cmp1); 121 up(i,1,n)//更新排名 122 { 123 if(i!=1) 124 { 125 if(fabs(a[i].score-a[i-1].score)<exp) 126 a[i].rank = a[i-1].rank; 127 else 128 a[i].rank = i; 129 } 130 else 131 a[i].rank = i; 132 } 133 sort(a+1,a+n+1,cmp2); 134 scanf("%d",&k); 135 w(k--) 136 { 137 int x; 138 scanf("%d",&x); 139 printf("%f %d\n",a[x].score,a[x].rank); 140 } 141 } 142 } 143 144 return 0; 145 }
最后附一张 board :
http://paste.ubuntu.com.cn/i2563575
浙大霸气!!!杭电威武!!!
任性啊,,,