Title Link: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5527
Surface:
Capture the Flag Time limit: 2 Seconds Memory Limit: 65536 KB Special Judge
in computer security, Capture the Flag ( CTF) is a computer security competition. CTF contests is usually designed to serve as an educational exercise to give participants experience in securing a Machin E, 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 is all SK Ills which has been required by prior CTF contests at DEF CON. There is both main styles of capture the flag competitions:attack/defense and jeopardy.
in an attack/defense style competition, Each team was given a machine (or a small network) to defend on an isolated network. Teams is 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 being attempting to take an opponent's flag from their m Achine or teams is attempting to plant their own flag on their opponent ' s machine.
recently, an attack/defense style Competition called MCTF held by Marjar University are 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 is some checkpoints which would renew scores for all teams. The rules of the competition are as follows:
- If A team have been attacked for a service P , they would lose N-1 points. The lost points would be split equally and being added to the team (s) which attacks successfully. For example, there is 4 teams and team A have been attacked by team B and Team C, so team A would lose 3 points, while team B and Team C each would get 1.5 points.
- If A team cannot maintain their service well, they'll lose N-1 points, which'll be split EQ Ually too and is added to the team (s) which maintains the service well.
The score is calculated at the checkpoints and then all attacks would 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 what to write. Please help him!
Input
There is multiple test cases. The first line of input contains an integer indicating the number of the T test cases. For each test case:
The first line contains four integers N (2 <= N <=)-The number of teams,-the number of Q service S (1 <= Q <=), S -the initial points (0 <= S <= 100000) and- C the number of checkpoints (1 <= C <= 100).
For each checkpoint, there is several parts:
Output
For each query L , output the score and the ranking of the Lth team. The relative error or absolute error of the score should is less than 10-5. The team with higher score gets higher rank; The teams with the same scores should has the same rank. It is guaranteed, the scores of any, teams is either the same or with a difference greater than 10-5.
Sample Input
14 2 2500 501 1 1 11 1 1 141 2 3 421 2 13 2 11 1 1 11 1 1 141 2 3 411 2 21 1 1 11 1 1 041 2 3 400 0 0 00 0 0 041 2 3 401 1 1 11 1 1 121 4
Sample Output
2500.00000000 12500.00000000 12500.00000000 12500.00000000 12501.50000000 12497.00000000 42501.50000000 12500.00000000 32505.50000000 12495.00000000 42502.50000000 22497.00000000 32499.50000000 12489.00000000 42496.50000000 22491.00000000 32499.50000000) 12491.00000000 3
Hint
For C + + users, kindly use scanf to avoid TLE for huge inputs.
Solving:
Provincial race, did not see a problem, at that time still feel very pity, but after writing to know that the scene is difficult to write out. It was written for nearly 2 hours and was killed by various small mistakes.
Tell me a few points.
1. When the number of attacks repeats, it only counts 1 times.
2. Do not repeat minus fractions
3. Do not reset every time the checkpoint is a continuation
4. Beware of situations where no one has survived successfully
5. The ranking should be noted, but the accuracy of only 0.00001 is enough
6. Various subscript to pay attention to, was the pit dead ...
Code:
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> #include < Cstring>using namespace Std;struct Team//group {double score; int no;} Store[105];bool attack[11][105][105];//record attack int attacklog[110];//record who attacked successfully bool maintain[11][105];//keep state int rank[105 ];//Rank array bool CMP (Team A,team b) {return a.score>b.score;} int main () {int n,q,s,c,t,a,fm,to,service,cnt,tmp,u;double check;scanf ("%d", &t), while (t--) {scanf ("%d%d%d%d", &N,&Q,&S,&C); Record ordinal for (int i=1;i<=n;i++) {store[i].score=s; Store[i].no=i; } for (int i=1;i<=c;i++) {scanf ("%d", &a); memset (attack,0,sizeof (attack)); for (int j=1;j<=a;j++) {scanf ("%d%d%d", &fm,&to,&service); Avoid duplication of attack[service][to][fm]=1; } for (int j=1;j<=q;j++) {for (int k=1;k<=n;k++) {cnt=0; for (int m=1;m<=n;m++) {if (Attack[j][k][m]) { Attacklog[cnt++]=m; }} if (CNT) {for (int i=1;i<=n;i++) {if (store[i].no==k) {//Do not reduce the number of store[i].score-= (n-1); Break }} double addscore=1.0* (n-1)/cnt;//per person plus split for (int m=0;m<cnt;m + +) {for (int x=1;x<=n;x++) {/ /Attack Success Plus if (store[x].no==attacklog[m]) Store[x].score+=addscore; }}}}} memset (MAIntain,0,sizeof (maintain)); for (int j=1;j<=q;j++) {for (int k=1;k<=n;k++) {scanf ("%d", &tmp ); if (TMP) {maintain[j][k]=1; }}} for (int j=1;j<=q;j++) {cnt=0; for (int k=1;k<=n;k++) {if (maintain[j][k]) cnt++; else {for (int x=1;x<=n;x++) {if (store[x]. No==k) {store[x].score-= (n-1); }}}} if (CNT) {///surviving each plus points Double addscore=1.0* (n-cnt) * (n-1)/cnt; for (int k=1;k<=n;k++) {if (Maintain[j][k]) {for (int x=1;x<=n;x++) {if (store[x].no==k) Store[x].score +=addscore; }}}}} sort (store+1,store+n+1,cmp); scanf ("%d", &u); Ranking processing rank[1]=1; for (int z=2;z<=n;z++) {if ((store[z-1].score-store[z].score) <=0.00001) rank[z]=rank[z-1 ]; else rank[z]=z; } for (int k=1;k<=u;k++) {scanf ("%d", &tmp); for (int x=1;x<=n;x++) {if (store[x].no==tmp) {printf ("%.8lf%d\n", Store[x]. SCORE,RANK[X]); }}}}}return 0;}
Capture the Flag Time limit: 2 Seconds Memory Limit: 65536 KB Special Judge
in computer security, Capture the Flag ( CTF) is a computer security competition. CTF contests is usually designed to serve as an educational exercise to give participants experience in securing a Machin E, 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 is all SK Ills which has been required by prior CTF contests at DEF CON. There is both main styles of capture the flag competitions:attack/defense and jeopardy.
in an attack/defense style competition, Each team was given a machine (or a small network) to defend on an isolated network. Teams is 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 being attempting to take an opponent's flag from their m Achine or teams is attempting to plant their own flag on their opponent ' s machine.
recently, an attack/defense style Competition called MCTF held by Marjar University are 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 is some checkpoints which would renew scores for all teams. The rules of the competition are as follows:
- If A team have been attacked for a service P , they would lose N-1 points. The lost points would be split equally and being added to the team (s) which attacks successfully. For example, there is 4 teams and team A have been attacked by team B and Team C, so team A would lose 3 points, while team B and Team C each would get 1.5 points.
- If A team cannot maintain their service well, they'll lose N-1 points, which'll be split EQ Ually too and is added to the team (s) which maintains the service well.
The score is calculated at the checkpoints and then all attacks would 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 what to write. Please help him!
Input
There is multiple test cases. The first line of input contains an integer indicating the number of the T test cases. For each test case:
The first line contains four integers N (2 <= N <=)-The number of teams,-the number of Q service S (1 <= Q <=), S -the initial points (0 <= S <= 100000) and- C the number of checkpoints (1 <= C <= 100).
For each checkpoint, there is several parts:
Output
For each query L , output the score and the ranking of the Lth team. The relative error or absolute error of the score should is less than 10-5. The team with higher score gets higher rank; The teams with the same scores should has the same rank. It is guaranteed, the scores of any, teams is either the same or with a difference greater than 10-5.
Sample Input
14 2 2500 501 1 1 11 1 1 141 2 3 421 2 13 2 11 1 1 11 1 1 141 2 3 411 2 21 1 1 11 1 1 041 2 3 400 0 0 00 0 0 041 2 3 401 1 1 11 1 1 121 4
Sample Output
2500.00000000 12500.00000000 12500.00000000 12500.00000000 12501.50000000 12497.00000000 42501.50000000 12500.00000000 32505.50000000 12495.00000000 42502.50000000 22497.00000000 32499.50000000 12489.00000000 42496.50000000 22491.00000000 32499.50000000) 12491.00000000 3
Hint
For C + + users, kindly use scanf to avoid TLE for huge inputs.
ZOJ 3879 Capture the Flag