Nash Equilibrium
Time limit1sMemory limit128 MB
Given two m by n payoff matrices for players A and B, list every action pair where each player's action is a best response to the other's.
- Level
Easy3 of 10
- Topics
- Brute force, Matrix, Implementation
- Solved
- No attempts yet
Problem
A two-player normal-form game between players and is completely described by:
- , the set of actions available to player ;
- , the set of actions available to player ;
- , an payoff matrix for player ;
- , an payoff matrix for player .
Both players choose their actions simultaneously — say player plays and player plays . The payoffs are then read from the matrices: player receives and player receives . Each player wants to maximize their own payoff.
Given a fixed action of player , a best response of player is any action that maximizes 's payoff, that is, any with . Symmetrically, given a fixed action of player , a best response of player is any action with .
A pair of actions is a pure-strategy Nash equilibrium if is a best response to and, at the same time, is a best response to .
Given the two payoff matrices and , find and list all pure-strategy Nash equilibria of the game.
Input
The input contains multiple test cases.
Each test case begins with a line containing two integers and (). The next lines give the rows of payoff matrix , and the following lines give the rows of payoff matrix ; each row lists integers. Every payoff value is an integer in the range to , inclusive.
The input ends with a line 0 0, which must not be processed.
Output
For each test case, let be the number of pure-strategy Nash equilibria of the game. Output:
- a line containing the single integer ;
- then lines, each containing two integers and (1-indexed), meaning that is a Nash equilibrium.
List the equilibria in lexicographic order: comes before if , or if and .
Hint
Consider a game in which players and each have two actions, with the payoff matrices shown below:

If player plays , then player maximizes their payoff by playing , since . Likewise, if player plays , then player maximizes their payoff by playing , since . So is a best response to and vice versa, which makes a pure-strategy Nash equilibrium.
By contrast, is not a Nash equilibrium: if player plays , then 's best response is , because .