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> # ...
随机推荐
- Servlet和JSP之标签文件学习
在上一篇文章中介绍了自定义标签的用法,接下来介绍标签文件的用法啦. tag file指令 tag file简介 用tag file的方式,无需编写标签处理类和标签库描述文件,也可以自定义标签.tag ...
- 转载自infoq:MYSQL的集群方案
分布式MySQL集群方案的探索与思考 2016-04-29 张成远 “本文整理自ArchSummit微信大讲堂张成远线上群分享内容 背景 数据库作为一个非常基础的系统,任何一家互联网公司都会 ...
- jni ndk 入门
1. Linux环境模拟,下载sygwin 安装,选择devl 和shell -> install sygwin 中的配置ndk环境,进入安装目录c:/cygwin64 etc/profile文 ...
- ucosii(2.89)semaphore 应用要点
semaphore 的作用:1,允许一个任务与其他任务(中断)同步.2,取得共享资源使用权.3,标志事件的发生.
- python matplotlib 可视化操作实例
具体代码: # encoding: utf-8 # coding = utf-8 import sys reload(sys) sys.setdefaultencoding('utf8') from ...
- Linux系统GEDIT编译运行C++
作为NOIP第一年强制使用Linux系统的考生,真的很难受,被迫还要学一波Linux系统. 正常的Windows对于较基础的程序员来说非常方便好用,但是对于高级程序员来说就是一个坑,于是就有了Linu ...
- cookies,sessionStorage和localStorage的相同点和不同点?
相同点:都存储在客户端. 不同点: 1.存储大小: cookies数据大小不能超过4k sessionStorage和localStorage虽然也有存储大小的限制,但比cookies大得多,可以达到 ...
- emoji等表情符号存mysql的方法
项目中需要存储用户信息(用户昵称有表情符号),自然就遇到了emoji等表情符号如何被mysql DB支持的问题 这里引用先行者博文:https://segmentfault.com/a/1190000 ...
- curl学习笔记(以php为例)
一.demo,抓取百度页码代码: $url = 'https://www.baidu.com/'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RE ...
- LeetCode(112) Path Sum
题目 Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up ...