枚举n个数的排列

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
using namespace std;

int swap(int &a, int &b){ //交换数组中两个元素位置
int t = a;
a = b;
b = t;
return 0;
}

int permutation(int k, int n, int perm[]){
if(k == n - 1){
for(int i = 0; i < n; i++) //输出一个排列
cout << perm[i] << " ";
cout << endl;
return 0;
}
for(int i = k; i < n; i++){
if(i != k && perm[i] == perm[k]) continue; //除本身外,如果交换的两个数相同,则跳过
swap(perm[i], perm[k]);
permutation(k + 1, n, perm); //递归进行排列
swap(perm[i], perm[k]); //恢复原来的位置
}
return 0;
}

int main(){
int n;
cin >> n;
int a[n];
for(int i = 0; i < n; i++)
cin >> a[i];
permutation(0, n, a);
return 0;
}

Linux下的技巧操作

一、好用的工具

  1. autojump: 可以记录进入过的目录, 支持直接跳转到想到的目录
    j path: 进入path目录
    j: 进入权值最高的目录
    j -i[权重]: 增加权值
    j -d[权重]: 减少权值
    jo path: 打开目录
    j -s: 显示自动跳转数据库中的条目

vim配置

“ —————————– Vundle Start —————————–
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
“插件管理
Plugin ‘VundleVim/Vundle.vim’
“目录树
Plugin ‘The-NERD-tree’
“代码补全
Bundle ‘Valloric/YouCompleteMe’
“异步语法检查
Plugin ‘w0rp/ale’
call vundle#end()
filetype plugin indent on
“ —————————– Vundle End —————————–

牛客网43的B题

链接:https://ac.nowcoder.com/acm/contest/548/B
来源:牛客网

题目描述
立华奏在学习初中数学的时候遇到了这样一道大水题:
“设箱子内有 n 个球,其中给 m 个球打上标记,设一次摸球摸到每一个球的概率均等,求一次摸球摸到打标记的球的概率”
“emmm…语言入门题”
但是她改了一下询问方式:设最终的答案为 p ,请输出 p 小数点后K1到K2位的所有数字(若不足则用 0 补齐)
输入描述:
第一行一个整数 T,表示有 T 组数据。
接下来每行包含四个整数
m, n, K1, K2,
意义如「题目描述」所示。
输出描述:
输出 T 行,每行输出 K 2 − K 1 + 1 K2−K1+1 个数,表示答案。
注意同行的数字中间不需要用空格隔开。
示例1
输入
5 2 3 2 3
1 7 1 7
2 5 1 3
12345 54321 3 10
12345 54321 100000 100010
输出
66
1428571
400
72601756
78428232175
备注: 1<=m<=n<=109, 1<=K1<=K2<=109, 1<=m<=n<=109,1<=K1<=K2<=109

|