Codeforces Round #506 (Div. 3) 1029 F. Multicolored Markers
生活随笔
收集整理的這篇文章主要介紹了
Codeforces Round #506 (Div. 3) 1029 F. Multicolored Markers
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
CF-1029F
題意:
a,b個小正方形構造一個矩形,大小為(a+b),并且要求其中要么a個小正方形是矩形,要么b個小正方形是矩形。
思路:
之前在想要分a,b是否為奇數(shù)討論,后來發(fā)現(xiàn)根本不需要。只用枚舉(a+b)大小的矩形的邊長,并暴力判斷(注意暴力判斷的順序)能否成立,更新答案。
#include <algorithm> #include <iterator> #include <iostream> #include <cstring> #include <iomanip> #include <cstdlib> #include <cstdio> #include <string> #include <vector> #include <bitset> #include <cctype> #include <queue> #include <cmath> #include <list> #include <map> #include <set> //#include <unordered_map> //#include <unordered_set> //#include<ext/pb_ds/assoc_container.hpp> //#include<ext/pb_ds/hash_policy.hpp> using namespace std; //#pragma GCC optimize(3) //#pragma comment(linker, "/STACK:102400000,102400000") //c++ #define lson (l , mid , rt << 1) #define rson (mid + 1 , r , rt << 1 | 1) #define debug(x) cerr << #x << " = " << x << "\n"; #define pb push_back #define pq priority_queuetypedef long long ll; typedef unsigned long long ull;typedef pair<ll ,ll > pll; typedef pair<int ,int > pii; typedef pair<int ,pii> p3; //priority_queue<int> q;//這是一個大根堆q //priority_queue<int,vector<int>,greater<int> >q;//這是一個小根堆q //__gnu_pbds::cc_hash_table<int,int>ret[11]; //這是很快的hash_map #define fi first #define se second //#define endl '\n'#define OKC ios::sync_with_stdio(false);cin.tie(0) #define FT(A,B,C) for(int A=B;A <= C;++A) //用來壓行 #define REP(i , j , k) for(int i = j ; i < k ; ++i) //priority_queue<int ,vector<int>, greater<int> >que;const ll mos = 0x7FFFFFFFLL; //2147483647 const ll nmos = 0x80000000LL; //-2147483648 const int inf = 0x3f3f3f3f; const ll inff = 0x3f3f3f3f3f3f3f3fLL; //18const double PI=acos(-1.0);template<typename T> inline T read(T&x){x=0;int f=0;char ch=getchar();while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();return x=f?-x:x; }/*-----------------------showtime----------------------*/ll a,b, sum;bool check(ll x,ll y){for(ll i=x; i>=1; i--){if(a%i == 0 && a/i <= y)return true;if(b%i == 0 && b/i <= y)return true; } return false;}int main(){cin>>a>>b;sum = a + b;ll ans = inff;for(ll i=1ll; i * i <= sum; i++){if(sum % i == 0){ll x = i, y = sum/i;if(check(x,y)){ans = min(ans, 2ll*(x + y));}}}cout<<ans<<endl;return 0; } CF-1029F?
轉載于:https://www.cnblogs.com/ckxkexing/p/9540502.html
總結
以上是生活随笔為你收集整理的Codeforces Round #506 (Div. 3) 1029 F. Multicolored Markers的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: tp5.0初入
- 下一篇: 如何从svn上down项目