题意:

给定一个靠着坐标轴长为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的更多相关文章

  1. 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 ...

  2. Rectangle Puzzle CodeForces - 281C (几何)

    You are given two rectangles on a plane. The centers of both rectangles are located in the origin of ...

  3. [Swift]LeetCode850. 矩形面积 II | Rectangle Area II

    We are given a list of (axis-aligned) rectangles.  Each rectangle[i] = [x1, y1, x2, y2] , where (x1, ...

  4. Codeforces Gym101257F:Islands II(求割点+思维)

    http://codeforces.com/gym/101257/problem/F 题意:给出一个n*m的地图,上面相同数字的代表一个国家,问对于每个国家有多少个国家在它内部(即被包围).例如第一个 ...

  5. CodeForces 346C Number Transformation II

    Number Transformation II 题解: 对于操作2来说, a - a % x[i] 就会到左边离a最近的x[i]的倍数. 也就是说 [ k * x[i] + 1,  (k+1)* x ...

  6. [LeetCode] 850. Rectangle Area II 矩形面积之二

    We are given a list of (axis-aligned) rectangles.  Each rectangle[i] = [x1, y1, x2, y2] , where (x1, ...

  7. Codeforces - 1198D - Rectangle Painting 1 - dp

    https://codeforces.com/contest/1198/problem/D 原来是dp的思路,而且是每次切成两半向下递归.好像在哪里见过类似的,貌似是紫书的样子. 再想想好像就很显然的 ...

  8. codeforces B. Island Puzzle

    B. Island Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  9. Codeforces 346C Number Transformation II 构造

    题目链接:点击打开链接 = = 990+ms卡过 #include<stdio.h> #include<iostream> #include<string.h> # ...

随机推荐

  1. sublime text 3中emmet常用技巧

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 程序windows上可以上传附件,部署到 linux服务器后出现 “上传目录 不可写” 怎么解决?

    这样的问题一般都是linux  下文件读写权限引起的,用 shell  命名到上传附件的目录(如 cd /data/www/project/upload/),然后执行 shell 文件权限设置: 例如 ...

  3. js 前端不调接口直接下载图片

    // 下载图片 downPhoto (path) { this.downloadFiles(path) }, // 下载 downloadFiles (content) { console.log(c ...

  4. dfs染色法判定二分图

    #include<iostream> #include<cstring> using namespace std; ][],color[],n; int dfs(int x,i ...

  5. C++ C++ 值传递、指针传递、引用传递详解

    这一篇博客写的不错: https://www.cnblogs.com/dingxiaoqiang/p/8012578.html

  6. HTTP协议详解-基础知识

    HTTP是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒体信息系统.绝大多数的Web开发,都是构建在HTTP协议之上的Web应用. HTTP协议的主要特点可概括如下: 简单: ...

  7. PAT (Basic Level) Practise (中文)-1025. 反转链表 (25)

    PAT (Basic Level) Practise (中文)-1025. 反转链表 (25)   http://www.patest.cn/contests/pat-b-practise/1025 ...

  8. bootstrap 两端对齐的导航

    您可以在屏幕宽度大于768px时,通过在分别使用.nav .nav-tabs或.nav .nav-pills的同时使用class.nav-justified,让标签式或胶囊式导航菜单与父元素等宽,在更 ...

  9. 【单调栈 动态规划】bzoj1057: [ZJOI2007]棋盘制作

    好像还有个名字叫做“极大化”? Description 国际象棋是世界上最古老的博弈游戏之一,和中国的围棋.象棋以及日本的将棋同享盛名.据说国际象棋起源 于易经的思想,棋盘是一个8*8大小的黑白相间的 ...

  10. (19)zabbix Applications使用介绍

    介绍 Applications(我们翻译为应用程序)是item的一个组. 例如我们要监控MySQL,我们可以将所有和MySQL相关的item放到这个应用程序中. 例如MySQL的availabilit ...