哎这题有点意思。。

一开始肿么看都不理解题意,发现好多ACM题都这样,好多英文意思不能完全理解,只得照样例猜啦,猜不出来?? 那就靠神队友解释了,囧。

就是排列,涂色使结果最大化。

反正别人的博客把这题的题意解释的很清楚了,我这只小牛就把自己的拙思路稍提一下。

也许做题多了马上就能感觉出这题当 a1,an,a2,an-1这样排列顺序效果会最大化,囧。

关键是代码实现的过程也很坎坷,自己一开始以为前面的减少的部分可能会与后面减少的部分有冲突,其实不然,还是自己没深入分析,,,

那这样就用总的情况减掉会有“冲突”的情况就行了。

除法取模,根本木有。。

要不就求逆元,可实际上不用,递推一下就OK了。

还有又顺便复习了一下取模过程中可能出现的溢出情况。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
//除法取模显然有错误啊,都可能出来0了。。。
typedef __int64 LL;
LL a[1000005];
LL b[1000005];
LL sum1[1000005];
LL sum2[1000005];
LL min(LL a,LL b)
{
if(a>b) return b;
else return a;
}
const int maxn=1000000007;
int main()
{
int case_num;
scanf("%d",&case_num);
while(case_num--)
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%I64d",&a[i]);
sort(a+1,a+1+n);
int temp1=1,temp2=n;
for(int i=1;i<=n;i+=2)
b[i]=a[temp1++];
for(int i=2;i<=n;i+=2)
b[i]=a[temp2--];
sum1[0]=1;
sum1[1]=b[1];
sum2[n]=b[n];
sum2[n+1]=1;
for(int i=2;i<=n;i++)
{
sum1[i]=sum1[i-1]*b[i]%maxn;
}
for(int i=n-1;i>=1;i--)
{
sum2[i]=sum2[i+1]*b[i]%maxn;
}
long long ans=(sum1[n]%maxn)*(n%maxn)%maxn;
long long temp=0;
for(int i=2;i<=n;i++)
{
temp=(temp%maxn+(((min(b[i],b[i-1])*sum1[i-2])%maxn)*(sum2[i+1]%maxn))%maxn)%maxn;
}
ans=(ans-temp+maxn)%maxn;
printf("%lld\n",ans);
}
return 0;
}

HDU4655【题意+分析】的更多相关文章

  1. 【LeetCode题意分析&解答】43. Multiply Strings

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  2. 【LeetCode题意分析&解答】42. Trapping Rain Water

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...

  3. 【LeetCode题意分析&解答】41. First Missing Positive

    Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0]  ...

  4. 【LeetCode题意分析&解答】40. Combination Sum II

    Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...

  5. 【LeetCode题意分析&解答】39. Combination Sum

    Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...

  6. 【LeetCode题意分析&解答】38. Count and Say

    The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...

  7. 【LeetCode题意分析&解答】37. Sudoku Solver

    Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...

  8. 【LeetCode题意分析&解答】36. Valid Sudoku

    Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...

  9. 【LeetCode题意分析&解答】35. Search Insert Position

    Given a sorted array and a target value, return the index if the target is found. If not, return the ...

  10. 【LeetCode题意分析&解答】34. Search for a Range

    Given a sorted array of integers, find the starting and ending position of a given target value. You ...

随机推荐

  1. table下tbody滚动条与thead对齐的方法且每一列可以不均等

    1 前言 table下tbody滚动条与thead对齐的方法,开始在tbody的td和thead的tr>td,对每一个Item加入百分比,结果是没对齐.也尝试了用bootstrap的col-md ...

  2. dubbo作为消费者注册过程分析--????

    请支持原创: http://www.cnblogs.com/donlianli/p/3847676.html   作者当前分析的版本为2.5.x.作者在分析的时候,都是带着疑问去查看代码,debug进 ...

  3. Android 颜色透明度换算

    每次开发的时候,UI在设计图中标注的颜色都是类似于#FF0000(红色),这倒没什么,但是呢后面却标注了30%的透明度,这下抓狂了,透明度怎么计算?不用着急,不用你算,收藏我这篇文章即可. 颜色简介 ...

  4. 实现自己的Koa2

    这部分的代码在https://github.com/zhaobao1830/koa2中demo文件夹中 Koa就是基于node自带的http模块,经过封装,监听端口,实现ctx(上下文)管理,中间件管 ...

  5. 调试Windows Service

    调试Windows Service 使用一般的调试方法调试不了Windows Servers,所以参考了一些调试方法 我服务源码中使用了Timer,注意不能使用工具箱内的Timer,用System.T ...

  6. 搭建ssh框架项目(一)

    一.创建web项目 二.导入jar包 三.创建数据库(MySQL) 四.建立javaBean对象(ElecText.java),属于持久层对象(PO对象) package com.cppdy.ssh. ...

  7. Twitter开源的Heron快速安装部署教程

    什么是Heron? Twitter使用Storm实时分析海量数据已经有好几年了,并在2011年将其开源.该项目稍后开始在Apache基金会孵化,并在2015年秋天成为顶级项目.Storm以季度为发布周 ...

  8. IDA Pro的patch插件 KeyPatch

    本来这个是没什么可写的,但是安这个插件的时候真是气到爆炸,安装文档写的不明不白,几万行的代码都写了就差那么点时间写个几十字的详细说明吗? 1.下载keypatch.py放到\IDA\plugins里 ...

  9. DDD领域模型数据访问权限(九)

    权限分为:数据权限和功能权限 数据权限: 查询提供附加表达式的支持: //提供附加表达式的支持 List<TAggreateRoot> GetByCondition(Expression& ...

  10. 两个用于win7任务栏显示进度的dll

    Microsoft.WindowsAPICodePack.dll 和Microsoft.WindowsAPICodePack.Shell.dll 下载 参考:http://blog.csdn.net/ ...