Codeforces 268C Beautiful Sets of Points【思维】

来源:互联网 发布:xampp ubuntu安装 编辑:程序博客网 时间:2024/05/22 06:28

C. Beautiful Sets of Points
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Manao has invented a new mathematical term — a beautiful set of points. He calls a set of points on a planebeautiful 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 ≤ n; 0 ≤ y ≤ m; x + 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 andm (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 nextk lines print a pair of space-separated integers — thex- and y- coordinates, respectively, of a point from the set.

If there are several optimal solutions, you may print any of them.

Examples
Input
2 2
Output
30 11 22 0
Input
4 3
Output
40 32 13 04 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.


题目大意:

让你在(0<=x<=n)(0<=y<=m)&&x+y>0的坐标范围中,找到最多的点组成一个集合,使得其坐标都是整数,并且集合中任意两个点的距离都不是整数。


思路:


1、首先确定这样一个问题,如果两个点的横坐标或者是纵坐标相同,那么两点间距离一定是整数,那么我们能够确定,对应范围内的点的个数一定是min(n,m)+1;


2、那么我们考虑分配min(n,m)+1个点的坐标,这时候我们考虑极限,因为一个正方形的对角线的距离一定不是整数,那么我们考虑将这些点都放在以min(n,m)为边长的正方形的对角线上。因为题目要求x+y>0,那么我们将所有点都放在从左上到右下的这条对角线上即可。


Ac代码:


#include<stdio.h>#include<string.h>#include<iostream>#include<math.h>using namespace std;int main(){    int n,m;    while(~scanf("%d%d",&n,&m))    {        int tmp=min(n,m);        printf("%d\n",tmp+1);        for(int i=0;i<tmp+1;i++)        {            printf("%d %d\n",i,tmp-i);        }    }}




0 0
原创粉丝点击