zoj The 12th Zhejiang Provincial Collegiate Programming Contest Capture the Flag
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5503
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.
分析:
先输入4个数,n,q,p,c
代表有n个队伍,q个服务器,每支队伍的初始分数p,还有c次操作
对于每次操作,首先输入一个k,代表k次攻击
每次攻击有三个数,a,b,c,代表a通过c服务器成功的攻击了b
对于每次成功的攻击,b会失去n-1分,这n-1分会平分给通过同一服务器攻击b的几支队伍
然后是q行,每行n个数,分别代表1~n是否成功维护了,1为成功,0为不成功
不成功的队伍会失去n-1分,这失去的分会平分给成功维护的那些队伍
然后输入k个数,询问这k支队伍的分数
AC代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
#define ls 2*i
#define rs 2*i+1
#define up(i,x,y) for(i=x;i<=y;i++)
#define down(i,x,y) for(i=x;i>=y;i--)
#define mem(a,x) memset(a,x,sizeof(a))
#define w(a) while(a)
#define LL long long
const double pi = acos(-1.0);
#define Len 20005
#define mod 19999997
#define exp 1e-5
const int INF = 0x3f3f3f3f; struct node
{
int id,rank;
double score;
} a[]; int n,q,c,t;
double p;
bool vis[][][],hsh[]; int cmp1(node a,node b)
{
return a.score>b.score;
} int cmp2(node a,node b)
{
return a.id<b.id;
} int main()
{
int i,j,k;
scanf("%d",&t);
w(t--)
{
scanf("%d%d%lf%d",&n,&q,&p,&c);
up(i,,n)
{
a[i].id = i;
a[i].rank = ;
a[i].score = p;
}
w(c--)
{
scanf("%d",&k);
mem(vis,false);
w(k--)
{
int atk,def,sev;
scanf("%d%d%d",&atk,&def,&sev);
if(vis[atk][def][sev]) continue;
vis[atk][def][sev] = true;
}
up(i,,q)//服务器
{
up(j,,n)//防守方
{
int cnt = ;
up(k,,n)//攻击方
{
if(vis[k][j][i])//统计攻击j的队伍有几支
cnt++;
}
if(!cnt)
continue;
double ss = 1.0*(n-)/cnt;//平分
a[j].score-=(n-);//防守方失去n-1
up(k,,n)
{
if(vis[k][j][i])//攻击方得到分数
a[k].score+=ss;
}
}
} up(i,,q)//服务器
{
mem(hsh,false);
int cnt = ;
up(j,,n)
{
int x;
scanf("%d",&x);
if(x)//成功维护的队伍数
{
hsh[j] = true;
cnt++;
}
else
{
hsh[j] = false;
a[j].score-=(n-);
}
}
if(cnt == n) continue;
double ss = 1.0*(n-)/cnt;
ss = ss*(n-cnt);
up(j,,n)
{
if(hsh[j])
a[j].score+=ss;
}
} sort(a+,a+n+,cmp1);
up(i,,n)//更新排名
{
if(i!=)
{
if(fabs(a[i].score-a[i-].score)<exp)
a[i].rank = a[i-].rank;
else
a[i].rank = i;
}
else
a[i].rank = i;
}
sort(a+,a+n+,cmp2);
scanf("%d",&k);
w(k--)
{
int x;
scanf("%d",&x);
printf("%f %d\n",a[x].score,a[x].rank);
}
}
} return ;
}
最后附一张 board :
http://paste.ubuntu.com.cn/i2563575
浙大霸气!!!杭电威武!!!
任性啊,,,
zoj The 12th Zhejiang Provincial Collegiate Programming Contest Capture the Flag的更多相关文章
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Team Formation
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5494 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Beauty of Array
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5496 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Lunch Time
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5499 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Convert QWERTY to Dvorak
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5502 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest May Day Holiday
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5500 The 12th Zhejiang Provincial ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Demacia of the Ancients
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5504 The 12th Zhejiang Provincial ...
- zjuoj The 12th Zhejiang Provincial Collegiate Programming Contest Ace of Aces
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5493 The 12th Zhejiang Provincial ...
- 140 - The 12th Zhejiang Provincial Collegiate Programming Contest(第二部分)
Floor Function Time Limit: 10 Seconds Memory Limit: 65536 KB a, b, c and d are all positive int ...
- 140 - The 12th Zhejiang Provincial Collegiate Programming Contest(浙江省赛2015)
Ace of Aces Time Limit: 2 Seconds Memory Limit: 65536 KB There is a mysterious organization c ...
随机推荐
- yum 安装mysql5.6
系统centos5.5 进入http://dev.mysql.com/downloads/repo/,下载RedHat Enterprise Linux 5 / Oracle Linux 5版. 点击 ...
- .Net搭建的WebService测试页使用TextArea大文本框方便调试
用.Net搭建的WebService,系统默认提供了测试页,供大家输入参数进行测试.但因为参数输入框使用的是单行input控件,导致无法输入换行文本,使得有些参数(如换行的xml)无法输入,及其不便. ...
- mysql创建外键出错(注意数据库表字段排序)
1. 两个字段的类型或者大小不严格匹配.例如,如果一个是int(10),那么外键也必须设置成int(10),而不是int(11),也不能是tinyint.另外,你还必须确定两个字段是否一个为 sig ...
- 导出证书Cer文件为Pem格式的步骤
(1)先导出Push Services的证书,比如我们命名为“magic_cert.p12”,注意导出时会让你输入密码. (2)再导出Push Services证书的密钥(Private Key),比 ...
- php object转数组示例
原本是这样格式的数据: object(Thrift\Server\PageCards)#32 (3) { ["cards"]=> array(10) { [0]=> o ...
- A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list.
图解: 此题过程分为三个阶段,分别是 1.负责后面一个节点,并且将这个节点插入到原来链表中 2.复制后面一个节点的random指针. 3 拆分组合链表为两部分. 第一部分代码: while(curr ...
- 解决 SVN cleanup 任务中断导致无法 update
解决 SVN cleanup 任务中断导致无法 update 今天在更新 svn 时, TortoiseSVN 一直在提示要进行 cleanup ,而执行 cleanup 时又提示: Cleanup ...
- shell && 和 || 的短路使用
shell && 和 || 的短路使用 && 和 || 在 shell 中分别表示 and 和 or,和其它语言类似,这两个操作有短路效应.也就是说,当判断式已经确定时 ...
- angularjs 获取地址传参
.controller('CityCtrl', function ($scope, $location,$ionicModal) { 注入location服务 $scope.name = $locat ...
- 海康威视摄像头SDK-网页版(NetVideoActiveX23.cab安装)
1.了解了OCX控件的使用.代码如下: <object classid="CLSID:CAFCF48D-8E34-4490-8154-026191D73924" codeba ...