Title Link: ZOJ 3879 Capture the Flag
Test instructions: Given n teams attacking each other server, there are the following rules:
1. If team A's server 1 is successfully attacked by Team B, Team A will lose n-1 points, and this n-1 point score will be split equally to other teams that successfully attack team A's server 1.
eg
A total of 4 teams
A B 1
C B 1
At this point team A and team C both got 1.5 (3/2) points and Team B lost 3 points.
2. If a team fails to maintain their servers, the team will lose n-1 points, which n-1 divided into other teams that can maintain a good server.
eg
1 1 0 1
0 1 1 1
For server 1 (that is, the first row), only the C team is not maintained, so C team lost 3 points, the A,B,D team each get 1 (3/3) points.
For server 2 (that is, the second row), only a team is not maintained, so team a lost 3 points, the C,B,D team each get 1 (3/3) points.
Output the score and rank of each game in the C game.
Note: Even if each server is attacked multiple times, the score is counted only once.
AC Code:
#include <stdio.h> #include <string.h> #include <vector> #include <algorithm>using namespace Std;const double ep=1e-5;bool vis[110][110][110];bool cvis[110][110];struct node{double p;int Id,rank;}; struct node pp[110];d ouble p[110];int rank[110];bool cmp (node A,node b) {return A.P>B.P;} BOOL CMP2 (node A,node b) {return a.id<b.id;} void GetRank (double arr[],int n) {int i;for (i=1;i<=n;i++) {pp[i].id=i;pp[i].p=arr[i];} Sort (pp+1,pp+n+1,cmp); int r=1;pp[1].rank=r;r++;for (i=2;i<=n;i++) {if (PP[I-1].P-PP[I].P<=EP) pp[i].rank=pp[ I-1].rank;else pp[i].rank=r;r++;} for (i=1;i<=n;i++) Rank[pp[i].id]=pp[i].rank;} int main () {int t;int n,q,s,c;int a,i,j;int u,v,w,k;scanf ("%d", &t), while (t--) {scanf ("%d%d%d%d", &n,&q, &S,&C); for (i=1;i<=n;i++) {p[i]=s*1.0; Rank[i]=1;} while (c--) {memset (vis,false,sizeof vis); Memset (cvis,false,sizeof CVIs); scanf ("%d", &a); for (i=0;i<a;i++) { scanf ("%d%d%d", &u,&v,&w); cvis[v][w]=true;vis[u][v][w]=true;} int count=0///attacked J team, K Server for (j=1;j<=n;j++) {for (k=1;k<=q;k++) {count=0;for (i=1;i<=n;i++) if (Vis[i][j][k]) count++;if (count==0) Continue; for (i=1;i<=n;i++) if (Vis[i][j][k]) p[i]+= (n-1) *1.0/count;} Count=0;for (k=1;k<=q;k++) if (Cvis[j][k]) p[j]-= (n-1);} int St;bool vvis[110];for (i=1;i<=q;i++) {count=0;for (j=1;j<=n;j++) {vvis[j]=false;scanf ("%d", &st); if (!st ) count++;//not work well else vvis[j]=true;} if (count==0) continue;for (j=1;j<=n;j++) {if (!vvis[j]) p[j]-= (n-1); else p[j]+= (n-1) *count*1.0/(N-count);}} GetRank (p,n); scanf ("%d", &u), while (u--) {scanf ("%d", &v);p rintf ("%.8lf%d\n", P[v],rank[v]);}} return 0;} /*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 42500.00000000 12500.00000000 12500.00000000 12500.00000000 12501.50000000 12497.00000000 42501.50000000 1 2500.00000000 32505.50000000 12495.00000000 42502.50000000 22497.00000000 32499.50000000 12489.00000000 42496.50000000 22491.0000000032499.50000000 12491.00000000 3*/
ZOJ 3879 Capture The Flag (Zhejiang province game K + simulation)