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 ...
随机推荐
- selenium捕捉视频
捕捉视频 有时候我们未必能够分析故障只需用日志文件或截图的帮助.有时捕获完整的执行视频帮助.让我们了解如何捕捉视频. 我们将利用Monte媒体库的执行相同. 配置 第1步:导航到URL - http: ...
- 常用adb操作命令详解
1. 查看当前运行的所有设备adb devices 返回当前设备列表 这个命令是查看当前连接的设备, 连接到计算机的android设备或者模拟器将会列出显示2. 安装软件adb install验证是否 ...
- git命令行提交并且同步到远程代码库
远程代码库以github为例 1.打开 git bash 2.进入项目目录 cd /e/myGitProjects/test 3.提交到本地git仓库 git add -Agit commit -m ...
- Android学习笔记————利用JDBC连接服务器数据库
/******************************************************************************************** * auth ...
- 两道SQL题目
1.查询省内所有城市气温都大于35度的省份(表名:Temp) SELECT province FROM Temp WHERE province NOT IN ( SELECT province FRO ...
- jQuery Ajax实例各种使用方法详解
在jquery中ajax实现方法分类很多种,如有:load.jQuery.get.jQuery.post.jQuery.getScript.jQuery Ajax 事件.jQuery.ajaxSetu ...
- 数论-质数 poj2689,阶乘分解,求阶乘的尾零hdu1124, 求尾零为x的最小阶乘
/* 要求出[1,R]之间的质数会超时,但是要判断[L,R]之间的数是否是素数却不用筛到R 因为要一个合数n的最大质因子不会超过sqrt(n) 所以只要将[2,sqrt(R)]之间的素数筛出来,再用这 ...
- ECMAscript5 新增数组内函数
indexOf() 格式:数组.indexOf(item, start) 功能:从start这个下标开始,查找item在数组中的第一次出现的下标. 参数:item 我们要去查找的元素 start从哪个 ...
- springbank 开发日志 SpringMVC是如何找到handler找到对应的方法并执行的
从DispatcherServlet说起,本文讨论的内容都是DispatcherServlet的doDispatch方法完成 mappedHandler是一个HandlerExecutionChain ...
- python学习之python安装
1.下载python源码包 wget https://www.python.org/ftp/python/3.5.5/Python-3.5.5.tar.xz 2.下载 xz yum -y insta ...