Topic Link: Click to open the link
Test instructions
Given n games.
The following n numbers: Indicates whether the field is 1 wins or 2 wins.
1. The winner gets a point.
2, if the whole season has been decided the outcome of the game will not continue.
3, set to win this season need to win the S-Bureau, each innings first won the T-score player.
Ask:
Find all the (s,t) combinations to make the given N game record legal.
The output to sort.
Enumerates T.
A array of what matches the first person wins.
b array the number of matches that the second person won.
Set to win T is divided into one sentence. Then the first person to win the T-score is the second, and the next one wins the T-Score is the third.
The man who won the T-Score obviously won the game.
This runs at the same time a number of 2 people.
Complexity of:
Set to win a score of I, then this array is enumerated up to n/i times
i = [1, n]
So complexity = N/1 + N/2 + + n/n = NLN (n+1);
There is a two-point. The total complexity is O (n * LN (n+1) * log n);
Import Java.util.arraylist;import java.util.collections;import Java.util.list;import Java.util.Scanner;public class Main {class Ans implements comparable<ans>{int S, t;public ans (int a, int b) {s = A; t = b;} public int compareTo (Ans o) {if (s! = O.s) return Integer.compare (S, O.S); return Integer.compare (T, O.T);}} static int N = 100050;int[] A = new Int[n], B = new Int[n], W = new int[n];int at, BT, N; arraylist<ans> Ans = new arraylist<> (), void Init () {n = cin.nextint (); for (int i = 1; I <= n; i++) w[i] = cin. Nextint (); at = BT = 0;a[at++] = 0; b[bt++] = 0;for (int i = 1; I <= n; i++) {if (w[i]==1) a[at++] = I;else b[bt++] = i;} at--; Bt--;ans.clear ();} void Add (int x, int y) {ans tmp = new Ans (x, y); Ans.add (TMP);} void work (int x) {int na = 0, NB = 0;int Siza = 0, Sizb = 0;//system.out.println (x+ ":" +at+ "" +BT ") and while (true) {if (Na = = AT & amp;& NB = = BT) break;if (Na+x > at && nb+x > BT) return,/*if (Na+x > at) {if (nb+x = = bt) {sizb++; break; }return;} if (Nb+x > BT) {if (na+x = = at) {siza++; return;} /**/if (Na+x<=at && (NB+X>BT | | a[na+x] < B[NB+X])) {Siza++;na + = X;int L = 0, R = bt, pos = 0;while (L < = R) {int mid = (l+r) >>1;if (B[mid] < A[na]) {pos = mid; L = mid+1;} else R = mid-1;} NB = pos;} else if (nb+x <= bt) {sizb++;nb + = X;int L = 0, R = at, pos = 0;while (L <= R) {int mid = (l+r) >>1;if (A[mid] < B[NB]) {pos = mid; L = mid+1;} else R = mid-1;} na = pos;} else Return;//system.out.println ("[" +na+ "" +nb+ "]" + "{" +siza+ "" +sizb+ "}");} /**///system.out.println ("Last:" +siza+ "" "+sizb); if (Siza = = Sizb) return;if (Siza>sizb && w[n] = = 1) Add (Siza, x); else if (Siza<sizb && w[n] = = 2) Add (Sizb, x);} public void work () {init ();//int AAA = 0; if (aaa<=0) {System.out.println ("Debug"); return;} for (int i = 1; I <= n; i++) work (i); System.out.println (Ans.size ()); Collections.sort (ANS); for (int i = 0; i < ans.size (); i++) System.out.println (Ans.get (i). S+ "" +ans.get (i). T);} Main () {cin = new Scanner(system.in); } public static void Main (string[] args) {main E = new main (); E.work (); } public Scanner cin;
Codeforces 496D Tennis Game enumeration + two points