思路:恶心模拟...照着题目怎么说就怎么做就好了
#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!
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 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.