HDU4655【题意+分析】
哎这题有点意思。。
一开始肿么看都不理解题意,发现好多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【题意+分析】的更多相关文章
- 【LeetCode题意分析&解答】43. Multiply Strings
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...
- 【LeetCode题意分析&解答】42. Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...
- 【LeetCode题意分析&解答】41. First Missing Positive
Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0] ...
- 【LeetCode题意分析&解答】40. Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...
- 【LeetCode题意分析&解答】39. Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...
- 【LeetCode题意分析&解答】38. Count and Say
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...
- 【LeetCode题意分析&解答】37. Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...
- 【LeetCode题意分析&解答】36. Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...
- 【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 ...
- 【LeetCode题意分析&解答】34. Search for a Range
Given a sorted array of integers, find the starting and ending position of a given target value. You ...
随机推荐
- 使用RMS API 自定义Office(Word、Excel、PPT)加密策略
什么是RMS: Microsoft Windows Rights Management 服务 (RMS),是一种与应用程序协作来保护数字内容(不论其何去何从)的安全技术,专为那些需要保护敏感的 Web ...
- Python-JS (JS介绍~JS的基础数据类型)
目录一.JS语言介绍: 1.JS概念 2.JS组成 二.JS的三种存在位置(引入方式): 1.行间式: 2.内联式: 3.外联式: 三.JS出现的具体位置: 四.JS语法规范 五.JS中变量的定义 E ...
- Python-CSS 基础
css入门 一.架构分析 页面 => div的层级结构 => 具有采用哪些功能标签显示内容 结构层 > 位置层(布局层) > 内容层 二.css引入 - 行间式 <div ...
- IntelliJ IDEA配置Tomcat 与安装Tomcat失败原因
1.jdk中jre损坏,无法提供运行环境:重新下载jre安装并配置
- OneNET麒麟座应用开发之八:采集大气压力等环境参数
采集大气压力和温度也是核算大气标准状况下的各种数据的必须参数,为此我们必须知道压力和温度才能计算标准状况下的各种参数,于此我们需要一个既能检测压力也能检测温度的元件. 1.硬件概述 MS5837压力传 ...
- jQuery Ajax实例各种使用方法详解
在jquery中ajax实现方法分类很多种,如有:load.jQuery.get.jQuery.post.jQuery.getScript.jQuery Ajax 事件.jQuery.ajaxSetu ...
- OI中坑点总结
以下是我个人OI生涯中遇到的坑点的一个小总结,可能是我太菜了,总是掉坑里,请大佬勿喷 1,多重背包的转移的循环顺序 //默认每个物品体积为一(不想打码……) //dp[i]表示占用背包容量i所能获得的 ...
- tyvj1051 选课
/* 分组背包+树形dp:以树的深度作为阶段,以节点编号作为一维状态, 思路:首先dp[u][t]表示选择以第u门课为根,选了t门课的最大值, 状态转移方程dp[u][t]=max(所有儿子中凑出t- ...
- Python 3 官方文档学习(1)
本文系官方文档翻译之作,不当之处,敬请原谅! range()函数 如果需要遍历一个数字序列,可以使用内置的range函数.该函数会生成等差序列. 1 2 3 range(5)# 范围[0, 5) ra ...
- SQLite Manager插件安装与使用(firefox)
下载与安装: FireFox 插件:SQLite Manager可以管理你电脑上的任何 SQLite数据库.一个直观的目录树状来展示数据库的对象.通过提示对话来管理表.索引.视图和触发器.你能浏览和搜 ...