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);
[CPP]View Plaincopy
- 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 ");
- While (true) {
- if (na = = at && 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++; break;
- }
- 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