2017杭电多校联赛team3 Kanade's sum hdu6058 快速幂

Kanade's sum

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2011    Accepted Submission(s): 810


Problem Description
Give you an array  A[1..n] of length  n

Let  f(l,r,k)  be the k-th largest element of  A[l..r] .

Specially ,  f(l,r,k)=0  if  rl+1<k .

Give you  k  , you need to calculate  nl=1nr=lf(l,r,k)

There are T test cases.

1T10

kmin(n,80)

A[1..n] is a permutation of [1..n]

n5105
 

Input
There is only one integer T on first line.

For each test case,there are only two integers  n , k  on first line,and the second line consists of  n  integers which means the array  A[1..n]
 

Output
For each test case,output an integer, which means the answer.
 

Sample Input
  
  
1 5 2 1 2 3 4 5
 

Sample Output
  
  
30
 

Source
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:   6066  6065  6064  6063  6062 



思路:
由样例发现,n^k%mod=ans。





ac代码:
#include<stdio.h>
#define LL long long
#define Mod 1e9+7

LL N,K,ans;
LL power2(LL a, LL b, LL c) {
	LL res = 1;
	a %= c;
	while (b) {
		if (b & 1)
			res = (res * a) % c;
		a = (a * a) % c;
		b >>= 1;
	}
	return res;
}

int main() {
	int cnt=0;
	while(~scanf("%lld%lld",&N,&K)) {
		printf("Case #%d: %lld\n",++cnt,power2(N,K,Mod));
	}
	return 0;
}


总结:有想法多试一试,数据大的题目打表看看(上一场多校貌似也有一道找规律的)。


 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值