Codeforces 268C Beautiful Sets of Points【思维】
来源:互联网 发布:xampp ubuntu安装 编辑:程序博客网 时间:2024/05/22 06:28
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:
- The coordinates of each point in the set are integers.
- 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.
The single line contains two space-separated integers n andm (1 ≤ n, m ≤ 100).
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.
2 2
30 11 22 0
4 3
40 32 13 04 2
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); } }}
- Codeforces 268C Beautiful Sets of Points【思维】
- Codeforces #164 C. Beautiful Sets of Points ( 思维
- Codeforces Round #164 (Div. 2) C. Beautiful Sets of Points【思维题】
- C. Beautiful Sets of Points
- CF268C. Beautiful Sets of Points
- Codeforces #24 C. Sequence of points
- CodeForces 24C Sequence of points (几何)
- Codeforces 466C Number of Ways【思维】
- Codeforces--486D-----Valid Sets思维
- Codeforces 651B Beautiful Paintings【思维】
- 思维 CodeForces - 651B Beautiful Paintings
- Codeforces Round #432 (Div. 2) C 850A Five Dimensional Points(思维)
- codeforces 593 C. Beautiful Function
- C. Vasya and Beautiful Arrays----思维题
- Codeforces Round #230 (Div. 2) C. Blocked Points D. Tower of Hanoi
- Codeforces Round #230 (Div. 2) C. Blocked Points D. Tower of Hanoi
- Codeforces 469D Two Sets【思维+并查集】
- Codeforces 268B Two Sets
- 获取easyui-datagrid中选中的数据,并遍历得到目标数据
- PyCharm2016.2专业版注册码
- Python基础学习--第四篇(条件判断和循环)
- 某处有某物
- 搞懂JAVA集合类--HashTable, LinkedHashMap, TreeMap(四)
- Codeforces 268C Beautiful Sets of Points【思维】
- Android广播接收 BroadcastReceiver监听系统全局的Broadcast消息
- python @staticmethod @classmethod 区别
- 蓝牙开发板相关
- 微信小程序例子——获取手机系统信息
- 最小栈实现
- windows下qt4.8安装
- 微信小程序例子——获取用户登录信息
- 微信小程序例子——使用微信小程序拨打电话