hdu 4627 The Unsolvable Problem

本文提供了一种解决HDU 4627问题的有效方法,通过分类讨论并给出简洁的代码实现,针对特定输入值进行处理以获得最大乘积。

http://acm.hdu.edu.cn/showproblem.php?pid=4627

分类讨论一下就可以

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<set>
using namespace std;

typedef long long ll;
typedef pair<double,double>ppd;
const double PI = acos(-1.);
const double eps = (1e-9);
const int N=2005;
const int M=2000000;
const int K=27;

int main()
{
    //freopen("data.in","r",stdin);
    int T;
    scanf("%d",&T);
    while(T--)
    {
       ll n;
       cin>>n;
       if(n==2)
       {cout<<"1"<<endl;continue;}
       ll a=n/2;
       ll b=n-a;
       if(a!=b)
       {cout<<(a*b)<<endl;continue;}
       if((a&1)==0)
       {cout<<(a-1)*(a+1)<<endl;continue;}
       cout<<(a-2)*(a+2)<<endl;
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/liulangye/p/3227935.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值