跳过正文
  1. Posts/

vim在acm-icpc中的配置(转自kuangbin巨巨)

·1494 字·3 分钟

vim在ACM/ICPC中的使用 Posted on 2014年11月22日 by kuangbin Vim大法好!

应大家的要求,写一篇博客来介绍下vim在ACM中的简单使用。

写本文的目的,只是为了给广大acmer一个入门vim的指导。不喜勿喷! 不想看到的请远离!

vim大法好,远离sublime、cb保平安!

从13年开始,平时写程序和比赛都是用的vim,也一直在推荐大家使用vim,至于为何要用vim,原因很多。

为何要使用vim?1) 可以装逼,vim显得高端大气上档次,现场赛你打开的是丑陋的CB,别人打开的是VIM,高下立判。 2) 用vim可以明显提高写代码的感觉,加快代码速度。3) vim大法好。

当然,前面纯粹个人胡扯,要用啥都是个人偏好而已。

下面简单介绍VIM的使用。

比赛篇 首先介绍vim在比赛使用的使用。

先大致介绍现场赛vim的配置方法。

现场赛比赛系统是ubuntu, 都是安装好了vim的。

ubuntu系统下打开终端(终端一般在左侧有了,没有就按Ctrl+Alt+T启动,然后可以锁定在左侧),打开终端输入vim就进入vim了。

配置方法是输入 vim ~/.vimrc (这样是用vim编辑配置文件,或者用 gedit ~/.vimrc 就是用gedit编辑了)

配置的话,按照自己习惯加几句配置文件就可以使用了。

我一般配置下面几个:

1syntax on
2set nu
3set tabstop=4
4set shiftwidth=4
5colo evening
6set mouse=a
7set cin

上面这几个配置的具体含义可以去百度下,有的也是可以不要的。

然后配置以后保存。VIM的配置就结束了。

然后在终端里面 输入 vim A.cpp 然后就开始写代码了。

编译运行的话,可以另外打开一个终端(就是左侧右击,然后new一个出来),就可以一边编辑,一遍保存了。

但是注意在代码编译以后,一定要 :w 来保存下,然后进行编译运行。

编译可以输入 g++ A.cpp -o A

如果没有错就可以了。

然后输入 ./A 来运行,然后输入数据啥的,退出的话是 按 Ctrl+C

VIM入门篇

简明Vim练级攻略 把这上面教的VIM命令都熟悉下,差不多就可以了。

VIM命令很多,但是一开始常用的就那么几个吧,需要的指令慢慢积累就会了。

如果你的系统是WINDOWS,那可以安装一个GVIM,进行学习,用来平时写代码。

下载链接:here 进去后点击左侧的Download, 然后选择

PC: MS-DOS and MS-Windows 这个进行下载。 下载以后进行安装。

安装后桌面出现好几个快捷方式,有用的就gVim 7.4, 其余可以删除。

GVIM就直接点开就可以写了。一般是新建一个文本,改名为A.cpp, 然后打开Gvim, 把A.cpp拖入Gvim ,然后就可以进行编辑了。

Gvim的配置,就是在安装目录那有一个 _vimrc文件,编辑这个文件,在后面添加一些你自己需要的配置。

我的配置如下: (加到_vimrc后面)

代码实现
 1set nu
 2set history=1000000
 3set tabstop=4
 4set shiftwidth=4
 5
 6set smarttab
 7
 8set cindent
 9
