Friday, 10 April 2015

Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a plane beautiful if it meets the following conditions:
  1. The coordinates of each point in the set are integers.
  2. For any two points from the set, the distance between them is a non-integer.
Consider all points (x, y) which satisfy the inequations: 0 ≤ x ≤ n0 ≤ y ≤ mx + y > 0. Choose their subset of maximum size such that it is also a beautiful set of points.
Input
The single line contains two space-separated integers n and m (1 ≤ n, m ≤ 100).
Output
In the first line print a single integer — the size k of the found beautiful set. In each of the next k lines print a pair of space-separated integers — the x- and y- coordinates, respectively, of a point from the set.
If there are several optimal solutions, you may print any of them.
Sample test(s)
input
2 2
output
3
0 1
1 2
2 0
input
4 3
output
4
0 3
2 1
3 0
4 2
Note
Consider the first sample. The distance between points (0, 1) and (1, 2) equals , between (0, 1) and (2, 0) — , between (1, 2) and (2, 0) — . Thus, these points form a beautiful set. You cannot form a beautiful set with more than three points out of the given points. Note that this is not the only solution.


##########################editorial###################################
 note that maximum points we can form in min ( n,m) +1 ;  
let say m is minimum than n than we can fix 2nd coardinate 0 to m , if we repeat 2nd coardinate 
than it certenly form integral distane with ans privious point so maximum m+1 points possible .
ex-----
let say n=3 m=2;
so 2nd coardinate can vary from 0 to 2 ie 0,1,2  if we repeat any 2nd coardinate than it certenply form integral distance with any exiting point having same 2nd coardinate since d=sqrt((n1-n2)^2+(m1-m2)^2))  ..if m1=m2 than abs(n1-n2) which is integer ...
hence max point =min(n,m)+1;
and pair of point are like
 0,max(n,m)
1,max(n,m)-1;
2,max(n,m)-2;
3,max(n,m)-3;
4,max(n,m)-4;
''''''''''''''''''''
than only possible '
#############################code#################
#include<iostream>
using namespace std;
int main()
 {
  int n,m;
   cin>>n>>m;
   if(n==0 && m==0)
    {
    cout<<"0"<<endl;
    return 0;
    }
   int ans=min(n,m);
    cout<<ans+1<<endl;
    if(ans==0)
     {
      if(n>0) cout<<"1 0 "<<endl;
      else
      cout<<"0 1"<<endl;
      return 0;
     }
      
       
    for(int i=0;i<=ans;i++)
     cout<<i<<" "<<ans-i<<endl;
     return 0;
 }



No comments:

Post a Comment