以此题纪念我写的第一篇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. Robot Framework 环境搭建

    一.下载软件 1.安装Python 到官网,下载Python 2.7.9:https://www.python.org/downloads/,最好选择32位版本的(64位系统也支付32位版本),然后安 ...

  2. hdu 2736 Surprising Strings(类似哈希,字符串处理)

    重点在判重的方法,嘻嘻 题目 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> int ...

  3. Java快速排序 分别以数组0位作为基准 和最后一位作为基准的排序演示

    package util; public class Pub { public static void beforeSort(int[] arr){ System.out.println(" ...

  4. 李洪强iOS开发之OC语言description方法和sel

    OC语言description方法和sel 一.description方法 Description方法包括类方法和对象方法.(NSObject类所包含) (一)基本知识 -description(对象 ...

  5. iOS开发--多线程

    前面在<Bison眼中的iOS开发多线程是这样的(二)>一文中讲完了多线程的NSThread,不难发现这种方式的多线程实现起来非常的复杂,为了简化多线程的开发,iOS提供了GCD来实现多线 ...

  6. 是什么让 Ubuntu 选用 Qt 而不是 GTK?

    是什么让 Ubuntu 选用 Qt 而不是 GTK? 一个正在发生的事实,Ubuntu正在不断Qt化!我曾一直在抱怨的Software Center,今日一看源码,竟然有softwarecenter/ ...

  7. Unigui有用的网址

    http://www.cnblogs.com/ChinaEHR/tag/Delphi/

  8. java:synchronized

    synchronized:利用上锁实现数据同步,避免多线程操作的情况下,数据出现异常. 另一个线程必须等待当前线程执行完这个代码块以后才能执行该代码块. 一个线程获得了一个对象的同步锁,那这个对象上所 ...

  9. [POJ1330]Nearest Common Ancestors(LCA, 离线tarjan)

    题目链接:http://poj.org/problem?id=1330 题意就是求一组最近公共祖先,昨晚学了离线tarjan,今天来实现一下. 个人感觉tarjan算法是利用了dfs序和节点深度的关系 ...

  10. Enabling HierarchyViewer on Rooted Android Devices

    转自http://blog.apkudo.com/2012/07/26/enabling-hierarchyviewer-on-rooted-android-devices/. The Hierarc ...