10colo evening
11
12set showcmd
13
14set nobackup
15set noswapfile
16
17set mouse=a
18
19map :call CR()
20func! CR()
21exec "w"
22exec "!g++ -O2 -g % -o %<"
23exec "! %<"
24endfunc
25
26imap <c-]> {}O
27
28map ggVG"+y
29
30"inoremap ( ()
31"inoremap [ []
32"inoremap { {}
33"inoremap " ""
34"inoremap ' ''
35
36map :call SetTitle()
37func SetTitle()
38let l = 0
39let l = l + 1 | call setline(l,'/* ***********************************************')
40let l = l + 1 | call setline(l,'Author :kuangbin')
41let l = l + 1 | call setline(l,'Created Time :'.strftime('%c'))
42let l = l + 1 | call setline(l,'File Name :'.expand('%'))
43let l = l + 1 | call setline(l,'************************************************ */')
44let l = l + 1 | call setline(l,'')
45
46let l = l + 1 | call setline(l,'#include ')
47let l = l + 1 | call setline(l,'#include ')
48let l = l + 1 | call setline(l,'#include ')
49let l = l + 1 | call setline(l,'#include ')
50let l = l + 1 | call setline(l,'#include ')
51let l = l + 1 | call setline(l,'#include ')
52let l = l + 1 | call setline(l,'#include ')
53let l = l + 1 | call setline(l,'#include
54<map>')
55let l = l + 1 | call setline(l,'#include ')
56let l = l + 1 | call setline(l,'#include ')
57let l = l + 1 | call setline(l,'#include ')
58let l = l + 1 | call setline(l,'#include ')
59let l = l + 1 | call setline(l,'using namespace std;')
60let l = l + 1 | call setline(l,'')
61let l = l + 1 | call setline(l,'int main()')
62let l = l + 1 | call setline(l,'{')
63let l = l + 1 | call setline(l,' //freopen("in.txt","r",stdin);')
64let l = l + 1 | call setline(l,' //freopen("out.txt","w",stdout);')
65let l = l + 1 | call setline(l,' ')
66let l = l + 1 | call setline(l,' return 0;')
67let l = l + 1 | call setline(l,'}')
68endfunc</map>

里面的配置可以自己修改,可以加一些快捷键之类的。 我的配置文件是 按F2,自动写好头文件之类的信息,然后按F6进行编译运行。

平时用起来都很方便。

相关文章

vimrc备份

·3888 字·8 分钟
代码实现 1map <F9> :call SaveInputData()<CR> 2func! SaveInputData() 3 exec "tabnew" 4 exec 'normal "+gP' 5 exec "w! code/in.txt" 6endfunc 7 8 9 10"colorscheme torte 11" colorscheme murphy 12colorscheme elflord 13" colorscheme molokai 14"colorscheme elisex 15"colorscheme colorer 16"colorscheme blacklight 17"colorscheme blue 18"colorscheme darkblue 19"colorscheme evening 20"colorscheme shine 21 22 23 24 25"set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936 26"set termencoding=utf-8 27"set encoding=utf-8 28"set fileencodings=ucs-bom,utf-8,cp936 29"set fileencoding=utf-8 30 31"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 32" 显示相关 33"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 34"set shortmess=atI " 启动的时候不显示那个援助乌干达儿童的提示 35"winpos 5 5 " 设定窗口位置 36"set lines=40 columns=155 " 设定窗口大小 37set go= " 不要图形按钮 38"color asmanian2 " 设置背景主题 39"set guifont=Courier_New:h10:cANSI " 设置字体 40syntax on " 语法高亮 41autocmd InsertLeave * se nocul " 用浅色高亮当前行 42autocmd InsertEnter * se cul " 用浅色高亮当前行 43"set ruler " 显示标尺 44set showcmd " 输入的命令显示出来,看的清楚些 45"set cmdheight=1 " 命令行(在状态行下)的高度,设置为1 46"set whichwrap+=<,>,h,l " 允许backspace和光标键跨越行边界(不建议) 47"set scrolloff=3 " 光标移动到buffer的顶部和底部时保持3行距离 48set novisualbell " 不要闪烁(不明白) 49set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")} "状态行显示的内容 50set laststatus=1 " 启动显示状态行(1),总是显示状态行(2) 51"set foldenable " 允许折叠 52set foldmethod=manual " 手动折叠 53"set background=dark "背景使用黑色 54set nocompatible "去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限 55" 显示中文帮助 56if version >= 603 57 set helplang=cn 58 set encoding=utf-8 59endif 60" 设置配色方案 61"colorscheme murphy 62"字体 63"if (has("gui_running")) 64" set guifont=Bitstream\ Vera\ Sans\ Mono\ 10 65"endif 66""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 67"""""新文件标题 68"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 69"新建.c,.h,.sh,.java文件,自动插入文件头 70autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()" 71""定义函数SetTitle,自动插入文件头 72"map <F4> :call SetTitle()<CR> 73func SetTitle() 74 "如果文件类型为.sh文件 75 if &filetype == 'sh' 76 call setline(1,"\#########################################################################") 77 call append(line("."), "\# File Name: ".expand("%")) 78 call append(line(".")+1, "\# Author: 111qqz") 79 call append(line(".")+2, "\# mail: rkz2013@126.com") 80 call append(line(".")+3, "\# Created Time: ".strftime("%c")) 81 call append(line(".")+4, "\#########################################################################") 82 call append(line(".")+5, "\#!/bin/bash") 83 call append(line(".")+6, "") 84 else 85 let l = 0 86 let l = l + 1 | call setline(l,'/* ***********************************************') 87 let l = l + 1 | call setline(l,'Author :111qqz') 88 let l = l + 1 | call setline(l,'Created Time :'.strftime('%c')) 89 let l = l + 1 | call setline(l,'File Name :'.expand('%')) 90 let l = l + 1 | call setline(l,'************************************************ */') 91 let l = l + 1 | call setline(l,'') 92 endif 93 if &filetype == 'cpp' 94 let l = l + 1 | call setline(l,'#include <cstdio>') 95 let l = l + 1 | call setline(l,'#include <cstring>') 96 let l = l + 1 | call setline(l,'#include <iostream>') 97 let l = l + 1 | call setline(l,'#include <algorithm>') 98 let l = l + 1 | call setline(l,'#include <vector>') 99 let l = l + 1 | call setline(l,'#include <queue>') 100 let l = l + 1 | call setline(l,'#include <set>') 101 let l = l + 1 | call setline(l,'#include <map>') 102 let l = l + 1 | call setline(l,'#include <string>') 103 let l = l + 1 | call setline(l,'#include <cmath>') 104 let l = l + 1 | call setline(l,'#include <cstdlib>') 105 let l = l + 1 | call setline(l,'#include <ctime>') 106 let l = l + 1 | call setline(l,'#define fst first') 107 let l = l + 1 | call setline(l,'#define sec second') 108 let l = l + 1 | call setline(l,'#define lson l,m,rt<<1') 109 let l = l + 1 | call setline(l,'#define rson m+1,r,rt<<1|1') 110 let l = l + 1 | call setline(l,'#define ms(a,x) memset(a,x,sizeof(a))') 111 let l = l + 1 | call setline(l,'typedef long long LL;') 112 let l = l + 1 | call setline(l,'#define pi pair < int ,int >') 113 let l = l + 1 | call setline(l,'#define MP make_pair') 114 let l = l + 1 | call setline(l,'') 115 let l = l + 1 | call setline(l,'using namespace std;') 116 let l = l + 1 | call setline(l,'const double eps = 1E-8;') 117 let l = l + 1 | call setline(l,'const int dx4[4]={1,0,0,-1};') 118 let l = l + 1 | call setline(l,'const int dy4[4]={0,-1,1,0};') 119 let l = l + 1 | call setline(l,'const int inf = 0x3f3f3f3f;') 120 let l = l + 1 | call setline(l,'int main()') 121 let l = l + 1 | call setline(l,'{') 122 let l = l + 1 | call setline(l,' #ifndef ONLINE_JUDGE ') 123 let l = l + 1 | call setline(l,' freopen("code/in.txt","r",stdin);') 124 let l = l + 1 | call setline(l,' #endif') 125 let l = l + 1 | call setline(l,'') 126 let l = l + 1 | call setline(l,' #ifndef ONLINE_JUDGE ') 127 let l = l + 1 | call setline(l,' fclose(stdin);') 128 let l = l + 1 | call setline(l,' #endif') 129 let l = l + 1 | call setline(l,' return 0;') 130 let l = l + 1 | call setline(l,'}') 131 132 133 endif 134 if &filetype == 'c' 135 call append(line(".")+6, "#include<stdio.h>") 136 call append(line(".")+7, "") 137 endif 138 if &filetype == 'java' 139 call append(line(".")+6,"public class ".expand("%")) 140 call append(line(".")+7,"") 141 endif 142 "新建文件后,自动定位到文件末尾 143 autocmd BufNewFile * normal G23 144endfunc 145"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 146"键盘命令 147""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""v"""""""""""""""""""""""""""""""""""""""" 148 149nmap <leader>w :w!<cr> 150nmap <leader>f :find<cr> 151 152nmap <F8> :TagbarToggle<CR> 153 154 155" 映射全选+复制 ctrl+a 156map <C-A> ggvG"+Y 157map! <C-A> <Esc>ggVGY 158map <F12> gg=G 159" 选中状态下 Ctrl+c 复制 160vmap <C-c> "+y 161"去空行 162nnoremap <F2> :g/^\s*$/d<CR> 163"比较文件 164nnoremap <C-F2> :vert diffsplit 165"新建标签 166map <M-F2> :tabnew<CR> 167"列出当前目录文件 168map <F3> :tabnew .<CR> 169"打开树状文件目录 170map <C-F3> \be 171"C,C++ 按F5编译运行 172map <F5> :call CompileRunGcc()<CR> 173 174let g:tagbar_usearrows = 1 175nnoremap <leader>l :TagbarToggle<CR> 176func! CompileRunGcc() 177 exec "w" 178 if &filetype == 'c' 179 exec "!g++ % -o %<" 180 exec "! ./%<" 181 elseif &filetype == 'cpp' 182 exec "!g++ % -o %<" 183 exec "! ./%<" 184 elseif &filetype == 'java' 185 exec "!javac %" 186 exec "!java %<" 187 elseif &filetype == 'sh' 188 :!./% 189 elseif &filetype == 'py' 190 exec "!python %" 191 exec "!python %<" 192 endif 193endfunc 194"C,C++的调试 195"map <F8> :call Rungdb()<CR> 196func! Rungdb() 197 exec "w" 198 exec "!g++ % -g -o %<" 199 exec "!gdb ./%<" 200endfunc 201 202 203 204"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 205""实用设置 206""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 207" 设置当文件被改动时自动载入 208set autoread 209" quickfix模式 210autocmd FileType c,cpp map <buffer> <leader><space> :w<cr>:make<cr> 211"代码补全 212set completeopt=preview,menu 213"允许插件 214filetype plugin on 215"共享剪贴板 216set clipboard+=unnamed 217"从不备份 218set nobackup 219"make 运行 220:set makeprg=g++\ -Wall\ \ % 221"自动保存 222set autowrite 223set ruler " 打开状态栏标尺 224set cursorline " 突出显示当前行 225set magic " 设置魔术 226set guioptions-=T " 隐藏工具栏 227set guioptions-=m " 隐藏菜单栏 228"set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ %{&encoding}\ %c:%l/%L%)\ 229" 设置在状态行显示的信息 230set foldcolumn=0 231set foldmethod=indent 232set foldlevel=3 233set foldenable " 开始折叠 234" 不要使用vi的键盘模式,而是vim自己的 235set nocompatible 236" 语法高亮 237set syntax=on 238" 去掉输入错误的提示声音 239set noeb 240" 在处理未保存或只读文件的时候,弹出确认 241set confirm 242" 自动缩进 243set autoindent 244set clipboard+=unnamed 245set cindent 246" Tab键的宽度 247set tabstop=8 248" 统一缩进为8 249set softtabstop=4 250set shiftwidth=4 251" 不要用空格代替制表符 252set noexpandtab 253" 在行和段开始处使用制表符 254set smarttab 255" 显示行号 256set number 257" 历史记录数 258set history=1000 259"禁止生成临时文件 260set nobackup 261set noswapfile 262"搜索忽略大小写 263set ignorecase 264"搜索逐字符高亮 265set hlsearch 266set incsearch 267"行内替换 268set gdefault 269"编码设置 270set enc=utf-8 271set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936 272"语言设置 273set langmenu=zh_CN.UTF-8 274set helplang=cn 275" 我的状态行显示的内容(包括文件类型和解码) 276"set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")} 277"set statusline=[%F]%y%r%m%*%=[Line:%l/%L,Column:%c][%p%%] 278" 总是显示状态行 279set laststatus=2 280" 命令行(在状态行下)的高度,默认为1,这里是2 281set cmdheight=2 282" 侦测文件类型 283filetype on 284" 载入文件类型插件 285filetype plugin on 286" 为特定文件类型载入相关缩进文件 287filetype indent on 288" 保存全局变量 289set viminfo+=! 290" 带有如下符号的单词不要被换行分割 291set iskeyword+=_,$,@,%,#,- 292" 字符间插入的像素行数目 293set linespace=0 294" 增强模式中的命令行自动完成操作 295set wildmenu 296" 使回格键(backspace)正常处理indent, eol, start等 297set backspace=2 298" 允许backspace和光标键跨越行边界 299set whichwrap+=<,>,h,l 300" 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位) 301set mouse=a 302set selection=exclusive 303set selectmode=mouse,key 304" 通过使用: commands命令,告诉我们文件的哪一行被改变过 305set report=0 306" 在被分割的窗口间显示空白,便于阅读 307set fillchars=vert:\ ,stl:\ ,stlnc:\ 308" 高亮显示匹配的括号 309set showmatch 310" 匹配括号高亮的时间(单位是十分之一秒) 311set matchtime=1 312" 光标移动到buffer的顶部和底部时保持3行距离 313set scrolloff=3 314" 为C程序提供自动缩进 315set smartindent 316" 高亮显示普通txt文件(需要txt.vim脚本) 317set cursorline 318hi CursorLine cterm=bold ctermbg=blue ctermfg=yellow 319au BufRead,BufNewFile * setfiletype txt 320"自动补全 321":inoremap ( ()<ESC>i 322":inoremap ) <c-r>=ClosePair(')')<CR> 323:inoremap { {<CR>}<ESC>O 324:inoremap } <c-r>=ClosePair('}')<CR> 325":inoremap [ []<ESC>i 326":inoremap ] <c-r>=ClosePair(']')<CR> 327":inoremap " ""<ESC>i 328":inoremap ' ''<ESC>i 329function! ClosePair(char) 330 if getline('.')[col('.') - 1] == a:char 331 return "\<Right>" 332 else 333 return a:char 334 endif 335endfunction 336filetype plugin indent on 337"打开文件类型检测, 加了这句才可以用智能补全 338set completeopt=longest,menu 339""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 340 341 342 343 344 345 346"NERDtee设定 347let NERDChristmasTree=1 348let NERDTreeAutoCenter=1 349let NERDTreeBookmarksFile=$VIM.'\Data\NerdBookmarks.txt' 350let NERDTreeMouseMode=2 351let NERDTreeShowBookmarks=1 352let NERDTreeShowFiles=1 353let NERDTreeShowHidden=1 354let NERDTreeShowLineNumbers=1 355let NERDTreeWinPos='left' 356let NERDTreeWinSize=31 357nnoremap f :NERDTreeToggle 358map <F7> :NERDTree<CR> 359 360"""""""""""""""""Taglist设置""""""""""""""""" 361""let Tlist_Auto_Open = 1 362let Tlist_Ctags_Cmd = '/usr/bin/ctags' 363let Tlist_Show_One_File = 1 364let Tlist_Exit_OnlyWindow = 1 365 366 367 368"""""""""""""""""vundle设置""""""""""""""""" 369set nocompatible 370"filetype off 371set rtp+=~/.vim/bundle/vundle/ 372call vundle#rc() 373Bundle 'gmarik/vundle' 374" vim-scripts repos 375Bundle 'bash-support.vim' 376Bundle 'perl-support.vim' 377Bundle 'majutsushi/tagbar' 378Bundle 'ZoomWin' 379Bundle "scrooloose/syntastic" 380" set the runtime path to include Vundle and initialize 381set rtp+=~/.vim/bundle/vundle/ 382call vundle#rc() 383" alternatively, pass a path where Vundle should install plugins 384"let path = '~/some/path/here' 385"call vundle#rc(path) 386 387" let Vundle manage Vundle, required 388Plugin 'gmarik/vundle' 389Bundle "scrooloose/syntastic" 390filetype plugin indent on " required 391Bundle 'Valloric/YouCompleteMe' 392 393 394 395"""""""""""""""""Tagbar设置""""""""""""""""" 396let g:tagbar_autofocus = 1 397let g:tagbar_sort = 0 398let g:tagbar_compact = 1 399let g:tagbar_indent = 1 400let g:tagbar_autoshowtag = 1 401 402 403 404"""""""""""""""""youcompleteme设置""""""""""""""""" 405 406 407"let g:ycm_autoclose_preview_window_after_completion=1 408"nnoremap <leader>g :YcmCompleter GoToDefinitionElseDeclaration<CR> 409 410" YouCompleteMe 功能 411" 补全功能在注释中同样有效 412"let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/cpp/ycm/.ycm_extra_conf.py' 413"let g:ycm_complete_in_comments=1 414" 允许 vim 加载 .ycm_extra_conf.py 文件,不再提示 415"let g:ycm_confirm_extra_conf=0 416 417let g:ycm_error_symbol = '>>' 418let g:ycm_warning_symbol = '>' 419"nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR> 420"nnoremap <leader>gf :YcmCompleter GoToDefinition<CR> 421"nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR> 422"nmap <F4> :YcmDiags<CR> 423 424 425 426 427"""""""""""""""""youcompleteme设置 by wyz""""""""""""""""" 428let g:cpp_class_scope_highlight=1 429let g:cpp_experimental_template_highlight=1 430let g:ycm_show_diagnostics_ui=0 431let g:ycm_enable_diagnostic_signs=0 432let g:ycm_enable_diagnostic_highlighting = 0 433let g:ycm_echo_current_diagnostic = 0 434let g:ycm_collect_identifiers_from_tags_files = 1 435let g:ycm_key_invoke_completion = '<C-Q>' 436let g:ycm_seed_identifiers_with_syntax = 1 437let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py' 438let g:ycm_collect_identifiers_from_tags_files = 1 439let g:ycm_confirm_extra_conf = 0 440let g:ycm_autoclose_preview_window_after_completion = 1 441let g:ycm_autoclose_preview_window_after_insertion = 1 442 443 444"""""""""""""""""php是最好的语言23333"""""""""""""""" 445"只有在是PHP文件时,才启用PHP补全 446au FileType php call AddPHPFuncList() 447function AddPHPFuncList() 448 set dictionary-=/home/feiyan/tools/vim/funclist.txt dictionary+=/home/feiyan/tools/vim/funclist.txt 449 set complete-=k complete+=k 450endfunction 451 452"根据文件类型设置缩进格式 453 454au FileType html,python,vim,javascript setl shiftwidth=2 455au FileType html,python,vim,javascript setl tabstop=2 456au FileType java,php setl shiftwidth=4 457au FileType java,php setl tabstop=4 458 459set ai "自动对齐 460 461set foldlevel=100 " 禁止自动折叠 462 463filetype plugin on 464autocmd FileType python set omnifunc=pythoncomplete#Complete 465 466let g:pydiction_location='~/.vim/tools/pydiction/complete-dict'

