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

#include <iostream>

#include <string>

#include <stdio.h>

#include<algorithm>

#include<string.h>

#include<cmath>

#include<stack>

#include<queue>

#define exp 1e-5

using namespace std;// 大水题;

const int MAX=10000+10;

struct node
{
int ID; int rank; double sore;
}inf[110]; bool vis[110][110][15]; bool has[110]; bool cmp1(node a,node b)
{
return a.sore>b.sore;
} bool cmp2(node a,node b)
{
return a.ID<b.ID;
} int main()
{ int T,N,Q,C,k; double P; scanf("%d",&T); while(T--)
{ scanf("%d %d %lf %d",&N,&Q,&P,&C); for(int i=0;i<=N;i++)
{
inf[i].ID=i;
inf[i].rank=1;
inf[i].sore=P;
} while(C--)
{
scanf("%d",&k); memset(vis,false,sizeof(vis)); for(int i=0;i<k;i++)
{
int a,d,s; scanf("%d %d %d",&a,&d,&s); if(!vis[a][d][s])
{
vis[a][d][s]=true;
} }
for(int i=1;i<=Q;i++)
{ for(int j=1;j<=N;j++)
{
int ans=0; for(int kk=1;kk<=N;kk++)
{
if(vis[kk][j][i])
{
ans++;
}
}
if(!ans)
{
continue;
}
double sa=1.0*(N-1)/ans; inf[j].sore-=(N-1); for(int kk=1;kk<=N;kk++)
{
if(vis[kk][j][i])
{
inf[kk].sore+=sa;
}
}
}
}
for(int i=1;i<=Q;i++)
{
int ans=0; memset(has,false,sizeof(has));
for(int j=1;j<=N;j++)
{
int sa;
scanf("%d",&sa);
if(sa)
{
has[j]=true;
ans++;
}
else
{
inf[j].sore-=(N-1);
}
}
if(ans==N)
{
continue;
}
double ss=1.0*(N-1)/ans;
ss=(N-ans)*ss;
for(int j=1;j<=N;j++)
{
if(has[j])
{
inf[j].sore+=ss;
}
}
}
sort(inf+1,inf+N+1,cmp1); for(int i=1;i<=N;i++)
{
if(i!=1)
{
if(fabs(inf[i].sore-inf[i-1].sore)<exp)
{
inf[i].rank=inf[i-1].rank;
}
else
{
inf[i].rank=i;
}
}
else
{
inf[i].rank=i;
}
} sort(inf+1,inf+N+1,cmp2);//前一次排序的ID已乱,重排; scanf("%d",&k); while(k--)
{
int sa; scanf("%d",&sa); printf("%f %d\n",inf[sa].sore,inf[sa].rank); }
}
}
return 0; }

