codeforse 466B

来源:互联网 发布:学编程用不用面面俱到 编辑:程序博客网 时间:2024/06/15 22:15

题意:给出一个值,和长宽,然后要把长  * 宽变得大于等于值,问变化后最小的值为多少,长和宽不能减小。

思路:枚举一个数,然后另一个数就是和它相乘大于等于值,然后取最小就行。时间复杂度O(sqrt(n))


#include<bits/stdc++.h>using namespace std;typedef long long ll;typedef pair<int,int> P;typedef set<int>::iterator ITER;#define fi first#define se second#define INF 0x3f3f3f3f#define clr(x,y) memset(x,y,sizeof x)const int maxn = 1e5 + 10;const int Mod = 1e9 + 7;const int N = 2;struct Matrix{Matrix(){clr(m,0);}int m[N][N];};Matrix Mul(Matrix a,Matrix b){Matrix c;for(int i = 0; i < N; i ++){for(int k = 0; k < N; k ++){if(a.m[i][k] == 0)continue;for(int j = 0; j < N; j ++)c.m[i][j] += a.m[i][k] * b.m[k][j] % Mod,c.m[i][j] %= Mod;}}return c;}ll Mul(ll a,ll b){a %= Mod;b %= Mod;ll ret = 0;while(b){if(b & 1){ret += a;if(ret > Mod)ret -= Mod;}b >>= 1;a = (a << 1) % Mod;}return ret;}Matrix pows(Matrix x,ll n){Matrix ret;for(int i = 0; i < 2; i ++)ret.m[i][i] = 1;while(n){if(n & 1)ret = Mul(ret,x);x = Mul(x,x);n >>= 1;}return ret;}ll pows(ll x,ll n){ll ret = 1;while(n){if(n & 1)ret = ret * x % Mod;x = x * x % Mod;n >>= 1;}return ret;}ll powss(ll x,ll n){ll ret = 1;while(n){if(n & 1)ret = Mul(ret,x);x = Mul(x,x);n >>= 1;}return ret;}ll gcd(ll x,ll y){return y ? gcd(y,x % y):x;}ll euler(int n){int ret = n;for(int i = 2; i * i<= n; i ++)if(n % i == 0){ret = ret / i * (i - 1);while(n % i == 0)n /= i;}if(n > 1)ret = ret / n * (n - 1);return ret;}void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d = a;x = 1;y = 0;return;}ex_gcd(b,a % b,d ,y,x);y -=a/b * x;}inline int lowbit(int x){return x &(-x);}//void update(int x,int val){for(int i = x; x < maxn; i += lowbit(i))tree[i] += val;}//void get(int x){int ret = 0;for(int i = x; i > 0 ;i -= lowbit(i))ret += tree[i];return ret;}//int finds(int x){return fa[x] == x ? x : (fa[x] = finds(fa[x]));}int main(){ll n,a,b;while(~ scanf("%I64d%I64d%I64d",&n,&a,&b)){    n = n * 6;    if(a * b >= n)        {            printf("%I64d\n%I64d %I64d\n",a * b,a,b);continue;        }        ll ans = 1e17,x1,x2;for(ll i = min(a,b); i * i <= n; i ++)        {            ll t = n / i + (n % i ? 1 : 0);            if(i >= a && t >= b && t * i < ans)            {                ans = t * i; x1 = i;x2 = t;//                cout << i << " " << t << endl;            }            if(i >= b && t >= a && t * i < ans)            {                ans = t * i; x1 = t;x2 = i;//                cout << x1 << " " << x2 <<endl;            }        }        printf("%I64d\n%I64d %I64d\n",ans,x1,x2);}return 0;}


原创粉丝点击