Zoj Capture The Flag more difficult simulation

Source: Internet
Author: User

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 has 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:

  • The first line contains an integer-the number of the A successful attacks. Then A lines follow and all 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 is indexed from 1. You should notice that duplicate messages is invalid because of the rules. Just ignore them.
  • Then there is lines and each line Q contains N integers. jth ith The number of the line indicating jth the team's maintaining status ith of the service, where 1 means well and 0 means not well.
  • Finally There is an integer U (0 <= U <=), which describing the number of the queries. The following line contains U integers, which means Edward wants to know the score and the ranking of these teams.

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.


Links: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5527


Test instructions

N Teams, Q server, s for initial score, 5 operations


A attack in each operation

Each attack on a B ser represents a team attacking team B, via server ser. Ignoring repeated occurrences of the same a B ser.

After the attack, calculate the score to separate the attacks on each server. The attacking team-(n-1) points, divided the n-1 into the team attacking him.


Then the Q row n column

Indicates that on each server, n teams have not maintained their respective fields. Do not maintain a good team buckle n-1 points, the total score of the deduction divided to maintain a good team.


Then a u, ask you a team score and rank, and then output. When sorting, note the accuracy, such as 0.123451 and 0.123452 are not actually equal, but the accuracy is 1e-5, is considered equal


#include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> #include < malloc.h> #include <ctype.h> #include <math.h> #include <string> #include <iostream># Include <algorithm>using namespace std, #include <stack> #include <queue> #include <vector># Include <deque> #include <set> #include <map>using namespace std; #define MAXN 505#define EPS 1e-5struct Nodedef{double point;int id;int rank;}; Nodedef nod[110];int ok[11][110];int vis[110][110][15];vector <int> vec[11][110];int has[110]; int Cmp1 (nodedef a,nodedef b) {return a.point>b.point;} int CMP2 (nodedef a,nodedef b) {return a.id<b.id;} int main () {int t;scanf ("%d", &t), while (t--) {int n,q,s,c;scanf ("%d%d%d%d", &n,&q,&s,&c); for (int i =1;i<=n;i++) {nod[i].point=s;nod[i].id=i;} while (c--) {int aa;scanf ('%d ', &AMP;AA), memset (vis,0,sizeof Vis); for (int i=1;i<=q;i++) {for (int j=1;j<=n;j++) { Vec[i][j].clear ();}} For (inT i=0;i<aa;i++)//a server attack, there is no interaction between the servers, so Ser has to open a dimension, and then put all the troops attacking B together {int a,b,ser;scanf ("%d%d%d",&a,& B,&ser); if (vis[a][b][ser]==0)//Repeat command to remove vec[ser][b].push_back (a); Vis[a][b][ser]=1;} for (int i=1;i<=q;i++) {to (int j=1;j<=n;j++) {if (Vec[i][j].size ()) {nod[j].point-= (n-1); for (int k=0;k<vec[i  ][j].size (); k++)//According to the rules, the attacking person splits the n-1 (nod[vec[i][j][k]].point+=1.0* (n-1)/vec[i][j].size ();} }}} for (int i=1;i<=q;i++)//different servers directly do not affect each other {for (int j=1;j<=n;j++) {int tem;scanf ("%d", &ok[i][j]);} int li=0;int yi=0;for (int j=1;j<=n;j++) {if (ok[i][j]) yi++; else{nod[j].point-= (n-1); li++;}} for (int j=1;j<=n;j++) {if (Ok[i][j]) nod[j].point+=1.0* (n-1) *li/yi;//Divide the number of servers that have been corrupted by *n-1 divide the server by Yi Maintenance} sort (nod+1 , NOD+1+N,CMP1); nod[1].rank=1;for (int i=2;i<=n;i++) {if (nod[i-1].point-nod[i].point) <eps)//The place to note, because of the accuracy problem, So here to <eps//such as 0.123451 and 0.123452 are actually not equal, but the accuracy is 1e-5, is equal to the nod[i].rank=nod[i-1].rank;elsenod[i].rank=i;} int cha;scanf ("%d", &cha); sort (nod+1,nod+1+n,cmp2); for (int i=1;i<=cha;i++) {int id;scanf ("%d", &id);p rintf ("%f%d\n", Nod[id].point,nod[id].rank);}}}  return 0;}






Zoj Capture The Flag more difficult simulation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.