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 ...
随机推荐
- Android用户界面开发:Fragment
Android用户界面开发:Fragment 1:注意事项 3.0以前的Android 版本要使用FragmentActivity 来装载Fragment ,使用到support v4包. 3.0 ...
- PHP获取网卡的MAC地址原码;目前支持WIN/LINUX系统 获取机器网卡的物理(MAC)地址
声明转换于其它博客当中的. <?php /** 获取网卡的MAC地址原码:目前支持WIN/LINUX系统 获取机器网卡的物理(MAC)地址 **/ class GetMacAddr{ var $ ...
- Python-JS基础(基础结构~函数)
程序本质上分为三大结构: 顺序结构.分支结构.循环结构JavaScript中的程序结构也是这样,下面我们来分别介绍JS中的三种基本程序结构:我们上篇博客中介绍到的使用逻辑运算符&&实现 ...
- 几个常用的Node方法
1.写入文件 /** * 写入文件 * @param {string} filePath 文件路径 * @param {string} data 文件内容 * @return {none} */ fu ...
- iOS学习笔记之异步图片下载
写在前面 在iOS开发中,无论是在UITableView还是在UICollectionView中,通过网络获取图片设置到cell上是较为常见的需求.尽管有很多现存的第三方库可以将下载和缓存功能都封装好 ...
- canvas绘制简易动画
在canvas画布中制作动画相对来说很简单,实际上就是不断变化的坐标.擦除.重绘的过程 1.使用setInterval方法设置动画的间隔时间. setInterval(code,millisec) s ...
- SqlServr分页存储过程的写法
CREATE PROCEDURE [dbo].[GetDataByPager] ( --从第几条数据取 @startIndex INT, --分页的表 @tableName VARCHAR(50), ...
- java中与和或的注意点
1.&&和&的区别 &:无论左边是true是false.右边都运算. &&:当左边为false时,右边不运算. 2.|与||的区别 |:两边都参与运算. ...
- 063 日志分析(pv uv 登录人数 游客人数 平均访问时间 二跳率 独立IP)
1.需求分析 分析指标 pv uv 登录人数 游客人数 平均访问时间 二跳率 独立IP 2.使用的日志(一号店),会话信息 3.创建数据库 4.创建源表,存储源数据 5.创建我们需要的use表 6.创 ...
- JVM GC-----2、垃圾标记算法(一)
在上一篇文章中,我介绍了关于GC机制中,GC在确认垃圾对象后,是如何回收这些垃圾对象的几种算法.现在介绍下GC机制一般是如何定位(或者叫做标记)出这些垃圾对象的.我们先来问下自己,如何判介绍了断一个对 ...