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只按一个算;

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

代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
using namespace std;
typedef long long LL;
struct Node{
double sc;
int k, rat;
friend bool operator < (Node a, Node b){
if(a.sc >= b.sc)return true;
else return false;
}
};
Node dt[], ans[];
int vis[][][];
vector<int>vec[][];
struct Node1{
int b, c;
};
Node1 vv[];
int sj[]; int main(){
int T, N, Q, S, C;
scanf("%d", &T);
while(T--){
scanf("%d%d%d%d", &N, &Q, &S, &C);
for(int i = ; i <= N; i++)
dt[i].k = i, dt[i].sc = S;
while(C--){ memset(vis, , sizeof(vis));
for(int i = ; i < ; i++)
for(int j = ; j < ; j++)
vec[i][j].clear();
int tp = ;
int A;
scanf("%d", &A); for(int j = ; j < A; j++){
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
if(!vis[a][b][c]){
vis[a][b][c] = ;
if(vec[b][c].size() == ){
vv[tp].b = b;
vv[tp].c = c;
tp++;
}
vec[b][c].push_back(a);
}
}
for(int j = ; j < tp; j++){
dt[vv[j].b].sc -= (N - );
for(int i = ; i < vec[vv[j].b][vv[j].c].size(); i++){
int a = vec[vv[j].b][vv[j].c][i];
dt[a].sc += 1.0*(N - )/vec[vv[j].b][vv[j].c].size();
}
}
for(int j = ; j <= Q; j++){
int t = ;
for(int i = ; i <= N; i++){
scanf("%d", sj + i);
if(sj[i])t++;
} for(int i = ; i <= N; i++){ if(sj[i] == ){
dt[i].sc -= (N - );
for(int k = ; k <= N; k++){
if(sj[k]){
dt[k].sc += 1.0*(N - )/t;
}
}
}
}
}
for(int i = ; i <= ; i++)ans[i] = dt[i];
sort(ans + , ans + N + ); ans[].rat = ;
for(int i = ; i <= N; i++){
if(fabs(ans[i].sc - ans[i - ].sc) <= 1e-){
ans[i].rat = ans[i - ].rat;
}
else ans[i].rat = i;
}
for(int i = ; i <= N; i++){
dt[ans[i].k].rat = ans[i].rat;
}
int L;
scanf("%d", &L);
while(L--){
int x;
scanf("%d", &x);
for(int i = ; i <= N; i++){
if(dt[i].k == x){
printf("%lf %d\n", dt[i].sc, dt[i].rat);
break;
}
} }
}
}
return ;
}

Capture the Flag(模拟)的更多相关文章

  1. Capture the Flag ZOJ - 3879(模拟题)

    In computer security, Capture the Flag (CTF) is a computer security competition. CTF contests are us ...

  2. zoj The 12th Zhejiang Provincial Collegiate Programming Contest Capture the Flag

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5503 The 12th Zhejiang Provincial ...

  3. 第十二届浙江省大学生程序设计大赛-Capture the Flag 分类: 比赛 2015-06-26 14:35 10人阅读 评论(0) 收藏

    Capture the Flag Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge In computer security, Ca ...

  4. [DEFCON全球黑客大会] CTF(Capture The Flag)

    copy : https://baike.baidu.com/item/ctf/9548546?fr=aladdin CTF(Capture The Flag)中文一般译作夺旗赛,在网络安全领域中指的 ...

  5. [CTF]Capture The Flag -- 夺旗赛

    CTF(Capture The Flag) 简单介绍 CTF(Capture The Flag)中文一般译作夺旗赛,在网络安全领域中指的是网络安全技术人员之间进行技术竞技的一种比赛形式. `In co ...

  6. ZOJ 3879 Capture the Flag

    以此题纪念我写的第一篇acm博客,第一道模拟:) http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3879 题意非常复杂,感觉 ...

  7. ZOJ 3879 Capture the Flag 15年浙江省赛K题

    每年省赛必有的一道模拟题,描述都是非常的长,题目都是蛮好写的... sigh... 比赛的时候没有写出这道题目 :( 题意:首先输入4个数,n,q,p,c代表有n个队伍,q个服务器,每支队伍的初始分数 ...

  8. CTF—攻防练习之Capture the Flag

    主机:192.168.32.152 靶机:192.168.32.160 首先nmap扫描端口: ftp,ssh,http服务 dirb扫描目录,flag下有一个flag password目录下,查看源 ...

  9. Google Capture The Flag 2018 (Quals) - Reverse - Beginner's Quest - Gatekeeper

    参考链接:https://ctftime.org/task/6264 题目 It's a media PC! All fully purchased through the online subscr ...

随机推荐

  1. DM6437 dsp系列之启动过程全析(2)—AIS文件解析

    本文均属自己阅读源码的点滴总结,转账请注明出处谢谢. 欢迎和大家交流.qq:1037701636 email: gzzaigcn2009@163.com,gzzaigcn2012@gmail.com ...

  2. android开发步步为营之65:解决ScrollView和ListView触摸事件onInterceptTouchEvent相互冲突问题

    近期项目里面有个需求,一个页面放了一个ScrollView,整个页面能够向上滚动,然后ScrollView里面又嵌套了一个ListView,ListView里面的数据也是能够上下滑动的,理论上List ...

  3. go中string和slice no-copy转换

    在go里面,string和slice的互换是需要进行内存拷贝的,虽然在底层,它们都只是用 pointer + len来表示的一段内存. 通常,我们不会在意string和slice的转换带来的内存拷贝性 ...

  4. [Hapi.js] Up and running

    hapi is a rock solid server framework for Node.js. Its focus on modularity and configuration-over-co ...

  5. 编程算法 - 圆圈中最后剩下的数字(递推公式) 代码(C++)

    圆圈中最后剩下的数字(递推公式) 代码(C++) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 0,1...,n-1这n个数字排成一个圆圈, 从数字0開始 ...

  6. Tomcat 内存与优化篇

    Tomcat 内存与优化一.Tomcat 运行环境介绍 1.Tomcat 本身无法直接在计算机上运行,需要依赖硬件基础上的操作系统和Java虚拟机: 2.Java 程序启动时JVM都会分配一个初始内存 ...

  7. scrapy使用crontab定时任务不能自动执行的调试

    在用crontab进行定时任务时,发现任务并没有执行.而手动bash yourshell.sh时可以正常的执行程序.以下是个人的解决流程. 一.将错误打印打out.log */10 * * * * b ...

  8. openssl 对称加密算法enc命令详解

    1.对称加密算法概述 openssl的加密算法库提供了丰富的对称加密算法,我们可以通过openssl提供的对称加密算法指令的方式使用,也可以通过调用openssl提供的API的方式使用. openss ...

  9. IoC容器Autofac正篇之类型关联(服务暴露)(七)

    类型关联 类型关联就是将类挂载到接口(一个或多个)上去,以方便外部以统一的方式进行调用(看下例). 一.As关联 我们在进行手动关联时,基本都是使用As进行关联的. class Program { s ...

  10. EffectiveC#03--用委托表示回调,用事件定义对外接口

    1.回调的场景:我给了儿子一个任务且他可以报告状态来(重复的)打断我.而我在等待他完成任务的每一个部份时不用阻塞我自己的进程.他可以在有重要(或者事件)状态报告时,可以定时的打断我,或者向我询求帮助 ...