CodeForces 303B Rectangle Puzzle II
题意:
给定一个靠着坐标轴长为n,宽为m的矩形和 矩形中的一个点A,求在这个矩形内部一个
长宽比为a/b的小矩形,使这个小矩形的长宽尽量大使点A在小矩形内部,并且点A尽量靠近小矩形的中心
CF的思维题确实牛,让点A尽量靠近小矩形的中心其实是比较障眼法的,让你觉得这个问题又需要考虑
小矩形最大又需要考虑点A的问题,然是考虑这样一个问题,小矩形的大小和点A在小矩形内部,两个问题是否矛盾。
这是解决问题的关键,所以这不仅是思维的难度,也是心理的考验,在思考这个问题之初就默认这两个问题是矛盾的,
为之后的思考就变成了同时考虑两个因素,让问题变难了,所以要细分这个问题,矩形的大小和包括点在其中是不矛盾的!
任何一个小矩形都可以使这个点在包含在其中,所以先直接求这个小矩形的长宽最大值(答案的优先条件),从这个角度题目有一定
的提示,然后接下来的问题就是让这个点尽量的靠近小矩形的中心,这可以O(1)的复杂度办到,直接从点的坐标入手,如果可以直接让其分别在长宽的中点,
如果不能,那就需要一半短一点,另一半长一点,调整一下即可,注意当长度为偶数和奇数时需要分类讨论一下。
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <stack>
#include <set>
#include <map>
#include <math.h>
#define pb push_back
#define CLR(a) memset(a, 0, sizeof(a));
#define MEM(a, b) memset(a, b, sizeof(a));
#define fi first
#define se second using namespace std; typedef long long ll; const int MAXN = ;
const int MAXV = ;
const int MAXE = ;
const int INF = 0x3f3f3f3f; int n, m, x, y, a, b;
int gcd(int x, int y)
{
if (y == ) return x;
return gcd(y, x%y);
}
int main()
{
//freopen("in.txt", "r", stdin);
int len, wid;
int pw;
int up, down, left, right;
while (~scanf("%d%d%d%d%d%d", &n, &m, &x, &y, &a, &b))
{
int GCD = gcd(a, b);
a = a/GCD;
b = b/GCD;
pw = min(n/a, m/b);
len = pw*a;
wid = pw*b;
int d;
int half1 = wid / , half2 = (wid & ) ? half1+ : half1;
if (m - y >= half1 && y >= half2)
{
up = y+half1;
down = y-half2;
}
else if (m - y < half1)
{
up = m;
down = m-half1-half2;
}
else if (y < half2)
{
down = ;
up = half1 + half2;
}
half1 = len/;
half2 = (len & ) ? half1+ : half1;
if (n-x >= half1 && x >= half2)
{
left = x - half2;
right = x + half1;
}
else if (n-x < half1)
{
right = n;
left = n-half1-half2;
}
else if (x < half2)
{
left = ;
right = half1+half2;
}
cout << left << " " << down << " " << right << " " << up << endl;
}
return ;
}
CodeForces 303B Rectangle Puzzle II的更多相关文章
- Codeforces Round #172 (Div. 2) C. Rectangle Puzzle 数学题几何
C. Rectangle Puzzle Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/281/p ...
- Rectangle Puzzle CodeForces - 281C (几何)
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of ...
- [Swift]LeetCode850. 矩形面积 II | Rectangle Area II
We are given a list of (axis-aligned) rectangles. Each rectangle[i] = [x1, y1, x2, y2] , where (x1, ...
- Codeforces Gym101257F:Islands II(求割点+思维)
http://codeforces.com/gym/101257/problem/F 题意:给出一个n*m的地图,上面相同数字的代表一个国家,问对于每个国家有多少个国家在它内部(即被包围).例如第一个 ...
- CodeForces 346C Number Transformation II
Number Transformation II 题解: 对于操作2来说, a - a % x[i] 就会到左边离a最近的x[i]的倍数. 也就是说 [ k * x[i] + 1, (k+1)* x ...
- [LeetCode] 850. Rectangle Area II 矩形面积之二
We are given a list of (axis-aligned) rectangles. Each rectangle[i] = [x1, y1, x2, y2] , where (x1, ...
- Codeforces - 1198D - Rectangle Painting 1 - dp
https://codeforces.com/contest/1198/problem/D 原来是dp的思路,而且是每次切成两半向下递归.好像在哪里见过类似的,貌似是紫书的样子. 再想想好像就很显然的 ...
- codeforces B. Island Puzzle
B. Island Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces 346C Number Transformation II 构造
题目链接:点击打开链接 = = 990+ms卡过 #include<stdio.h> #include<iostream> #include<string.h> # ...
随机推荐
- Linux下文件以及文件名编码转换
1.查看文件编码方式--file 文件名(但不是很准确) yang@mint-linux ~ $ file baidu.html baidu.html: HTML document, UTF-8 Un ...
- jni log 使用
1. 在源文件中添加头文件 #include <android/log.h> #define LOG_TAG "System.out.c" #define LOGD(. ...
- Linux系统分区 进程管理 软件包安装
对于一块新的磁盘来说,系统能够使用需要有分区.格式化文件系统.挂载等主要操作,下面通过命令的方式对一块磁盘进行操作. 一. Linux系统分区 1.1 在虚拟机开机前选择虚拟机配置,添加一个新的SCS ...
- win7上安装虚拟机并上网
一.安装Workstation Pro 二.下载CentOS-7-x86_64-DVD-1511.iso包 三.创建新的虚拟机,按照向导安装即可 四.使用cd /etc/sysconfig/netwo ...
- a标签目标链接问题
1.先确定开始文件和目标文件,例如从css.html开始到body.html 2.确定文件寻找路径,因为css.html的父目录是css,而body.html在body目录下,所以需要先退到上一目录h ...
- struts2基于注解的action
使用注解来配置Action的最大好处就是可以实现零配置,但是事务都是有利有弊的,使用方便,维护起来就没那么方便了. 要使用注解方式,我们必须添加一个额外包:struts2-convention-plu ...
- nib、xib、storyboard(故事板)
nib:NeXT Interface Builder的缩写 xib:XML nib的缩写 相同点: nib和xib都是Interface Builder的图形界面设计文档.Interface Buil ...
- SVN的使用二
一,打开SCM 在xcode中,点击菜单: File -> Source Control –> Repositories 二,连接SVN服务器 1, 2,配置SVN服务器地址(http:/ ...
- C++系统学习之八:IO库
新的C++标准中有三分之二的内容都是描述标准库.接下来重点学习其中几种核心库设施,这些是应该熟练掌握的. 标准库的核心是很多容器类(顺序容器和关联容器等)和一簇泛型算法(该类算法通常在顺序容器一定范围 ...
- DocDokuPLM 2.5安装
安装记录:(大部分是环境安装和配置) 未完待续.