Thứ Hai, 12 tháng 11, 2012

Problem Heads or Tails

Link: http://codeforces.com/problemset/problem/242/A

A. Heads or Tails
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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 cidi — 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.
Sample test(s)
input
3 2 1 1
output
3
2 1
3 1
3 2
input
2 4 2 2
output
0

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<vector>
#include<utility>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
#include<cmath>

using namespace std;

vector<int> V;
map<int,int> M;
int res = -1; 
set<int> S;
int x,y,a,b;



struct node
{
    int x,y;
    node(){}
    node(int x,int y):x(x),y(y){}   
};
bool operator < (const node &n1, const node &n2)
{
    return ((n1.x != n2.x) ? n1.x < n2.x :  n1.y < n2.y);  
}

node N[100000];

int main()
{
    /*
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    */
    cin >> x >> y >> a >> b;
    
    for(int i=b;i<=y;i++)
    {
        for(int j = (i+1>=a?i+1:a);j<=x;j++)
        {
            res++;
            N[res] = node(j,i);
        }   
    }
    sort(N,N+res+1);
    //int res = (int)M.size();
    //if(res== -1)
    //  cout << 0 << endl;
    //else
    //{
    printf("%d\n",res+1);
    /*
    map<int,int>::iterator it;
    for(it = M.begin();it!=M.end(); it++)
        printf("%d %d\n",(*it).first,(*it).second);
    */
    for(int i=0;i <= res; i++)
        printf("%d %d\n",N[i].x,N[i].y);    
    //}
    return 0;
}






Không có nhận xét nào:

Đăng nhận xét