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

    1. [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. 1
  2. 4 2 2500 5
  3. 0
  4. 1 1 1 1
  5. 1 1 1 1
  6. 4
  7. 1 2 3 4
  8. 2
  9. 1 2 1
  10. 3 2 1
  11. 1 1 1 1
  12. 1 1 1 1
  13. 4
  14. 1 2 3 4
  15. 1
  16. 1 2 2
  17. 1 1 1 1
  18. 1 1 1 0
  19. 4
  20. 1 2 3 4
  21. 0
  22. 0 0 0 0
  23. 0 0 0 0
  24. 4
  25. 1 2 3 4
  26. 0
  27. 1 1 1 1
  28. 1 1 1 1
  29. 2
  30. 1 4

Sample Output

  1. 2500.00000000 1
  2. 2500.00000000 1
  3. 2500.00000000 1
  4. 2500.00000000 1
  5. 2501.50000000 1
  6. 2497.00000000 4
  7. 2501.50000000 1
  8. 2500.00000000 3
  9. 2505.50000000 1
  10. 2495.00000000 4
  11. 2502.50000000 2
  12. 2497.00000000 3
  13. 2499.50000000 1
  14. 2489.00000000 4
  15. 2496.50000000 2
  16. 2491.00000000 3
  17. 2499.50000000 1
  18. 2491.00000000 3

题意:首先给你四个数,n,q,s,c,代表着队伍的个数,服务器的个数,最初的分数,以及检查点的个数;

然后以下c行:

对于每一个检查点c:

1、首先有一个A,代表有A次攻击,对于每次攻击,有三个数a,b,c,a攻击了c服务器上的b;

对于每个服务器上的队伍,受攻击的会减少(n-1)分,并且会平均分配给攻击这个队伍的那些队伍;

还有一点就是重复的消息无效。(这点很坑)。

2、然后有q行01串,一行n位,代表每个服务器上的每个队伍的状态,如果为0,就代表处于失分状态,就会失去(n-1)分,然后平均分配给这一行上状态是1的那些队伍

3、最后有k个数字,为询问的队伍的个数,然后k个数字,代表要你输出这k个人的分数以及排名,分数相同的排名也一样。

总之题目比较长比较丑,不过理解了之后,还是一个比较水的模拟题;

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<cmath>
  6. using namespace std;
  7. const double eps=1e-;
  8. int t,n,q,c,u;
  9. double s;
  10. bool vis[][][];
  11. int a,x,y,z,ser[][],book[],cnt,p[];
  12. struct team{
  13. int i;
  14. double s;
  15. }te[];
  16.  
  17. inline bool cmp1(team a,team b){
  18. return a.s>b.s;
  19. }
  20.  
  21. inline bool cmp2(team a,team b){
  22. return a.i<b.i;
  23. }
  24.  
  25. int main(){
  26. scanf("%d",&t);
  27. while(t--){
  28. scanf("%d%d%lf%d",&n,&q,&s,&c);
  29. for(int i=;i<=n;i++) te[i].s=s,te[i].i=i;
  30. while(c--){
  31. scanf("%d",&a);
  32. for(int i=;i<=n;++i){
  33. for(int j=;j<=n;++j){
  34. for(int k=;k<=q;++k)
  35. {
  36. vis[i][j][k]=;
  37. ser[j][k]=;
  38. }
  39. }
  40. }
  41. for(int i=;i<=a;++i){
  42. scanf("%d%d%d",&x,&y,&z);
  43. if(!vis[x][y][z])
  44. {
  45. vis[x][y][z]=;
  46. ser[y][z]++;
  47. }
  48.  
  49. }
  50. for(int j=;j<=n;++j)
  51. for(int k=;k<=q;++k)
  52. if(ser[j][k])
  53. {
  54. te[j].s-=(n-);
  55. for(int i=;i<=n;++i)
  56. if(vis[i][j][k])
  57. te[i].s+=(n-)/(double)ser[j][k];
  58. }
  59. for(int j=;j<=q;++j)
  60. {
  61. cnt=;
  62. for(int i=;i<=n;++i)
  63. {
  64. scanf("%d",&book[i]);
  65. if(!book[i]){
  66. cnt++;
  67. te[i].s-=(n-);
  68. }
  69. }
  70. for(int i=;i<=n;++i)
  71. if(book[i]) te[i].s+=(double)(n-)*cnt/(n-cnt);
  72. }
  73. sort(te+,te+n+,cmp1);
  74. for(int i=;i<=n;++i)
  75. {
  76. if(i==||fabs(te[i].s-te[i-].s)>eps)
  77. p[te[i].i]=i;
  78. else
  79. p[te[i].i]=p[te[i-].i];
  80. }
  81. sort(te+,te+n+,cmp2);
  82. scanf("%d",&u);
  83. while(u--){
  84. int temp;
  85. scanf("%d",&temp);
  86. printf("%.8f %d\n",te[temp].s,p[temp]);
  87. }
  88. }
  89. }
  90. return ;
  91. }

Capture the Flag ZOJ - 3879(模拟题)的更多相关文章

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

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

  2. Capture the Flag(模拟)

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

  3. 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 ...

  4. CodeForces - 427B (模拟题)

    Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  5. 第十二届浙江省大学生程序设计大赛-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 ...

  6. 全国信息学奥林匹克联赛 ( NOIP2014) 复赛 模拟题 Day1 长乐一中

    题目名称 正确答案  序列问题 长途旅行 英文名称 answer sequence travel 输入文件名 answer.in sequence.in travel.in 输出文件名 answer. ...

  7. UVALive 4222 Dance 模拟题

    Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...

  8. cdoj 25 点球大战(penalty) 模拟题

    点球大战(penalty) Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/2 ...

  9. Educational Codeforces Round 2 A. Extract Numbers 模拟题

    A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...

随机推荐

  1. Vim 经常使用快捷键及键盘图

    Vim经常使用的快捷键 h - 光标左移一个字符   j - 光标下移一个字符 k - 光标上移一个字符   l - 光标右移一个字符  下移15行 - 15j Ctrl + f - 屏幕向下移动一页 ...

  2. ios 从rgb array生成UIImage并显示,oc版

    ; ; const size_t Area = Width * Height; ; // rgba std::vector<uint8_t> output(Area*channles); ...

  3. shell 切割文件

    [root@hadoop2 xiaole_chk_url]# cat looh.index.splitfile.sh loop_c=0loop_step=10001loop_tag=0str_head ...

  4. Linux I2C设备驱动编写(一)【转】

    本文转载自:http://blog.csdn.net/airk000/article/details/21345457 在Linux驱动中I2C系统中主要包含以下几个成员: I2C adapter 即 ...

  5. poj3539 Elevator——同余类bfs

    题目:http://poj.org/problem?id=3539 题目大意是给定 a, b, c,求 1~h 内有多少个数可以被 a, b, c 通过加减法组成: 这是今天刚讲的神奇的——同余类 b ...

  6. bzoj1345

    贪心 这并没有想清楚就看题解了... 看上去肯定是贪心,那么怎么贪呢?事实上,我们想一下,假设max(a[i],a[i+1])中a[i]没有合并,那么后面取max肯定是a[i+1],因为如果后面合并之 ...

  7. 基于spark和flink的电商数据分析项目

    目录 业务需求 业务数据源 用户访问Session分析 Session聚合统计 Session分层抽样 Top10热门品类 Top10活跃Session 页面单跳转化率分析 各区域热门商品统计分析 广 ...

  8. [Swift通天遁地]二、表格表单-(12)设置表单文字对齐方式以及自适应高度的文本区域TextArea

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  9. iOS - UITableView 多选功能实现

    :自定义Cell中的代码 #import <UIKit/UIKit.h> @interface TestCell : UITableViewCell @property(nonatomic ...

  10. Android 从服务器获取时间戳转换为年月日

    用JAVA相关类转换.代码如下: Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(NumberUtils.ge ...