1029F. Multicolored Markers

题目链接:http://codeforces.com/problemset/problem/1029/F

题意:给出a块红砖,b块蓝砖,现在用这些转拼矩形,要求两种颜色形成大矩形的同时,其中至少一种颜色的砖块也要形成矩形,问:他们所形成的所有矩形中,最小周长是多少。

个人思路:现在我们总共有c = a+b块砖,而如果我们要得到最小周长C,我们就要使砖块形成的矩形尽量向正方形靠拢。在此之前我们先记录一个最小长度x=c,即可行的最大周长矩形长,我们如果对长搜索,则其范围i应是1到sqrt(a+b)取下整,同理,在其搜索过程中我们判断:a%i==0&&sqrt(a)>=i或者b%i==0&&sqrt(b)>=i,如果是的话,我们将x更新,然后再保留符合要求中的最小周长的那个就行了。

代码:

#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;

int main()
{
    ll a,b,c;
    cin>>a>>b;
    c = a+b;
    int sa = sqrt(a);
    int sb = sqrt(b);
    int sc = sqrt(c);
    ll x = c,C = 0;
    for(int i = 1; i <= sc; i++)
    {
        if(a%i==0&&sa>=i)x = min(x,a/i);
        if(b%i==0&&sb>=i)x = min(x,b/i);
        if(c%i==0)
        {
            ll j = c/i;
            if(j>=x)C = 2*(i+j);
        }
    }
    cout<<C;
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Sure, I'd be happy to help you plan your trip to Guilin! Here are some tips to make the most out of your 3-day vacation. Day 1: - Start the day early and hike up to the top of the iconic Elephant Trunk Hill. Take in the stunning views of the Li River and the city below. - Next, head over to the Seven Star Park. This beautiful park boasts limestone caves, lush gardens and the Seven Star Cave, which is a must-visit attraction. - Head to the Reed Flute Cave to witness the beautiful natural limestone formations and the dazzling multicolored lights. - End your day with a leisurely stroll around the picturesque Ronghu Lake to soak up the tranquil atmosphere and enjoy the local delicacies. Day 2: - Begin your day by exploring the historic Fubo Hill, a gorgeous hill with a rich cultural and historical significance. - Visit the Guilin Art Museum to appreciate the stunning calligraphy and art exhibitions. - Next up, take a relaxing bamboo raft ride down the Li River and enjoy the breathtaking scenic views. - Head over to the Xiangshan Scenic Area to watch the sunset over the beautiful karst peaks and the stunning skyline of Guilin. Day 3: - Start your day by exploring the spectacular Longji Rice Terraces, located about 2 hours away from Guilin. Take in the panoramic views and marvel at the beautiful rice terraces. - Next, head to the ancient town of Xingping. This charming town is located on the banks of the Li River and is a great place to get a glimpse of traditional Chinese architecture and cultural heritage. - End your day with a visit to the picturesque Yanjiang Road, a pedestrian street filled with local souvenirs, street food, and boutiques. As for your request on what I said earlier, I happen to know a great joke! Why did the tomato turn red? Because it saw the salad dressing! ;)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值