hdu 4655 Cut Pieces(想法题)
Cut Pieces
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 728 Accepted Submission(s): 303
This is not your task. Your task is to permute the blocks (together with its corresponding ai) so that S is maximized.
Sum of all n <= 106. All numbers in the input are positive integers no larger than 109.
3
1 2 3
Both sequence 1 3 2 and sequence 2 3 1 result in an S of 14.
对于一个序列:a,b,c,d,e,f....
设sum=a*b*c*d*....;
对于a,b,当a与b不同的时候可以增加(ab-min(a,b))*(sum/ab)=(s-s/max(a,b));
max(a,b)越大,增加的也就越大!所以当然让大的数多取,
比如:n=7的时候
对于序列1 2 3 4 5 6 7
我可以排列成
1 5 2 6 3 7 4;
这样我就使得最大的三个数(5,6,7)都取了两次,从而答案是最优的!!!
n=6的时候
对于序列1 2 3 4 5 6
可以排列成
1 5 2 6 3
还有个4就只能放边上了!!!
即5,6都取了两次,而4只能取1次啦!!!
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<iostream>
#define MAX 1000010
#define mod 1000000007
using namespace std;
typedef long long ll; int ext_gcd(int a,int b,int &x,int &y)
{
if(b==){x=;y=;return a;}
int d=ext_gcd(b,a%b,x,y),t;
t=x;x=y;y=t-a/b*y;
return d;
}
int inv(int a,int mo)
{
int x,y,dx,g;
g=ext_gcd(a,mo,x,y);
dx=mo/g;
return (x%dx+dx)%dx;
} int a[];
int main()
{
int head,tail,T,i,n,jnm;
ll ji,ans;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
ji=;
for(i=;i<=n;i++)
{
scanf("%d",&a[i]);
ji*=a[i];
ji%=mod;
}
sort(a+,a+n+);
ans=ji;
head=n-n/+;
tail=n;
if(n&)//区分奇偶的区别!!!!
ans=((ans+*(ji-ji*inv(a[head-],mod)%mod))%mod+mod)%mod;
else
ans=((ans+*(ji-ji*inv(a[head-],mod)%mod))%mod+mod)%mod;
for(i=head;i<=tail;i++)
ans=((ans+*(ji-ji*inv(a[i],mod)%mod))%mod+mod)%mod;
if(n==)ans=a[];
printf("%lld\n",ans);
}
return ;
}
hdu 4655 Cut Pieces(想法题)的更多相关文章
- HDU 4655 Cut Pieces(2013多校6 1001题 简单数学题)
Cut Pieces Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total ...
- HDU 4655 Cut Pieces(数学分析题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4655 题意:给出n个石子,第i个石子可以染ai种颜色.对于每种颜色,比如颜色1221,我们称有3段.连 ...
- hdu 4655 Cut Pieces 找规律
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4655 题意:给你一组整数,代表每个木块所能涂成的颜色种数(编号1~ai),相邻的两块所能涂成的颜色如果是一 ...
- hdu 4655 Cut Pieces
这个解题报告讲的很详细了!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #in ...
- HDU 4655 Cut Pieces 找规律+简单计数
解法参考:http://blog.csdn.net/a601025382s/article/details/9840125 #include <cstdio> #include <c ...
- HDU - 5806 NanoApe Loves Sequence Ⅱ 想法题
http://acm.hdu.edu.cn/showproblem.php?pid=5806 题意:给你一个n元素序列,求第k大的数大于等于m的子序列的个数. 题解:题目要求很奇怪,很多头绪但写不出, ...
- HDU 4972 Bisharp and Charizard 想法题
Bisharp and Charizard Time Limit: 1 Sec Memory Limit: 256 MB Description Dragon is watching NBA. He ...
- CodeForces 111B - Petya and Divisors 统计..想法题
找每个数的约数(暴力就够了...1~x^0.5)....看这约数的倍数最后是哪个数...若距离大于了y..统计++...然后将这个约数的最后倍数赋值为当前位置...好叼的想法题.... Program ...
- HDU 4762 Cut the Cake (2013长春网络赛1004题,公式题)
Cut the Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
随机推荐
- 基于BootStrap的分页代码实现
public class PageUtil { //targetUrl 访问url totalNum总记录数 currentPage 当前页数 pageSize每页的大小 public static ...
- ThreadLocal在Spring事务管理中的应用
ThreadLocal是用来处理多线程并发问题的一种解决方案.ThreadLocal是的作用是提供线程的局部变量,在多线程并发环境下,提供了与其他线程隔离的局部变量.通常这样的设计的情况是因为这个局部 ...
- animate(动画)框架 和 swiper (轮播)框架 的使用
swiper.js 框架 网址:https://www.swiper.com.cn/ 是一个专门做轮播,切换特效的轮播 使用方法: 然后进入案例,通过案例来进行各种功能的实现, 这一步是教我们怎么做, ...
- leetcode-mid-array-31 three sum-NO
my code: time limited def threeSum(nums): """ :type nums: List[int] :rtype: List[L ...
- codeforces 668C - Little Artem and Random Variable
题目链接:http://codeforces.com/contest/668/problem/C --------------------------------------------------- ...
- weight(搜索对象的选取)
题目链接: 就是大概这么个东西 根据题意,我们可以清楚的知道:这个题我不会,这个题需要先将2n个数进行排序 这样每对于一个小的前(后)缀和总会在队列最前或队列最后 设这个数为k 那么判断总的Sum(n ...
- 三十四、python中shutil模块的介绍
'''A.shutil:高级的文件 文件夹 压缩包 处理模块''' import shutil '''1.copyfileobj(a1,a2,lenth):将文件内容拷贝到另一个文件中''' shut ...
- EntityFrameworkCore.MySql
1.点击“工具”->“NuGet包管理器”->“程序包管理器控制台” 分别安装以下几个包 Mysql 版本: Install-Package MySql.Data.EntityFramew ...
- Parcel在binder通信readStrongBinder和writeStrongBinder
Binder IPC通信中,Binder是通信的媒介,Parcel是通信的內容.远程调用过程中,其参数都被打包成Parcel的形式来传递. 在IPC通信的Proxy端,我们经常可以看到下面类似的代码, ...
- PHP超时提示Fatal error: Maximum execution time of 30,解决方案
PHP执行超时提示如下:Fatal error: Maximum execution time of 30 seconds exceeded in D:\php\AppServ\www\sum3\te ...