解法参考:http://blog.csdn.net/a601025382s/article/details/9840125

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm> using namespace std; #define LL long long int const int MAXN = ;
const LL MOD = (1e9) + ; int n;
LL a[MAXN];
LL b[MAXN]; void ExGcd( LL a, LL b, LL& d, LL& x, LL& y )
{
if ( !b ) { d = a, x = , y = ; }
else
{
ExGcd( b, a % b, d, y, x );
y -= x * ( a / b );
}
} LL GetInverse( LL num )
{
LL d, x, y;
ExGcd( num, MOD, d, x, y );
return ( x % MOD + MOD ) % MOD;
} int main()
{
// freopen( "1001.in", "r", stdin );
// freopen( "s.out", "w", stdout );
int T;
scanf( "%d", &T );
while ( T-- )
{
scanf( "%d", &n );
LL all = ;
for ( int i = ; i < n; ++i )
{
scanf( "%I64d", &a[i] );
b[i] = a[i];
all *= a[i];
all %= MOD;
} //printf( "all = %I64d\n", all ); sort( b, b + n );
int i, j;
for ( i = , j = ; i < n ; i += , ++j )
a[i] = b[j];
for ( i = , j = n - ; i < n; i += , --j )
a[i] = b[j]; // for ( int i = 0; i < n; ++i )
// printf( "%I64d ", a[i] );
// puts(""); LL p = ;
for ( int i = ; i < n; ++i )
{
LL tmp = ( all * GetInverse( ( a[i] * a[i - ] ) % MOD ) ) % MOD;
p += ( min( a[i], a[i - ] ) * tmp ) % MOD ;
p %= MOD;
}
all *= n;
all %= MOD;
// printf("p = %I64d\n", p );
LL ans = ( all - p + MOD ) % MOD;
printf( "%I64d\n", ans );
}
return ;
}

HDU 4655 Cut Pieces 找规律+简单计数的更多相关文章

  1. hdu 4655 Cut Pieces 找规律

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4655 题意:给你一组整数,代表每个木块所能涂成的颜色种数(编号1~ai),相邻的两块所能涂成的颜色如果是一 ...

  2. HDU 4655 Cut Pieces(2013多校6 1001题 简单数学题)

    Cut Pieces Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total ...

  3. hdu 4655 Cut Pieces(想法题)

    Cut Pieces Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Tota ...

  4. HDU 4655 Cut Pieces(数学分析题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4655 题意:给出n个石子,第i个石子可以染ai种颜色.对于每种颜色,比如颜色1221,我们称有3段.连 ...

  5. hdu 4655 Cut Pieces

    这个解题报告讲的很详细了!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #in ...

  6. HDU 4861 Couple doubi(找规律|费马定理)

    Couple doubi Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  7. Tetrahedron(Codeforces Round #113 (Div. 2) + 打表找规律 + dp计数)

    题目链接: https://codeforces.com/contest/166/problem/E 题目: 题意: 给你一个三菱锥,初始时你在D点,然后你每次可以往相邻的顶点移动,问你第n步回到D点 ...

  8. hdu 2604 Queuing dp找规律 然后矩阵快速幂。坑!!

    http://acm.hdu.edu.cn/showproblem.php?pid=2604 这题居然O(9 * L)的dp过不了,TLE,  更重要的是找出规律后,O(n)递推也过不了,TLE,一定 ...

  9. hdu 3951 - Coin Game(找规律)

    这道题是有规律的博弈题目,,, 所以我们只需要找出规律来就ok了 牛人用sg函数暴力找规律,菜鸟手工模拟以求规律...[牢骚] if(m>=2) { if(n<=m) {first第一口就 ...

随机推荐

  1. android获取传感器数据

    传感器获取数据的频率: https://blog.csdn.net/huangbiao86/article/details/6745933 SensorManager.SENSOR_DELAY_GAM ...

  2. A Multigrid Tutorial中涉及到的难点词汇

    Multigrid Tutorial中涉及的词汇: Elliptic PDEs 椭圆型偏微分方程 Lawrence Livermore National Laboratory 劳伦斯利福摩尔国家实验室 ...

  3. macOS Sierra系统偏好设置->安全性和隐私->通用中的“任何来源” 选项开与关

    显示"任何来源"选项在控制台中执行: sudo spctl --master-disable 不显示"任何来源"选项(macOS 10.12默认为不显示)在控制 ...

  4. C语言学生成绩管理系统(简易版)

    #include<stdio.h> #include<stdlib.h> #include<string.h> int readstudents(struct st ...

  5. 路由传参,path和query的刷新报错js文件丢失

    日常的路由跳转,基本都会用到传参,有两种方式:path + query, name + params 常用的写法: this.$router.push({ path: 'proDetail',quer ...

  6. 牛客小白月赛1 J おみやげをまらいました 【MAP】

    链接:https://www.nowcoder.com/acm/contest/85/J おみやげをまらいました!    蛙蛙还是给你带来了礼物.但它有个小小的要求,那就是你得在石头剪刀布上赢过它才能 ...

  7. BZOJ2683: 简单题(cdq分治 树状数组)

    Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 2142  Solved: 874[Submit][Status][Discuss] Descripti ...

  8. git 常用命令及仓库创建

    一.常用命令 1.添加到本地仓库缓存 git add . 2.查看本地仓库状态 git status 3.提交到本地仓库 git commit -am 'project init' 4.连接线上分支 ...

  9. mysql数据库设置外键,更新与删除选项

    CASCADE:父表delete.update的时候,子表会delete.update掉关联记录:SET NULL:父表delete.update的时候,子表会将关联记录的外键字段所在列设为null, ...

  10. kafka单机环境搭建及其基本使用

    最近在搞kettle整合kafka producer插件,于是自己搭建了一套单机的kafka环境,以便用于测试.现整理如下的笔记,发上来和大家分享.后续还会有kafka的研究笔记,依然会与大家分享! ...