2016 ICPC大连赛区 hdu5976 Detachment

本文探讨了一道关于如何将线段划分成不同长度的小线段以构建多维空间的问题,目的是最大化空间尺寸的同时满足特定条件。介绍了问题背景、输入输出格式及样例,并给出了解题思路与代码实现。


Detachment

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 437    Accepted Submission(s): 144


Problem Description
In a highly developed alien society, the habitats are almost infinite dimensional space.
In the history of this planet,there is an old puzzle.
You have a line segment with x units’ length representing one dimension.The line segment can be split into a number of small line segments:  a1,a2 , … (x=  a1+a2 +…) assigned to different dimensions. And then, the multidimensional space has been established. Now there are two requirements for this space: 
1.Two different small line segments cannot be equal (  aiaj  when i≠j).
2.Make this multidimensional space size s as large as possible (s=  a1a2 *...).Note that it allows to keep one dimension.That's to say, the number of ai can be only one.
Now can you solve this question and find the maximum size of the space?(For the final number is too large,your answer will be modulo 10^9+7)
 

Input
The first line is an integer T,meaning the number of test cases.
Then T lines follow. Each line contains one integer x.
1≤T≤10^6, 1≤x≤10^9
 

Output
Maximum s you can get modulo 10^9+7. Note that we wants to be greatest product before modulo 10^9+7.
 

Sample Input
  
1 4
 

Sample Output
  
4
 

Source
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:   5981  5977  5975  5973  5972 
题意:给你一个x,你可以任意分成n段,但每一段的长度不一样,求a1*a2...*an的最大值。

思路:从1开始枚举你会发现,拆得越小是越划算的(1除外,1*任何数为1),所以把x尽可能拆小就能得到最大值,因此我们维护前缀和和前缀积,二分找到前缀和大于等于x的位置,那么该前缀和只要去掉其中某个值就能得到x,套个逆元就可以了,但如果去掉的值刚好是1的话,那么我们选择去掉头和尾再加上pos+1就能得到x,一样用逆元就可以了。下面给代码:

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<queue>
#include<functional>
typedef long long LL;
using namespace std;
#define maxn 45000
#define ll l,mid,now<<1
#define rr mid+1,r,now<<1|1
#define lson l1,mid,l2,r2,now<<1
#define rson mid+1,r1,l2,r2,now<<1|1
#define pi 3.14159
const int mod = 1e9 + 7;
int sum[maxn];
LL mul[maxn];
LL quitemod(LL a, LL b){
	LL ans = 1;
	a = a%mod;
	while (b){
		if (b & 1)
			ans = (ans*a) % mod;
		b >>= 1;
		a = (a*a) % mod;
	}
	return ans;
}
int main(){
	sum[1] = 0;
	mul[1] = 1;
	for (int i = 2; i<45000; i++){
		sum[i] = sum[i - 1] + i;
		mul[i] = mul[i - 1]*i;
		mul[i] %= mod;
	}
	int t;
	scanf("%d", &t);
	while (t--){
		int x;
		scanf("%d", &x);
		if (x == 1){
			printf("1\n");
			continue;
		}
		int pos = lower_bound(sum, sum + 45000, x) - sum;
		LL now = sum[pos] - x;
		LL ans;
		if (now){
			if (now == 1){
				ans = mul[pos] * quitemod(pos, mod - 2) % mod*quitemod(2, mod - 2) % mod*(pos + 1) % mod;
			}
			else
				ans = mul[pos] * quitemod(now, mod - 2) % mod;
		}
		else
			ans = mul[pos];
		printf("%lld\n", ans);

	}
}


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值