test

·1604 字·4 分钟
应大家的要求,写一篇博客来介绍下vim在ACM中的简单使用。 写本文的目的,只是为了给广大acmer一个入门vim的指导。不喜勿喷! 不想看到的请远离!

数学专题 by kuangbin

·8864 字·18 分钟
从放暑假前周sir给我讲了一个用polya计数法和burnside定理做的题目(pku2409)后,突然觉得组合数学挺有意思,然后从那时起到现在几乎都在做这类的题目。 做到现在感觉这类题目的一些基本知识点都差不多有所了解了,水题也刷了不少,但还有很多难题自己实在是做不动,所以准备把这类题目先放一放,然后把前段时间做的水题整理一下(供以后的初学者参考,大牛就不要看了哈,都是水题)。剩下的比较难的题目就慢慢来吧,以后做出来再补上,这个小结会不断地更新。也希望大家有好的题目可以推荐一下,分享一下哈。 感谢:周sir,J_factory和福州大学神牛aekdycoin,大连理工大学神牛czyuan。 不扯了,进入主题: 1.burnside定理,polya计数法 这个专题我单独写了个小结,大家可以简单参考一下:polya 计数法,burnside定理小结 2.置换,置换的运算 置换的概念还是比较好理解的,《组合数学》里面有讲。对于置换的幂运算大家可以参考一下潘震皓的那篇《置换群快速幂运算研究与探讨》,写的很好。 *简单题:(应该理解概念就可以了) pku3270 Cow Sorting http://acm.pku.edu.cn/JudgeOnline/problem?id=3270 pku1026 Cipher http://acm.pku.edu.cn/JudgeOnline/problem?id=1026 *置换幂运算: pku1721 CARDS http://162.105.81.212/JudgeOnline/problem?id=1721 pku3128 Leonardo’s Notebook http://162.105.81.212/JudgeOnline/problem?id=3128 *推荐:(不错的应用) pku3590 The shuffle Problem http://162.105.81.212/JudgeOnline/problem?id=3590 3.素数,整数分解,欧拉函数 素数是可能数论里最永恒,最经典的问题了(我们的队名就叫PrimeMusic^-^)。素数的判断,筛法求素数,大素数的判断···还有很多其他问题都会用到素数。 *最水最水的:(心情不爽时用来解闷吧) pku1365 Prime Land pku2034 Anti-prime Sequences pku2739 Sum of Consecutive Prime Numbers pku3518 Prime Gap pku3126 Prime Path pku1595 Prime Cuts pku3641 Pseudoprime numbers pku2191 Mersenne Composite Numbers pku1730 Perfect Pth Powers pku2262 Goldbach’s Conjecture pku2909 Goldbach’s Conjecture *筛法: pku2689 Prime Distance(很好的一个应用) http://162.105.81.212/JudgeOnline/problem?id=2689 *反素数: zoj2562 More Divisors http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2562 *素数判断,整数分解: 这两题都要用到miller_rabin的素数判断和pollard_rho的整数分解,算法书上都会有,应该是属于模板题吧,不过最好看懂自己敲一遍。 pku1811 Prime Test http://acm.pku.edu.cn/JudgeOnline/problem?id=1811 pku2429 GCD & LCM Inverse http://acm.pku.edu.cn/JudgeOnline/problem?id=2429 *欧拉函数: 数论里很多地方都能用到欧拉函数,很重要的。 pku1284 Primitive Roots (很水) http://acm.pku.edu.cn/JudgeOnline/problem?id=1284 pku2407 Relatives (很水) http://acm.pku.edu.cn/JudgeOnline/problem?id=2407 pku2773 Happy 2006 http://162.105.81.212/JudgeOnline/problem?id=2773 pku2478 Farey Sequence (快速求欧拉函数) http://162.105.81.212/JudgeOnline/problem?id=2478 pku3090 Visible Lattice Points (法雷级数) http://acm.pku.edu.cn/JudgeOnline/problem?id=3090 *推荐:(欧拉函数,费马小定理) pku3358 Period of an Infinite Binary Expansion http://acm.pku.edu.cn/JudgeOnline/problem?id=3358 *整数分解 这个也很重要的耶,包括大数的表示方法。 pku2992 Divisors http://acm.pku.edu.cn/JudgeOnline/problem?id=2992 fzu1753 Another Easy Problem http://acm.fzu.edu.cn/problem.php?pid=1753 hit2813 Garden visiting http://acm-hit.sunner.cn/judge/show.php?Proid=2813 pku3101 Astronomy (分数的最小公倍数) http://acm.pku.edu.cn/JudgeOnline/problem?id=3101 4.扩展欧几里得,线性同余,中国剩余定理 这应该是数论里比较重要的一个部分吧,这类的题目也挺多,具体的内容最好先看看数论书,我也整理过一些,可以参考参考: http://hi.baidu.com/shw/blog/item/0676025d56a87d4afbf2c093.html *简单题: pku1006 Biorhythms http://acm.pku.edu.cn/JudgeOnline/problem?id=1006 pku1061 青蛙的约会 http://acm.pku.edu.cn/JudgeOnline/problem?id=1061 pku2891 Strange Way to Express Integers http://acm.pku.edu.cn/JudgeOnline/problem?id=2891 pku2115 C Looooops http://acm.pku.edu.cn/JudgeOnline/problem?id=2115 pku2142 The Balance http://162.105.81.212/JudgeOnline/problem?id=2142 *强烈推荐: sgu106 The equation http://acm.sgu.ru/problem.php?contest=0&problem=106 pku3708 Recurrent Function (经典) http://acm.pku.edu.cn/JudgeOnline/problem?id=3708 5.约瑟夫环问题 这个问题还是比较有意思的,不是很难。 *简单题: pku3517 And Then There Was One http://acm.pku.edu.cn/JudgeOnline/problem?id=3517 pku1781 In Danger http://acm.pku.edu.cn/JudgeOnline/problem?id=1781 pku1012 Joseph http://162.105.81.212/JudgeOnline/problem?id=1012 pku2244 Eeny Meeny Moo http://162.105.81.212/JudgeOnline/problem?id=2244 *推荐: pku2886 Who Gets the Most Candies? http://162.105.81.212/JudgeOnline/problem?id=2886 6.高斯消元法解方程 其实解方程并不是很难,就是按线性代数中学的那种方法,把系数矩阵化成上三角矩阵或数量矩阵,不过有些题目要判断是否有解,或枚举所有解。不过这类题目我认为比较难的还是怎么去建立这个方程组,这个理解了,就没什么大问题了。 *简单题: pku1222 EXTENDED LIGHTS OUT http://162.105.81.212/JudgeOnline/problem?id=1222 pku1681 Painter’s Problem http://162.105.81.212/JudgeOnline/problem?id=1681 pku1830 开关问题 http://162.105.81.212/JudgeOnline/problem?id=1830 *推荐: pku2947 Widget Factory http://162.105.81.212/JudgeOnline/problem?id=2947 pku2065 SETI http://162.105.81.212/JudgeOnline/problem?id=2065 *强烈推荐: pku1753 Flip Game http://162.105.81.212/JudgeOnline/problem?id=1753 pku3185 The Water Bowls http://162.105.81.212/JudgeOnline/problem?id=3185 *变态题: pku1487 Single-Player Games http://162.105.81.212/JudgeOnline/problem?id=1487 7.矩阵 用矩阵来解决问题确实很常见,但我现在用到还不是很好,很多难题我还不会做。建议大家可以去看Matrix67的那篇关于矩阵的十个问题,确实很经典,但不太好看懂。 *简单: pku3070 Fibonacci http://162.105.81.212/JudgeOnline/problem?id=3070 pku3233 Matrix Power Series http://162.105.81.212/JudgeOnline/problem?id=3233 pku3735 Training little cats http://162.105.81.212/JudgeOnline/problem?id=3735 8.高次同余方程 有关这个问题我应该是没什么发言权了,A^B%C=D,我现在只会求D和B,唉,很想知道A该怎么求。就先推荐几道题目吧,这里涉及到了一个baby-step,giant-step算法。 fzu1759 Super A^B mod C http://acm.fzu.edu.cn/problem.php?pid=1759 pku3243 Clever Y http://162.105.81.212/JudgeOnline/problem?id=3243 pku2417 Discrete Logging http://162.105.81.212/JudgeOnline/problem?id=2417 hdu2815 Mod Tree http://acm.hdu.edu.cn/showproblem.php?pid=2815 9.容斥原理,鸽巢原理 很有用的两个定理,但好像单独考这两个定理的不是很多。 *鸽巢原理: pku2365 Find a multiple http://162.105.81.212/JudgeOnline/problem?id=2356 pku3370 Halloween treats http://162.105.81.212/JudgeOnline/problem?id=3370 *容斥原理: hdu1695 GCD http://acm.hdu.edu.cn/showproblem.php?pid=1695 hdu2461 Rectangles http://acm.hdu.edu.cn/showproblem.php?pid=2461 10.找规律,推公式 这类题目的设计一般都非常巧妙,真的是很难想出来,但只要找到规律或推出公式,就不是很难了。我很多都是在参考别人思路的情况下做的,能自己想出来真的很不容易。 *个人感觉都挺不错的: pku3372 Candy Distribution http://162.105.81.212/JudgeOnline/problem?id=3372 pku3244 Difference between Triplets http://162.105.81.212/JudgeOnline/problem?id=3244 pku1809 Regetni http://162.105.81.212/JudgeOnline/problem?id=1809 pku1831 不定方程组 http://162.105.81.212/JudgeOnline/problem?id=1831 pku1737 Connected Graph http://162.105.81.212/JudgeOnline/problem?id=1737 pku2480 Longge’s problem http://162.105.81.212/JudgeOnline/problem?id=2480 pku1792 Hexagonal Routes http://acm.pku.edu.cn/JudgeOnline/problem?id=1792 11.排列组合,区间计数,计数序列 这些题目可能需要一些组合数学知识,基本上高中的知识就够了。区间计数问题一般不难,但写的时候需要仔细一些,各种情况要考虑到位。至于像卡特兰数,差分序列,斯特灵数···都还挺有意思,可以去看看《组合数学》。 *简单题: pku1850 Code http://162.105.81.212/JudgeOnline/problem?id=1850 pku1150 The Last Non-zero Digit http://162.105.81.212/JudgeOnline/problem?id=1150 pku1715 Hexadecimal Numbers http://162.105.81.212/JudgeOnline/problem?id=1715 pku2282 The Counting Problem http://162.105.81.212/JudgeOnline/problem?id=2282 pku3286 How many 0’s? http://162.105.81.212/JudgeOnline/problem?id=3286 *推荐: pku3252 Round Numbers http://162.105.81.212/JudgeOnline/problem?id=3252 *计数序列: pku1430 Binary Stirling Numbers http://162.105.81.212/JudgeOnline/problem?id=1430 pku2515 Birthday Cake http://acm.pku.edu.cn/JudgeOnline/problem?id=2515 pku1707 Sum of powers http://acm.pku.edu.cn/JudgeOnline/problem?id=1707 12.二分法 二分的思想还是很重要的,这里就简单推荐几个纯粹的二分题。 *简单: pku3273 Monthly Expense http://162.105.81.212/JudgeOnline/problem?id=3273 pku3258 River Hopscotch http://162.105.81.212/JudgeOnline/problem?id=3258 pku1905 Expanding Rods http://162.105.81.212/JudgeOnline/problem?id=1905 pku3122 Pie http://162.105.81.212/JudgeOnline/problem?id=3122 *推荐: pku1845 Sumdiv http://acm.pku.edu.cn/JudgeOnline/problem?id=1845 13.稳定婚姻问题 无意中接触到这个算法,还蛮有意思的,《组合数学》中有详细的介绍。 pku3487 The Stable Marriage Problem http://acm.pku.edu.cn/JudgeOnline/problem?id=3487 zoj1576 Marriage is Stable http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1576 14.数位类统计问题 在航点月赛中第一次接触到这类问题,scau大牛little龙推荐我看了一篇论文,09年刘聪的《浅谈数位类统计问题》,这篇论文相当精彩,也相当详细,每道题都有详细的分析和作者的参考代码。所以我也没什么可说的了,这些题的代码我博客里也就不贴了,大家直接去看论文吧。 简单: ural1057 Amount of degrees http://acm.timus.ru/problem.aspx?space=1&num=1057 spoj1182 Sorted bit squence https://www.spoj.pl/problems/SORTBIT/ hdu3271 SNIBB http://acm.hdu.edu.cn/showproblem.php?pid=3271 较难: spoj2319 Sequence https://www.spoj.pl/problems/BIGSEQ/ sgu390 Tickets http://acm.sgu.ru/problem.php?contest=0&problem=390 以上分类的题目在我的博客里都可以找到详细的解题报告和参考代码,由于比较麻烦就没加链接,需要的可以用我的站内搜索找到。 本小结会不断更新,转载请注明出处。 严重声明:本文只适合ACM初学者,路过的大牛如有相同类型的比较好的题目可以推荐一些啊。 来自: http://hi.baidu.com/shw/blog/item/5305e12c7289973e359bf768.html

uva 6692 Lucky Number

·395 字·1 分钟
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4704 题目大意是说,定义一个数的lucky number是距离i最远的j且满足(a[i]<a[j] i<j)。

codeforces #332 div 2 C. Day at the Beach

·561 字·2 分钟
C. Day at the Beach time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunately, the weather was bad, so the friends were unable to ride waves. However, they decided to spent their time building sand castles.