HDU 4655 Cut Pieces 找规律+简单计数
解法参考: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 找规律+简单计数的更多相关文章
- hdu 4655 Cut Pieces 找规律
链接:http://acm.hdu.edu.cn/showproblem.php?pid=4655 题意:给你一组整数,代表每个木块所能涂成的颜色种数(编号1~ai),相邻的两块所能涂成的颜色如果是一 ...
- HDU 4655 Cut Pieces(2013多校6 1001题 简单数学题)
Cut Pieces Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total ...
- hdu 4655 Cut Pieces(想法题)
Cut Pieces Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Tota ...
- HDU 4655 Cut Pieces(数学分析题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4655 题意:给出n个石子,第i个石子可以染ai种颜色.对于每种颜色,比如颜色1221,我们称有3段.连 ...
- hdu 4655 Cut Pieces
这个解题报告讲的很详细了!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #in ...
- HDU 4861 Couple doubi(找规律|费马定理)
Couple doubi Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- Tetrahedron(Codeforces Round #113 (Div. 2) + 打表找规律 + dp计数)
题目链接: https://codeforces.com/contest/166/problem/E 题目: 题意: 给你一个三菱锥,初始时你在D点,然后你每次可以往相邻的顶点移动,问你第n步回到D点 ...
- hdu 2604 Queuing dp找规律 然后矩阵快速幂。坑!!
http://acm.hdu.edu.cn/showproblem.php?pid=2604 这题居然O(9 * L)的dp过不了,TLE, 更重要的是找出规律后,O(n)递推也过不了,TLE,一定 ...
- hdu 3951 - Coin Game(找规律)
这道题是有规律的博弈题目,,, 所以我们只需要找出规律来就ok了 牛人用sg函数暴力找规律,菜鸟手工模拟以求规律...[牢骚] if(m>=2) { if(n<=m) {first第一口就 ...
随机推荐
- 为什么实例没有prototype属性?什么时候对象会有prototype属性呢?
为什么实例没有prototype属性?什么时候对象会有prototype属性呢? javascript loudou 1月12日提问 关注 9 关注 收藏 6 收藏,554 浏览 问题对人有帮助,内容 ...
- Notepad++配色方案
1.下载notepad++样式文件 styles.xml 2.将该文件拷贝到 C:\Users\Administrator\AppData\Roaming\Notepad++ 目录(将Administ ...
- 前端JavaScript之DOM使用案例
1.弹出框点击关闭 (这个例子关键自己创建标签以及属性,不是太好想啊,而且作用相对来数也不是太大) <!DOCTYPE html> <html> <head> &l ...
- 【iOS】史上最全的iOS持续集成教程 (下)
:first-child{margin-top:0!important}.markdown-body>:last-child{margin-bottom:0!important}.markdow ...
- python核心编程2 第六章 练习
6-2. 字符串标识符.修改例 6-1 的 idcheck.py 脚本,使之可以检测长度为一的标识符,并且可以识别 Python 关键字,对后一个要求,你可以使用 keyword 模块(特别是 key ...
- LeetCode977. 有序数组的平方
问题:977. 有序数组的平方 给定一个按非递减顺序排序的整数数组 A,返回每个数字的平方组成的新数组,要求也按非递减顺序排序. 示例 1: 输入:[-4,-1,0,3,10] 输出:[0,1,9,1 ...
- ethereum(以太坊)(四)--值传递与引用传递
contract Person { string public _name; function Person() { _name = "liyuechun"; } function ...
- tcl之控制流-break/continue
- thinkphp centos7 报class POD not found
没有安装PDO yum install php70w-pdo yum install php70w-mysqlnd 两条命令搞定
- vue 组件轮播联动
组件轮播联动我使用的是 el-carousel 组件,具体代码如下: <el-carousel trigger="click" :interval="3000&qu ...