哎这题有点意思。。

一开始肿么看都不理解题意,发现好多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. lnmp创建站点

    一.创建站点 1.输入命令 lnmp vhost add 输入域名 www.xxx.com 回车 回车 回车 y创建 n不创建 网站如果有目录权限 更改目录权限 chown -R www:www /h ...

  2. java多线程快速入门(十四)

    使用atomicInteger解决了原子性问题(AtomicInteger保证每次只能一个线程操作count) package com.cppdy; import java.util.concurre ...

  3. LeetCode(1):两数之和

    写在前面:基本全部参考大神“Grandyang”的博客,附上网址:http://www.cnblogs.com/grandyang/p/4130379.html 写在这里,是为了做笔记,同时加深理解, ...

  4. 有关cookie

    cookie     会话跟踪技术               <script>             /*                 cookie 全称  会话跟踪技术.     ...

  5. bootstrap之表格和按钮

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. VEMap.DeleteAllShapeLayers 方法

    来源:https://msdn.microsoft.com/zh-cn/library/bb412514.aspx <!DOCTYPE html PUBLIC "-//W3C//DTD ...

  7. Codeforces 1000F One Occurrence 主席树|| 离线+线段树

    One Occurrence 为什么我半年前这么菜呀, 这种场只A三题... 我们在主席树 || 线段树上维护每个数的右边和它一样的数在哪里, 然后就变成了区间求最大值. 注意加进去的时候要把它右边一 ...

  8. C#: 执行批处理文件(*.bat)的方法

    static void Main(string[] args) { Process proc = null; try { proc = new Process(); proc.StartInfo.Fi ...

  9. 078 Hbase中rowkey设计原则

    1.热点问题 在某一时间段,有大量的数据同时对一个region进行操作 2.原因 对rowkey的设计不合理 对rowkey的划分不合理 3.解决方式 rowkey是hbase的读写唯一标识 最大长度 ...

  10. 《Gradle权威指南》--自定义Android Gradle工程

    No1: minSdkVersion public void minSdkVersion(int minSdkVersion){ setMinSdkVersion(minSdkVersion); } ...