以此题纪念我写的第一篇acm博客,第一道模拟:)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3879

题意非常复杂,感觉好像在写一个游戏似的,一大堆规则,还全部都是纯模拟,一点算法都没有,全考代码的……

废话结束,开始说题——

  第一行输入t,表示有t组数据

  每组数据,第一行输入n, q, s, c,表示有n组队伍,每队q个地点,每队初始s分,一共c次操作

  接下来c组操作……

  每组操作,第一行输入m, 表示m次成功攻击

  接下来m次攻击……每次输入a, b, c,表示a攻击b的c地点。

  接下来输入q行,每行n个数,表示每队伍的每个地点的状态,1表示好,0表示不好……

  接下来一行输入d,表示d次查询

  接下来一行输入d个数,表示查询d组队的得分情况,并查询这几组队的排名……

规则:

  攻击n组队,每队q个地点。

  每一回合(即每次操作):

    如果第a队共有b个地点被攻击,无论多少队伍攻击他,每个地点十七失去(n-1)分,一共失去b*(n-1)分。攻击那个地点的队伍平均获得那个地点失去的(n-1)分。

    如果第a队的c地点状态为“不好”,则a队失去(n-1)分.

    如果第a队的c地点状态为“好”,c地点状态不好的队伍的个数为k,则a队获得(n-1)*k/(n-k);

    如果两支队伍的得分之差<0.00001,则认为两支队伍排名相同……

(坑死爹的规则啊啊啊啊啊啊)

写这道题要注意——

  1. 判断那个0.00001

  2. 如果在同一回合,a队攻击了b队的c地点多次,则只认为他攻击了一次

  3. 下一回合各个地点的状态重置……

ps.写完发现……

  1.  其实这道题我的姿势很挫,但最终还是过了……谢天谢地……

  2.  题很水,我也很水

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm> using namespace std; const int N = ;
const int NN = ; struct node //存各支队伍的信息
{
bool q[NN]; //个地点的状态
double point; //得分
bool ed[NN][N]; //c点是否被b队攻击
bool edp[NN]; //c点是否被攻击
int eds[NN]; //c点被攻击了几次
}tm[N]; struct node1 //按得分排序使用,这是最搓的地方……
{
int flag;
double p;
int r;
}sorting[N]; int t;
int n, q, c;
double s;
int sum[NN]; //存c地点良好状态的队伍数 bool cmp(node1 x, node1 y)
{
return x.p - y.p > 0.00001; //坑爹的0.00001
} void update() //数据初始化
{
for(int i = ; i < n; i++)
{
memset(tm[i].q, , sizeof(tm[i].q));
memset(tm[i].ed, , sizeof(tm[i].ed));
memset(tm[i].edp, , sizeof(tm[i].edp));
memset(tm[i].eds, , sizeof(tm[i].eds));
}
memset(sum, ,sizeof(sum));
} int main()
{
//freopen("test.txt", "r", stdin);
scanf("%d", &t);
while(t--)
{
scanf("%d%d%lf%d", &n, &q, &s, &c);
for(int i = ; i < n; i++)
{
memset(tm[i].q, , sizeof(tm[i].q));
memset(tm[i].ed, , sizeof(tm[i].ed));
memset(tm[i].edp, , sizeof(tm[i].edp));
memset(tm[i].eds, , sizeof(tm[i].eds));
memset(sum, , sizeof(sum));
tm[i].point = s;
}
for(int i = ; i < c; i++) //c次操作
{ int midn;
scanf("%d", &midn); //midn次攻击
for(int j = ; j < midn; j++)
{
int a, b, qc;
scanf("%d%d%d", &a, &b, &qc); tm[b-].edp[qc-] = ;
if(!tm[b-].ed[qc-][a-]) //判断是否重复攻击(ac前最后一次wa)
{
tm[b-].ed[qc-][a-] = ;
tm[b-].eds[qc-]++;
} }
if(midn > ) //如果有攻击,则算分(也不知道是不是有效剪枝)
{
for(int j = ; j < n; j++) //n点被攻击
{
for(int k = ; k < q; k++)
{
if(tm[j].edp[k] == ) //k点被攻击
{
tm[j].point -= 1.0*(n-); for(int l = ; l < n; l++)
{
if(tm[j].ed[k][l] == ) //l队攻击
{
tm[l].point += 1.0*(n-)/tm[j].eds[k];
}
} }
}
}
} for(int j = ; j < q; j++) //各队个点状态判断
{
int mid;
for(int k = ; k < n; k++)
{ scanf("%d", &mid);
if(mid == ) //状态不错
{
tm[k].q[j] = ;
sum[j]++; //j点状态好的数目++
}
}
for(int k = ; k < n; k++) //算分
{
if(tm[k].q[j] == ) tm[k].point -= 1.0*(n-);
else tm[k].point += 1.0*(n-)*(n-sum[j])/sum[j];
}
} int cq;
scanf("%d", &cq); //cq次查询
if(cq > ) //又是一个不知道有没有用的剪枝……
{
for(int j = ; j < n; j++)
{
sorting[j].p = tm[j].point;
sorting[j].flag = j;
}
sort(sorting, sorting+n, cmp);
sorting[].r = ;
for(int j = ; j < n; j++)
{
if(fabs(sorting[j-].p-sorting[j].p) < 0.00001 ) sorting[j].r = sorting[j-].r; //又是0.00001
else sorting[j].r = j+;
} for(int j = ; j < cq; j++)
{
int miding;
scanf("%d", &miding);
printf("%.8f", tm[miding-].point);
for(int k = ; k < n; k++) //最搓的地方又一次出现,寻找对应队伍的排名,效率低的要死(居然这么挫……推荐大家看看别人的排序方法,我这个实在……但是我实在不想改了)
{
if(sorting[k].flag == miding-) printf(" %d\n", sorting[k].r);
}
}
}
update();
}
}
return ;
}

  附上别人对队伍排名的操作——

 struct node1
{
int r; //排名
double p; //得分
int s; //下标
}sorting[N]; bool cmp1(node1 x, node1 y)
{
return x.p - y.p > 0.00001 //按得分排名
} bool cmp2(node1 x, node1 y)
{
return x.s < y.s; //按下标排序
} for(int i = ; i < n; i++)
{
sorting[i].p = tm[i].p;
sorting[i].s = i;
} sort(sorting, sorting+n, cmp1); sorting[].r = ;
for(int i = ; i < n; i++)
{
if(fabs(sorting[i]-sorting[i-]) < 0.00001) sorting[i].r = sorting[i-].r;
else sorting[i].r = i+;
} sort(sorting, sorting+n, cmp2);

