---题目:冒泡排序计数
Description
考虑冒泡排序的一种实现。
bubble-sort (A[], n)
> round = 0
> while A is not sorted
> > round := round + 1
> > for i := 1 to n - 1
> > > if (A[i] > A[i + 1])
> > > > swap(A[i], A[i + 1])
求1 .. n的排列中,有多少个排列使得A被扫描了K遍,亦即算法结束时round == K。
答案模20100713输出。
Input
输入包含多组数据。每组数据为一行两个整数N,K。
Output
对每组数据,输出一行一个整数表示答案。
Sample Input 1
3 3 0 3 1 3 2
Sample Output 1
1 3 2
Hint
HINT:时间限制:1.0s 内存限制:256.0MB
T <= 10 ^ 5。
1 <= K < N < 10 ^ 6。
AC代码:
#include <cstdio>
#include <iostream>
using namespace std;
const int mod = 20100713;
typedef long long ll;
const int N = 1e6+10;
ll f[N];
ll quick(ll a,ll n){
ll ans = 1;
while(n){
if(n&1) ans = (ans*a)%mod;
a = (a*a)%mod;
n>>=1;
}
return ans;
}
void init(){
f[0] = f[1] = 1;
for(int i = 2;i <= N-10;i++){
f[i] = (f[i-1]*i)%mod;
}
}
int main(){
init();
int t;scanf("%d",&t);
ll n,k;
while(t--){
scanf("%lld%lld",&n,&k);
ll ans = (f[k]*(quick(k+1,n-k)-quick(k,n-k)+mod)%mod)%mod;
printf("%lld\n",ans);
}
return 0;
}
这道题 好难TT
---题目:前10名
Description
数据很多,但我们经常只取前几名,比如奥运只取前3名。现在我们有n个数据,请按从大到小的顺序,输出前10个名数据。
Input
两行。
第一行一个整数n,表示要对多少个数据
第二行有n个整数,中间