ZOJ 3879 Capture the Flag(模拟)

思路:恶心模拟...照着题目怎么说就怎么做就好了


#include<bits/stdc++.h>
using namespace std;
const int maxn = 100000;
#define exp 1e-5
struct Node
{int id,rank;double score;
}nodes[105];int vis[105][105][105];
int visit[105];
bool cmp1(Node a,Node b)
{return a.score > b.score;
}
bool cmp2(Node a,Node b)
{return a.id<b.id;
}
int T;
int main()
{scanf("%d",&T);while (T--){//	memset(vis,0,sizeof(vis));int n,q,p,c;scanf("%d%d%d%d",&n,&q,&p,&c);for (int i = 0;i<=n;i++){nodes[i].id=i;nodes[i].rank=1;nodes[i].score = p;}while (c--){int k;scanf("%d",&k);memset(vis,0,sizeof(vis));while (k--){int a,b,c;scanf("%d%d%d",&a,&b,&c);if (vis[a][b][c])continue; vis[a][b][c]=1;}for (int i = 1;i<=q;i++){for (int j = 1;j<=n;j++){int cnt = 0;for (int k = 1;k<=n;k++){if (vis[k][j][i])cnt++;}if (!cnt)continue;double sscore = 1.0*(n-1)/cnt;nodes[j].score-=(n-1);for (int k = 1;k<=n;k++){if (vis[k][j][i])nodes[k].score+=sscore;}}}for (int i = 1;i<=q;i++){memset(visit,0,sizeof(visit));int cnt = 0;for (int j = 1;j<=n;j++){int x;scanf("%d",&x);if (x){visit[j]=1;cnt++;}else{visit[j]=0;nodes[j].score-=(n-1);}}if (cnt==n)continue;double sscore = 1.0*(n-1)/cnt;sscore = sscore * (n-cnt);for (int j = 1;j<=n;j++){if (visit[j])nodes[j].score+=sscore;}}sort(nodes+1,nodes+n+1,cmp1);for (int i = 1;i<=n;i++)         {if(i!=1){if(fabs(nodes[i].score-nodes[i-1].score)<exp)nodes[i].rank = nodes[i-1].rank;elsenodes[i].rank = i;}elsenodes[i].rank = i;}sort(nodes+1,nodes+n+1,cmp2);int kk;scanf("%d",&kk);while (kk--){int x;scanf("%d",&x);printf("%f %d\n",nodes[x].score,nodes[x].rank);}}}
}

Description

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.



转载于:https://www.cnblogs.com/q934098774/p/5388686.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/288190.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

晋中学院计算机考研,晋中学院有多少人死在考研路上

晋中学院有多少人死在考研路上(2011-05-23 20:34:30)标签&#xff1a;日记杂谈有一句话叫作&#xff1a;长江后浪推前浪,前浪死在沙滩上&#xff0c;用来形容少年老成与故人的可怜。转眼间到了谋取出路的时候了&#xff0c;班上几乎所有的人都在那里嚷嚷的要考研&#xff0c;但…

解决ArcGIS 9.3卸载时出现invalid install.log file的方法

地信君都知道,ArcGIS 9.3 License卸载时常出现“invalid install.log file”的错误提示,而导致卸载失败,如下:

Nodejs前端服务器压缩图片

Nodejs作为前端服务器&#xff0c;自然能承担处理图片的能力&#xff0c; 使用GM for nodejs 作为图片处理器&#xff0c;调用ImageMagick处理图片 使用ImageMagick var imageMagick gm.subClass({ imageMagick: true }); 然后就像文档中使用gm那样使用ImageMagick即可 &#…

人工神经网络心得体会_卷积神经网络学习心得

萌新小白一只&#xff0c;刚刚接触AI&#xff0c;在遍历人工智能发展时就看到了“卷积神经网络”&#xff0c;顿时想到了去年被概率论支配的恐惧&#xff0c;因此想在这里分享一点经验来帮助大家更好理解。所谓“卷积神经网络”&#xff0c;就是结合卷积公式&#xff0c;建立类…

使用virt-install安装kvm虚拟机时需要的问题

使用virt-install安装kvm虚拟机时需要的问题今天在做kvm的实验时&#xff0c;使用virt-install安装虚拟机的过程中遇到了一些问题&#xff0c;其中有一个问题弄了好久都没有弄好&#xff0c;不过现在已经好了。由于我使用virt-install命令安装虚拟机的&#xff0c;其命令如下&a…

样式和主题的区别(Styles and Themes)

参考资料&#xff1a; http://www.tuicool.com/articles/VfiUba http://android.blog.51cto.com/268543/303728/转载于:https://www.cnblogs.com/8dull/p/5387072.html

从同步函数 hello-world-dotnet 开始探索OpenFunction

OpenFunction[1] 是一个现代化的云原生 FaaS&#xff08;函数即服务&#xff09;框架&#xff0c;它引入了很多非常优秀的开源技术栈&#xff0c;包括 Knative、Tekton、Shipwright、Dapr、KEDA 等&#xff0c;这些技术栈为打造新一代开源函数计算平台提供了无限可能&#xff1…

剑指offer之股票的最大利润

1 问题 求股票的最大利润&#xff0c;简言之就是求一个数组里面元素差的最大值&#xff0c;要求时间复杂度O(n) 2 代码实现 #include <stdio.h> #include <stdlib.h>int maxDiff(int *number, int length) {if (NULL number || length < 2){return 0;}int mi…

【ArcGIS风暴】ArcGIS 10.2栅格计算器实用公式大全(经典珍藏版)

栅格计算器(Raster Calculator) 是一种空间分析函数工具,可以输入地图代数表达式,使用运算符和函数来做数学计算,建立选择查询,或键入地图代数语法。只有熟练的运用并记忆一些常用的公式,才能很好的运用栅格计算器。本文将常见的及一些容易出错的公式予以总结,方便学习…

试卷代号6098计算机应用基础,2231电大《Visual Basic程序设计》试题和答案200507

试卷代号&#xff1a;2231座位号口口中央广播电视大学2004-2005学年度第二学期"开放专科"期末考试计算(应)、软件信息软 件 网 站 专业 VisualBasic程序设计 试题2005年7月题 号一二三四五总 分分 数得 分评卷人一&#xff0c;单项选择题(每小题2分&#xff0c;共30分…

还不会制作游戏脚本解放双手?那是你不会超强自动化框架AirTest!

最近朋友问我能不能写一个自动化&#xff0c;帮他解放一下双手。我想了想&#xff0c;在我知识里很多辅助脚本制作工具&#xff0c;想想那些可能会有一堆局限性&#xff0c;想到了Python有自动化测试游戏框架或者工具&#xff0c;但是一直没有了解&#xff0c;搜了下资料&#…

[js高手之路]使用原型对象(prototype)需要注意的地方

我们先来一个简单的构造函数原型对象的小程序 1 function CreateObj( uName, uAge ) {2 this.userName uName;3 this.userAge uAge;4 }5 CreateObj.prototype.showUserName function () {6 return this.userNa…

python 虚拟环境原理_Python 虚拟环境

建议在开发环境和生产环境下都使用虚拟环境来管理项目的依赖。 - Flask背景Python 应用通常会使用一些第三方的软件包和模块。不同的应用可能会依赖不同版本的同一个软件包&#xff0c;或者依赖不同的 Python 版本。设想这样的场景:小白之前有一个 Flask 0.10 做的网站并且一直…

pullToRefresh下拉刷新上拉加载

PullToRefresh 是一个第三方的工程。 之前的自定义下拉刷新控件貌似不太好用&#xff0c;于是网上找了这个。 参考&#xff1a;http://www.cnblogs.com/summers/p/4343964.html 主要是一些功能都提供了接口&#xff0c;不需要自己再写了。 废话不多说&#xff0c;上干货。 1、布…

ArcGIS删除地图投影坐标,只保留地理坐标

今天突发奇想,在ArcGIS中进行投影转换很容易,那么如何删除投影坐标,只保留地理坐标呢? 一开始想着从投影文件(.prj)入手,删除其投影信息,结构不尽如人意。 如果从定义地理坐标(Define Projection)的角度入手,重新定义地理坐标,如WGS84呢?经过尝试之…

RHEL5U8配置Centos yum源

由于RHEL的yum在线更新是收费的&#xff0c;如果没有注册的话是不能使用的&#xff0c;即不能在线安装软件。在这种情况下&#xff0c;如果我们使用的机器安装的是RHEL系统要是每次安装软件先挂载本地光盘会很繁琐&#xff0c;而且有些软件也是老版本的&#xff0c;这种情况下我…

剑指offer之圆圈最后剩下的数

1 问题 求圆圈最后剩下的数&#xff0c;比如数组0, 1, 2 ,3 ,4围城一个环&#xff0c;我们每次去掉第三个数字&#xff0c;删除的前4个数字依次是2, 0, 4, 1&#xff0c;最后剩下的数字是3 04 13 2 2 思路 我们用list,我们要支持环就这样,如果发现当…

如何获取 Linq 查询结果集合中的索引?

咨询区 Guy我有下面一段伪代码&#xff1a;string[] s {"zero", "one", "two", "three", "four", "five"};var x s .Select((a,i) > new {Value a, Index i}) .Where(b > b.Value.StartsWith("t&…

AirTest 基本使用及框架浅剖析——五分钟上手制作游戏辅助

简介 Airtest Project 是为编写自动化脚本&#xff0c;达到提升测试效率的一整套解决方案。它可以轻松的扩展到多平台、多引擎上&#xff1b;如基础的 Android和IOS手机应用、App&#xff1b;Windows上的应用等。 学习使用 Airtest Project 很容易&#xff0c;由于 Airtest P…

计算机组成原理xchg,8088数据传送指令-计算机组成原理与汇编语言-电子发烧友网站...

3.2.1 数据传送指令1. MOVOPRD1,OPRD2MOV是操作码&#xff0c;OPRD1和OPRD2分别是目的操作数和源操作数。该指令可把一个字节或一个字操作数从源地址传送到目的地址。源操作数可以是累加器、寄存器、存贮器以及立即操作数&#xff0c;而目的操作数可以是累加器、寄存器和存贮器…