ZOJ 3879 Capture the Flag的更多相关文章

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

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

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

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

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

  5. Capture the Flag(模拟)

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

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

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

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

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

  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. Matlab安装

    第一步:下载MATLAB 7.0,下载自己百度下就好. 三个ios文件 第二步:把每个IOS文件直接右键解压就好. 第三步:打开第一个解压文件夹.双击.exe文件 第四步:next之后把序列号黏贴上去 ...

  2. LR_问题_在导入wsdl时出现parsing error

    问题描述:使用LR录制webservice协议的脚本,在导入wsdl时出现parsing error,详见图 问题解决:在导入wsdl时输入的地址错误,只指定了地址的虚拟目录名称,未指定方法名称,应该 ...

  3. OpenCV在Android平台上的应用

    今年8月份, OpenCV 2.3.1发布了. 虽然从2.2开始, OpenCV就号称支持Android平台, 但真正能让OpenCV在Android上运行起来还是在2.3.1版本上. 在这个版本上, ...

  4. mysql中bigint在php中表示

    http://bbs.csdn.net/topics/340266753 http://www.percona.com/blog/2008/01/10/php-vs-bigint-vs-float-c ...

  5. px,dp,sp单位转换工具类

    在layout中使用dp 在代码中getWidth系列得到的是px 设置字体大小时使用的是sp /** * Android大小单位转换工具类 */ public class PxDpSpUtil { ...

  6. Cookie的具体使用之来存储对象

    1.创建一个新的cookie,并赋值. HttpCookie cookie;       cookie=new HttpCookie("user");       cookie.D ...

  7. VS2012 professional和VS2012 Ultimate的区别

    http://www.c-sharpcorner.com/news/1750/visual-studio-2012-editions-comparison.aspx http://karthikdod ...

  8. 设置COOKIE过期时间的方法

    第一,日期运算法 1)将期限设置为当前日期后的第N天的0时0分0秒 Response.Cookies(LastView).Expires=dateadd(d,N,date) 2)将期限设置为当前日期后 ...

  9. Android远程图片获取和本地缓存

    对于客户端——服务器端应用,从远程获取图片算是经常要用的一个功能,而图片资源往往会消耗比较大的流量,对 应用来说,如果处理不好这个问题,那会让用户很崩溃,不知不觉手机流量就用完了,等用户发现是你的应用 ...

  10. Java I/O 扩展

    Java I/O 扩展 标签: Java基础 NIO Java 的NIO(新IO)和传统的IO有着相同的目的: 输入 输出 .但是NIO使用了不同的方式来处理IO,NIO利用内存映射文件(此处文件的含 ...