ZOJ - 3879 Capture the Flag (模拟)题意难懂的水题

来源:互联网 发布:域名有什么商业价值 编辑:程序博客网 时间:2024/05/21 22:42
ZOJ - 3879
Capture the Flag
Time Limit:                                                        2000MS                        Memory Limit: 65536KB 64bit IO Format:                            %lld & %llu                       

SubmitStatus

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 areN teams which participate in the competition. In the beginning, each team hasS 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!

<h4< body="">

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. ThenA 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. Thejth number of the ith line indicating the jth team's maintaining status of theith 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 containsU integers, which means Edward wants to know the score and the ranking of these teams.

<h4< body="">

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.

<h4< body="">

Sample Input

14 2 2500 501 1 1 11 1 1 141 2 3 421 2 13 2 11 1 1 11 1 1 141 2 3 411 2 21 1 1 11 1 1 041 2 3 400 0 0 00 0 0 041 2 3 401 1 1 11 1 1 121 4
<h4< body="">

Sample Output

2500.00000000 12500.00000000 12500.00000000 12500.00000000 12501.50000000 12497.00000000 42501.50000000 12500.00000000 32505.50000000 12495.00000000 42502.50000000 22497.00000000 32499.50000000 12489.00000000 42496.50000000 22491.00000000 32499.50000000 12491.00000000 3

Hint

For C++ users, kindly use scanf to avoid TLE for huge inputs.

Hint

Source

The 12th Zhejiang Provincial Collegiate Programming Contest
//题意:有N个人相互打架,掠夺财产
前提:
1、在一个事件中,如果人x在某个水晶塔旁边被k个人打了,那么人x的钱数会将少(N-1)元,这(N-1)元会被打他的k个人平分。
2、如果人x的某个水晶塔坏了,那么他就得花(N-1)元请这个水晶塔好着的人来修复,那么这(N-1)元就会被他们平分。
先输入四个数N,Q,S,C,分别表示N个人参加一场搏斗,有Q个水晶塔(服务站),每个队伍刚开始时都有S元钱,接下来是C个事件。
每个事件第一行先输入一个A,表示发生了A次战斗,接下来A行,每行输入上个数x,y,z,表示在第z个水晶塔旁边x击打了y。(要忽略重复的)
接下来有Q行输入,每行输入有N个数,表示第j个人的第i个水晶塔是否是好的(1表示好的,0表示坏的)。
再接下来输入一个u,表示有u个询问,接下来输入u个数,对于每个数,表示询问这个人现在的钱数和排名,并输出。
//思路:
题意理解清了,这就是个水题了,直接模拟
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<cstring>#include<algorithm>#include<set>#include<vector>using namespace std;typedef long long LL;struct Node{double sc;int k, rat;friend bool operator < (Node a, Node b){if(a.sc >= b.sc) return true;else return false;}};Node dt[10010], ans[10010];int vis[110][110][110];vector<int>vec[110][110];struct Node1{int b, c;};Node1 vv[100010];int sj[1010];int main(){int T, N, Q, S, C;scanf("%d", &T);while(T--){scanf("%d%d%d%d", &N, &Q, &S, &C);for(int i = 1; i <= N; i++)dt[i].k = i, dt[i].sc = S;while(C--){memset(vis, 0, sizeof(vis));for(int i = 0; i < 110; i++)for(int j = 0; j < 110; j++)vec[i][j].clear();int tp = 0;int A;scanf("%d", &A);for(int j = 0; j < A; j++){int a, b, c;scanf("%d%d%d", &a, &b, &c);if(!vis[a][b][c]){vis[a][b][c] = 1;if(vec[b][c].size() == 0){vv[tp].b = b;vv[tp].c = c;tp++;}vec[b][c].push_back(a);}}for(int j = 0; j < tp; j++){dt[vv[j].b].sc -= (N - 1);for(int i = 0; i < vec[vv[j].b][vv[j].c].size(); i++){int a = vec[vv[j].b][vv[j].c][i];dt[a].sc += 1.0*(N - 1)/vec[vv[j].b][vv[j].c].size();}}for(int j = 1; j <= Q; j++){int t = 0;for(int i = 1; i <= N; i++){scanf("%d", sj + i);if(sj[i])t++;}for(int i = 1; i <= N; i++){if(sj[i] == 0){dt[i].sc -= (N - 1);for(int k = 1; k <= N; k++){if(sj[k]){dt[k].sc += 1.0*(N - 1)/t;}}}}}for(int i = 0; i <= 110; i++)ans[i] = dt[i];sort(ans + 1, ans + N + 1);ans[1].rat = 1;for(int i = 2; i <= N; i++){if(fabs(ans[i].sc - ans[i - 1].sc) <= 1e-6){ans[i].rat = ans[i - 1].rat;}else ans[i].rat = i;}for(int i = 1; i <= N; i++){dt[ans[i].k].rat = ans[i].rat;}int L;scanf("%d", &L);while(L--){int x;scanf("%d", &x);for(int i = 1; i <= N; i++){if(dt[i].k == x){printf("%lf %d\n", dt[i].sc, dt[i].rat);break;}}}}}return 0;}

0 0
原创粉丝点击