版权声明:本文为博主原创文章,未经博主允许不得转载。

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

  1. 第十二届浙江省大学生程序设计大赛-May Day Holiday 分类: 比赛 2015-06-26 14:33 10人阅读 评论(0) 收藏

    May Day Holiday Time Limit: 2 Seconds Memory Limit: 65536 KB As a university advocating self-learnin ...

  2. 第十二届浙江省大学生程序设计大赛-Beauty of Array 分类: 比赛 2015-06-26 14:27 12人阅读 评论(0) 收藏

    Beauty of Array Time Limit: 2 Seconds Memory Limit: 65536 KB Edward has an array A with N integers. ...

  3. 第十二届浙江省大学生程序设计大赛-Ace of Aces 分类: 比赛 2015-06-26 14:25 12人阅读 评论(0) 收藏

    Ace of Aces Time Limit: 2 Seconds Memory Limit: 65536 KB There is a mysterious organization called T ...

  4. 第十二届浙江省大学生程序设计大赛-Demacia of the Ancients 分类: 比赛 2015-06-26 14:39 30人阅读 评论(0) 收藏

    Demacia of the Ancients Time Limit: 2 Seconds Memory Limit: 65536 KB There is a popular multiplayer ...

  5. 第十二届浙江省大学生程序设计大赛-Lunch Time 分类: 比赛 2015-06-26 14:30 5人阅读 评论(0) 收藏

    Lunch Time Time Limit: 2 Seconds Memory Limit: 65536 KB The 999th Zhejiang Provincial Collegiate Pro ...

  6. 第十二届浙江省大学生程序设计大赛-Team Formation 分类: 比赛 2015-06-26 14:22 50人阅读 评论(0) 收藏

    Team Formation Time Limit: 3 Seconds Memory Limit: 131072 KB For an upcoming programming contest, Ed ...

  7. 团体程序设计天梯赛L1-019 谁先倒 2017-03-22 17:35 33人阅读 评论(0) 收藏

    L1-019. 谁先倒 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 划拳是古老中国酒文化的一个有趣的组成部分.酒桌上两人划拳 ...

  8. 团体程序设计天梯赛L3-010 是否完全二叉搜索树 2017-03-24 16:12 29人阅读 评论(0) 收藏

    L3-010. 是否完全二叉搜索树 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 将一系列给定数字顺序插入一个初始为空的二叉搜 ...

  9. Android 应用中十大常见 UX 错误 分类: H1_ANDROID 2013-09-21 13:59 404人阅读 评论(0) 收藏

    转载自:http://www.apkbus.com/android-5661-1.html 摘要: Android 开发者关系团队每天都会试用无数的 App 或者受到无数的开发者发来的请求评测的 Ap ...

随机推荐

  1. JAVA字符串的GZIP压缩解压缩

    package com.gzip; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import ...

  2. zabbix监控路由器所有接口信息

    zabbix监控路由器所有接口信息 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 1.首先在服务器端安装snmp工具 [root@bogon yinzhengjie]# yum - ...

  3. 转:NodeJS、NPM安装配置步骤

    1.windows下的NodeJS安装是比较方便的(v0.6.0版本之后,支持windows native),只需要登陆官网(http://nodejs.org/),便可以看到下载页面.  2.下载完 ...

  4. AJAX简单的数据增删改与分页应用

    运行截图: PageBar.js: /* * 说明: * 整体思想,1.第一页时不显示:首页,上一页, * 2.最后一页时不显示:下一页,尾页 * 3.中间有 5 页导航, * 若:3.1.(总页数& ...

  5. ofbiz进击 第一节。 新建自己的webapp项目

    创建一个webapp的过程更新下来项目(直接从svn上面切下来就好),要先ant clean 下,然后在重新ant下.一: start sheel here :ant create-component ...

  6. Spring 中 Xml配置文件属性的说明

    Xml配置文件属性的说明: <bean id="TheAction" ⑴ class="net.xiaxin.spring.qs.UpperAction" ...

  7. linux下MYSQL备份与恢复

    1.用命令实现备份 数据库备份是很重要的.如果定期做好备份,这样就可以在发生系统崩溃时恢复数据到最后一次正常的状态,把损失减小到最少.MySQLl提供了一个mysqldump命令,我们可以用它进行数据 ...

  8. 如何将扩展名为.backup的文件导入postgresql中 求步骤 新手 谢谢.

    1.到www.postgresql.org下载pgadmin这个工具,安装好2.在菜单-文件-新增服务器 名称:TEST-PGSQL(名称自己编) 主机:填上你postgresql数据库的服务器ip地 ...

  9. zw版【转发·台湾nvp系列Delphi例程】HALCON 3D Position Of Circles

    zw版[转发·台湾nvp系列Delphi例程]HALCON 3D Position Of Circles procedure TForm1.action();var ho_Image, ho_Elli ...

  10. 《C语言入门1.2.3—一个老鸟的C语言学习心得》—清华大学出版社炮制的又一本劣书及伪书

    <C语言入门1.2.3—一个老鸟的C语言学习心得>—清华大学出版社炮制的又一本劣书及伪书 [薛非评] 区区15页,有80多个错误. 最严重的有: 通篇完全是C++代码,根本不是C语言代码. ...