codeforces-242A-Heads or Tails【暴力】

来源:互联网 发布:数据库分页查询sql语句 编辑:程序博客网 时间:2024/06/07 08:56

codeforces-242A-Heads or Tails【暴力】


Petya and Vasya are tossing a coin. Their friend Valera is appointed as a judge. The game is very simple. First Vasya tosses a coin x times, then Petya tosses a coin y times. If the tossing player gets head, he scores one point. If he gets tail, nobody gets any points. The winner is the player with most points by the end of the game. If boys have the same number of points, the game finishes with a draw.

At some point, Valera lost his count, and so he can not say exactly what the score is at the end of the game. But there are things he remembers for sure. He remembers that the entire game Vasya got heads at least a times, and Petya got heads at least b times. Moreover, he knows that the winner of the game was Vasya. Valera wants to use this information to know every possible outcome of the game, which do not contradict his memories.

Input
The single line contains four integers x, y, a, b (1 ≤ a ≤ x ≤ 100, 1 ≤ b ≤ y ≤ 100). The numbers on the line are separated by a space.

Output
In the first line print integer n — the number of possible outcomes of the game. Then on n lines print the outcomes. On the i-th line print a space-separated pair of integers ci, di — the number of heads Vasya and Petya got in the i-th outcome of the game, correspondingly. Print pairs of integers (ci, di) in the strictly increasing order.

Let us remind you that the pair of numbers (p1, q1) is less than the pair of numbers (p2, q2), if p1 < p2, or p1 = p2 and also q1 < q2.

input
3 2 1 1
output
3
2 1
3 1
3 2

input
2 4 2 2
output
0

题目链接:cf-242A

题目大意:Petya和Vasya玩抛硬币游戏,Vasya抛了x次,Petya抛了y次。如果该玩家赢了,则得到一分,输了双方都不得到分数。Vasya至少赢了a局,Petya至少赢了b局。赢的局数多的人最终能赢。最后的结果是Vasya赢了,问双方赢的局数的可能结果是什么?

题目思路:直接暴力就可以了。保证Vasya赢的局数大于Petya即可。

#include <vector>#include <map>#include <set>#include <algorithm>#include <iostream>#include <cstdio>#include <cmath>#include <cstdlib>#include <string>#include <cstring>using namespace std;int main(){    int x,y,a,b;    cin >> x >> y >> a >> b;    int ans = 0;    for (int i = a; i<= x; i++)    {        for(int j = b; j <= y; j++)        {            if (i > j) ans++;        }    }    cout << ans << endl;    for (int i = a; i<= x; i++)    {        for(int j = b; j <= y; j++)        {            if (i > j)            {                cout << i << " " << j << endl;            }        }    }       return 0;}
0 0