Capture the Flag(模拟)

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

  • If a team has been attacked for a service P, they will lose N - 1 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 N - 1 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 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 first line contains an integer A - the number of the successful attacks. Then A 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 Q lines and each line contains N integers. The jth number of the ith line indicating the jth team's maintaining status of the ith service, where 1 means well and 0 means not well.
  • Finally there is an integer U (0 <= U <= 100), 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 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
Hint

For C++ users, kindly use scanf to avoid TLE for huge inputs.

题解:

排序的时候错了下,又开了个结构体,存排名,就过了,意思就是有N个队,每个队Q个防御塔,每个队初始得分是S,C个检查点;

每个检查点输入每个对的得分以及排名;

接下来一个A,A行,每行a,b,c代表a在防御塔c处打了b;

被打的扣N-1分,打的平分这些分;

然后Q行代表防御塔是否完好,坏了要修补,花费N-1,其他好的平分这些分;

还有如果存在多个a,b,c只按一个算;

说的有点啰嗦,就是一个模拟

代码:

  1 #include<iostream>
  2 #include<cstdio>
  3 #include<cstring>
  4 #include<cmath>
  5 #include<cstring>
  6 #include<algorithm>
  7 #include<set>
  8 #include<vector>
  9 using namespace std;
 10 typedef long long LL;
 11 struct Node{
 12     double sc;
 13     int k, rat;
 14     friend bool operator < (Node a, Node b){
 15         if(a.sc >= b.sc)return true;
 16         else return false;
 17     }
 18 };
 19 Node dt[10010], ans[10010];
 20 int vis[110][110][110];
 21 vector<int>vec[110][110];
 22 struct Node1{
 23     int b, c;
 24 };
 25 Node1 vv[100010];
 26 int sj[1010];
 27 
 28 int main(){
 29     int T, N, Q, S, C;
 30     scanf("%d", &T);
 31     while(T--){
 32         scanf("%d%d%d%d", &N, &Q, &S, &C);
 33         for(int i = 1; i <= N; i++)
 34             dt[i].k = i, dt[i].sc = S;
 35         while(C--){
 36             
 37             memset(vis, 0, sizeof(vis));
 38             for(int i = 0; i < 110; i++)
 39                 for(int j = 0; j < 110; j++)
 40                     vec[i][j].clear();
 41             int tp = 0;
 42             int A;
 43             scanf("%d", &A);
 44             
 45             for(int j = 0; j < A; j++){
 46                 int a, b, c;
 47                 scanf("%d%d%d", &a, &b, &c);
 48                 if(!vis[a][b][c]){
 49                     vis[a][b][c] = 1;
 50                     if(vec[b][c].size() == 0){
 51                         vv[tp].b = b;
 52                         vv[tp].c = c;
 53                         tp++;
 54                     }
 55                     vec[b][c].push_back(a);
 56                 }
 57             }
 58             for(int j = 0; j < tp; j++){
 59                 dt[vv[j].b].sc -= (N - 1);
 60                 for(int i = 0; i < vec[vv[j].b][vv[j].c].size(); i++){
 61                     int a = vec[vv[j].b][vv[j].c][i];
 62                     dt[a].sc += 1.0*(N - 1)/vec[vv[j].b][vv[j].c].size();
 63                 }
 64             }
 65             for(int j = 1; j <= Q; j++){
 66                 int t = 0;
 67                 for(int i = 1; i <= N; i++){
 68                     scanf("%d", sj + i);
 69                     if(sj[i])t++;    
 70                 }
 71                         
 72                 for(int i = 1; i <= N; i++){
 73                     
 74                     if(sj[i] == 0){
 75                         dt[i].sc -= (N - 1);
 76                         for(int k = 1; k <= N; k++){
 77                             if(sj[k]){
 78                                 dt[k].sc += 1.0*(N - 1)/t;
 79                             }
 80                         }
 81                     }
 82                 }
 83             }
 84             for(int i = 0; i <= 110; i++)ans[i] = dt[i];
 85             sort(ans + 1, ans + N + 1);
 86             
 87             ans[1].rat = 1;
 88             for(int i = 2; i <= N; i++){
 89                 if(fabs(ans[i].sc - ans[i - 1].sc) <= 1e-6){
 90                     ans[i].rat = ans[i - 1].rat;
 91                 }
 92                 else ans[i].rat = i;
 93             }
 94             for(int i = 1; i <= N; i++){
 95                 dt[ans[i].k].rat = ans[i].rat;
 96             }
 97             int L;
 98             scanf("%d", &L);
 99             while(L--){
100                 int x;
101                 scanf("%d", &x);
102                 for(int i = 1; i <= N; i++){
103                     if(dt[i].k == x){
104                         printf("%lf %d\n", dt[i].sc, dt[i].rat);
105                         break;
106                     }
107                 }
108                 
109             }
110         }
111     }
112     return 0;
113 }

 

转载于:https://www.cnblogs.com/handsomecui/p/5451060.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
CTF(Capture The Flag)是一种网络安全竞赛,参赛者通过解决一系列的题目,获取隐藏在其中的flag,以此来展示其网络安全攻防技术。而"the great wall"指的是中国长城,因此"CTF the great wall"可以理解为以中国长城为主题的CTF比赛。 "CTF the great wall"可将中国长城作为背景,提供一系列与其相关的题目。比赛的参与者可以通过解决这些题目,找到隐藏的flag,从而实现攻防技术的展示。 在CTF the great wall比赛中,可能会包括以下类型的题目: 1. 密码学:设置一些加密算法和密码,参赛者需要解密以找到flag。 2. 网络通信:模拟网络通信中的漏洞和攻击场景,参赛者需要找到并利用这些漏洞,获取flag。 3. 操作系统和二进制:提供一些二进制文件或者脚本,参赛者需要分析其中的漏洞,通过调试和逆向工程找到flag。 4. Web漏洞:提供一些网站,参赛者需要通过测试和分析发现其中存在的安全漏洞,从而找到flag。 通过这些题目,参赛者可以学习和展示各种网络安全攻防技术,例如密码学、网络漏洞挖掘、二进制漏洞挖掘和Web漏洞挖掘等,同时也能提高对中国长城的了解和认识。 总而言之,"CTF the great wall"是一种用中国长城作为主题的网络安全竞赛,通过解决一系列与长城相关的题目,参赛者能够在实践中学习和展示网络安全攻防技术。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值