码迷,mamicode.com
首页 > 其他好文 > 详细

MCM论文模板

时间:2014-10-08 03:12:14      阅读:642      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   io   os   ar   java   

bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣

 

 

MCM.sty

 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 2 %% latex Template
 3 %% The Template is writen by liuyu,I reference to it.
 4 %% Revised: NOV 21th, 2006
 5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 6 
 7 \NeedsTeXFormat{LaTeX2e}
 8 \ProvidesPackage{MCM}
 9 
10 % packages
11 \RequirePackage{color}          % color image and color definition
12 \RequirePackage{calc}           % do size calculations
13 \RequirePackage{fancyhdr}       % personalize page header
14 \RequirePackage{graphicx}       % include graphics
15 \RequirePackage{ifthen}         % logic options
16 \RequirePackage{lastpage}       % refer to the number of last page
17 \RequirePackage{listings}       % format source code
18 
19 % Declare Options
20 \newcommand{\MCM@control}{000}
21 \DeclareOption*
22 {
23     \edef\MCM@control{\CurrentOption}
24 }
25 
26 % Process Options
27 \ProcessOptions
28 \newcommand{\control}{\MCM@control}
29 \newcommand{\team}{Team \#\ \MCM@control}
30 
31 % if we are running pdflatex?
32 \newboolean{pdf}
33 \ifthenelse{\isundefined{\pdfoutput}}%
34     {\setboolean{pdf}{false}}%
35     {\setboolean{pdf}{true}}
36 
37 % style: hyperlinked references
38 %\ifpdf
39 %\RequirePackage[bookmarks=true,%
40 %    linkcolor=black,citecolor=black,pagecolor=black,%
41 %    colorlinks=true]{hyperref}
42 %\fi
43 
44 % style: page layout
45 \setlength{\headheight}{15pt}
46 \setlength{\headsep}{20pt}
47 \setlength{\footskip}{30pt}
48 \setlength{\voffset}{-5pt}
49 \setlength{\hoffset}{16pt}
50 \setlength{\oddsidemargin}{0pt}
51 \setlength{\evensidemargin}{\oddsidemargin}
52 \setlength{\textwidth}{\paperwidth-2\hoffset-2\oddsidemargin-2in}
53 \setlength{\marginparpush}{0pt}
54 \setlength{\marginparwidth}{0pt}
55 \addtolength{\textheight}{3\baselineskip}
56 
57 % style: float counter
58 \setcounter{totalnumber}{6}
59 \setcounter{topnumber}{3}
60 \setcounter{bottomnumber}{3}
61 
62 % style: table & figure caption vertical space
63 \setlength{\abovecaptionskip}{10pt}
64 \setlength{\belowcaptionskip}{10pt}
65 
66 % style: table & figure caption font size and face
67 \renewcommand{\figurename}{\footnotesize{\textbf{Fig}}}
68 \renewcommand{\tablename}{\footnotesize{\textbf{Tab}}}
69 
70 % style: table of contents topic depth
71 \setcounter{tocdepth}{3}
72 
73 % style: bibliography
74 \bibliographystyle{unsrt}
75 
76 % style: list typesetting
77 \definecolor{grey}{rgb}{0.3,0.3,0.3}
78 \definecolor{darkgreen}{rgb}{0,0.3,0}
79 \definecolor{darkblue}{rgb}{0,0,0.3}
80 \definecolor{grey}{rgb}{0.95,0.95,0.95}
81 \definecolor{darkgreen}{rgb}{0.0,0.5078,0.0}
82 
83 \lstset{language=Matlab} \lstset{xleftmargin=1em,xrightmargin=1em}
84 \lstset{frame=} \lstset{%backgroundcolor=\color{grey},
85 commentstyle=\color{darkgreen},keywordstyle=\color{blue},%,caption=\lstname,basicstyle=\footnotesize,
86 breaklines=true,columns=flexible,mathescape=fause }
87 \lstset{framexleftmargin=0.5em,framexrightmargin=1em,framextopmargin=0em,basicstyle=\footnotesize,framexbottommargin=1em}
88 %\lstdefinestyle{numbers}{numbers=left,stepnumber=1,numberstyle=\small,numbersep=1em}
89 \lstloadlanguages{C,C++,Java,Matlab,Mathematica}

MCM.tex

 1 %=====================导=======言==============================
 2 \documentclass[a4paper,12pt]{article}%\documentclass[a4paper,12pt,titlepage]{article}
 3 %======================Include Packages========================
 4 \usepackage[centerlast]{caption2}
 5 \usepackage{graphicx}
 6 \usepackage{amsfonts}
 7 \usepackage[toc,page,title,titletoc,header]{appendix}
 8 \usepackage{color}
 9 \usepackage{titlesec}
10 \usepackage{amsthm}
11 \usepackage{latexsym}
12 \usepackage{amsmath}        % AMSLaTeX
13 \usepackage{amssymb}        % AMSLaTeX sym-bols
14 \usepackage{indentfirst}    % indent first line of each paragraph
15 \usepackage{longtable}      % table that occupies multiple pages
16 \usepackage{algorithmic}    %
17 \usepackage{algorithm}      %
18 \usepackage{subfigure}      %
19 \usepackage{slashbox}       %@@表格头画斜线
20 \usepackage{graphicx}       %@@图象
21 \usepackage[centerlast]{caption2}
22 \usepackage{flafter}
23 
24 \usepackage{enumerate}
25 \usepackage{pifont,calc}
26 \usepackage{picins}
27 \usepackage{picinpar}
28 \usepackage{fancybox}
29 \usepackage{MCM}
30 
31 \usepackage{titletoc}
32 
33 %===============设置字体=============================
34 \usepackage{mathptmx}  % times roman, including math (where possible)
35 \usepackage{mathpazo}  % palatino, including math (where possible)
36 \usepackage{helvet}    % helvetica
37 %====================================================
38 %===============================列举间隔定义=======================
39 \makeatletter
40 \def\enumerate{%
41  \ifnum \@enumdepth >\thr@@\@toodeep\else
42    \advance\@enumdepth\@ne
43    \edef\@enumctr{enum\romannumeral\the\@enumdepth}%
44      \expandafter
45      \list
46        \csname label\@enumctr\endcsname
47        {\usecounter\@enumctr\def\makelabel##1{\hss\llap{##1}}%
48          \addtolength{\leftmargin}{10pt}\addtolength{\parsep}{10pt}\addtolength{\rightmargin}{20pt} %%
49          \addtolength{\listparindent}{50pt} %%%%
50          \addtolength{\itemsep}{-15pt} %%%%
51          \addtolength{\topsep}{-20pt}} %%%%
52  \fi}
53 \makeatother
54 %================================================================
55 
56 %===========================目录新定义==========================
57 
58 \titlecontents{section}[0mm]
59 {\vspace{.2\baselineskip}\bfseries}
60 {\normalsize{\thecontentslabel}~\hspace{.5em}} {}
61 {\dotfill\contentspage[{\makebox[0pt][r]{\thecontentspage}}]}
62 [\vspace{.1\baselineskip}]
63 \dottedcontents{section}[1.16cm]{\large}{2.0em}{4pt}
64 \dottedcontents{subsection}[2.00cm]{\normalsize}{2.0em}{4pt}
65 %===============================================================
66 
67 %=========================定义页眉================================
68 \usepackage{lastpage}
69 \usepackage{fancyhdr}
70 \pagestyle{fancy} \lhead{page\thepage\ of \pageref{LastPage}}
71 \chead{} \rhead{Team \footnotesize{\#} \ldots} \lfoot{}
72 \cfoot{\thepage}%%% team control number as package option    @@ 修改队号
73 \rfoot{}
74 \renewcommand{\headrulewidth}{0pt}
75 %==================================================================
76 
77 
78 \title{\rmfamily{\textbf{The \LaTeX{} Template for MCM}}}
79 \author{Wzlf11\and Wang Yong \and Ping Li}
80 \date{\today}
81 
82 
83 \begin{document}
84 \maketitle
85 \input{abstract.tex}                                              %
86 \newpage                                                          %
87 \tableofcontents                                                  %
88 \thispagestyle{plain}                                             %
89 \newpage                                                          %
90 \input{body.tex}
91 
92 \end{document}

Abstract.tex

 1 \begin{abstract}
 2 \addcontentsline{toc}{section}{Abstract}
 3 
 4 \thispagestyle{empty}
 5 
 6 But they also provided an early glimpse at the complex set of
 7 tradeoffs facing party leaders, from their desire to make their
 8 own influence felt to their worries about offending the candidates
 9 and particular constituencies not to mention the long, sometimes
10 troubled relationship between Mr. Gore and the Clintons.
11 
12 The issues party leaders are grappling with, they said, include
13 how to avoid the perception of a back-room deal that thwarts the
14 will of millions of voters who have cast ballots in primaries and
15 caucuses. That perception could cripple the eventual Democratic
16 nominee¡¯s chances of winning the presidency in November, they
17 said.
18 \end{abstract}

body.tex

  1 %======================问题介绍====================================
  2 \section{Introduction}
  3 
  4 \begin{figwindow}[0,r,{\includegraphics[width=4in]{./picture/aaa.eps}},
  5 {The figure}] She said the nomination should not be decided by
  6 delegates from Florida and Michigan allocated on the basis of
  7 voting in primaries there last month, as the Clinton campaign has
  8 proposed. Mrs. Clinton got more votes in both places, although
  9 neither candidate actively campaigned there and Mr. Obama was not
 10 even on the ballot in Michigan. The party had penalized those
 11 states for holding their primaries earlier than the party wanted
 12 by stripping them of their delegates to the convention.Although
 13 Mr. Gore has expressed concerns to some associates about the
 14 damage a brokered convention could cause, several associates said
 15 he was hopeful that one candidate would soon break through,
 16 sparing the party such an outcome. He told a close friend recently
 17 that his decision not to endorse “feels like the right thing”
 18 and that he remained optimistic the race “is going to tip at some
 19 point,” the friend said.
 20 \end{figwindow}
 21 
 22 
 23 
 24 Although Mr. Gore has expressed concerns to some associates about
 25 the damage a brokered convention could cause, several associates
 26 said he was hopeful that one candidate would soon break through,
 27 sparing the party such an outcome. He told a close friend recently
 28 that his decision not to endorse “feels like the right thing”
 29 and that he remained optimistic the race “is going to tip at some
 30 point,” the friend said.
 31 
 32 \begin{tabular}{|l||*{5}{c|}}\hline
 33 \backslashbox{Room}{Date}
 34 &\makebox[3em]{5/31}&\makebox[3em]{6/1}&\makebox[3em]{6/2}
 35 &\makebox[3em]{6/3}&\makebox[3em]{6/4}\\\hline\hline
 36 Meeting Room &&&&&\\\hline
 37 Auditorium &&&&&\\\hline
 38 Seminar Room &&&&&\\\hline
 39 \end{tabular}
 40 \begin{longtable}{|c|c|c|c|}\hline
 41   1 & Amesville Rockets & 19 & 13\\\hline
 42   1 & Amesville Rockets & 19 & 13\\\hline
 43   1 & Amesville Rockets & 19 & 13\\\hline
 44   1 & Amesville Rockets & 19 & 13\\\hline
 45   1 & Amesville Rockets & 19 & 13\\\hline
 46   1 & Amesville Rockets & 19 & 13\\\hline
 47   1 & Amesville Rockets & 19 & 13\\\hline
 48   1 & Amesville Rockets & 19 & 13\\\hline
 49   1 & Amesville Rockets & 19 & 13\\\hline
 50   1 & Amesville Rockets & 19 & 13\\\hline
 51   1 & Amesville Rockets & 19 & 13\\\hline
 52   1 & Amesville Rockets & 19 & 13\\\hline
 53   1 & Amesville Rockets & 19 & 13\\\hline
 54   1 & Amesville Rockets & 19 & 13\\\hline
 55   1 & Amesville Rockets & 19 & 13\\\hline
 56   1 & Amesville Rockets & 19 & 13\\\hline
 57   1 & Amesville Rockets & 19 & 13\\\hline
 58   1 & Amesville Rockets & 19 & 13\\\hline
 59   1 & Amesville Rockets & 19 & 13\\\hline
 60   1 & Amesville Rockets & 19 & 13\\\hline
 61 \end{longtable}
 62 %\renewcommand{\labelitemi}{\ding{46}}
 63 \begin{itemize}
 64 \item  \ldots is constant.
 65 \item   do not affect the population.
 66 \item   have no effect on \ldots .we can ignore it.
 67 \item  \ldots is  negligible
 68 \item
 69 \item
 70 \item
 71 \end{itemize}
 72 \subsection{Other Assumptions}
 73 %\renewcommand{\labelitemi}{\ding{43}}
 74 Although Mr. Gore has expressed concerns to some associates about
 75 the damage a brokered convention could cause, several associates
 76 said he was hopeful that one candidate would soon break through,
 77 sparing the party such an outcome. He told a close friend recently
 78 that his decision not to endorse “feels like the right thing”
 79 and that he remained optimistic the race “is going to tip at some
 80 point,” the friend said.
 81 \begin{itemize}
 82 \item
 83 \item
 84 \item
 85 \item
 86 \end{itemize}
 87 \vspace{0.5cm} Under the above and basic assumptions, we can set out
 88 to construct our model (show our approach in detail).
 89 %=============================问题分析==========================================
 90 \section{Analysis of the Problem }
 91 
 92 %==================================模型建立==============================================
 93 \begin{figure}[htbp]
 94 \small
 95 \centering
 96 \includegraphics[width=12cm]{./picture/aaa.eps}
 97 \caption{aa} \label{fig:aa}
 98 \end{figure}
 99 
100 Although Mr. Gore has expressed concerns to some associates about
101 the damage a brokered convention could cause, several associates
102 said he was hopeful that one candidate would soon break through,
103 sparing the party such an outcome. He told a close friend recently
104 that his decision not to endorse “feels like the right thing”
105 and that he remained optimistic the race “is going to tip at some
106 point,” the friend said.
107 
108 
109 
110 \[
111 \left( {\begin{array}{*{20}c}
112    {a_{11} } & {a_{12} } & {a_{13} }  \113    {a_{21} } & {a_{22} } & {a_{23} }  \114    {a_{31} } & {a_{32} } & {a_{33} }  \115 \end{array}} \right) = \frac{{Opposite}}{{Hypotenuse}}\cos ^{ - 1} \theta \arcsin \theta
116 \]
117 Although Mr. Gore has expressed concerns to some associates about
118 the damage a brokered convention could cause, several associates
119 said he was hopeful that one candidate would soon break through,
120 sparing the party such an outcome. He told a close friend recently
121 that his decision not to endorse “feels like the right thing”
122 and that he remained optimistic the race “is going to tip at some
123 point,” the friend said.
124 
125 \[
126 p_{j}=\begin{cases} 0,&\text{if $j$ is odd}\127 r!\,(-1)^{j/2},&\text{if $j$ is even}
128 \end{cases}
129 \]
130 Although Mr. Gore has expressed concerns to some associates about
131 the damage a brokered convention could cause, several associates
132 said he was hopeful that one candidate would soon break through,
133 sparing the party such an outcome. He told a close friend recently
134 that his decision not to endorse “feels like the right thing”
135 and that he remained optimistic the race “is going to tip at some
136 point,” the friend said.
137 \[
138 \arcsin \theta  =
139 \mathop{{\int\!\!\!\!\!\int\!\!\!\!\!\int}\mkern-31.2mu
140 \bigodot}\limits_\varphi
141  {\mathop {\lim }\limits_{x \to \infty } \frac{{n!}}{{r!\left( {n - r}
142  \right)!}}} \eqno (1)
143 \]
144 
145 
146 
147 
148 \section{Calculating and Simplifying the Model  } ``A is equivalent
149 to B‘‘ Although Mr. Gore has expressed concerns to some associates
150 about the damage a brokered convention could cause, several
151 associates said he was hopeful that one candidate would soon break
152 through, sparing the party such an outcome. He told a close friend
153 recently that his decision not to endorse “feels like the right
154 thing” and that he remained optimistic the race “is going to tip
155 at some point,” the friend said.
156 
157 
158 
159 %===============================模型结果============================================
160 \section{The Model Results}
161 Although Mr. Gore has expressed concerns to some associates about
162 the damage a brokered convention could cause, several associates
163 said he was hopeful that one candidate would soon break through,
164 sparing the party such an outcome. He told a close friend recently
165 that his decision not to endorse “feels like the right thing”
166 and that he remained optimistic the race “is going to tip at some
167 point,” the friend said.
168 
169 
170 %========================模型的实效分析(适应性说明)=============================
171 
172 \section{Validating the Model}%确认模型,使之合理。
173 Although Mr. Gore has expressed concerns to some associates about
174 the damage a brokered convention could cause, several associates
175 said he was hopeful that one candidate would soon break through,
176 sparing the party such an outcome. He told a close friend recently
177 that his decision not to endorse “feels like the right thing”
178 and that he remained optimistic the race “is going to tip at some
179 point,” the friend said. Although Mr. Gore has expressed concerns
180 to some associates about the damage a brokered convention could
181 cause, several associates said he was hopeful that one candidate
182 would soon break through, sparing the party such an outcome. He
183 told a close friend recently that his decision not to endorse
184 “feels like the right thing” and that he remained optimistic the
185 race “is going to tip at some point,” the friend said.
186 
187 
188 Although Mr. Gore has expressed concerns to some associates about
189 the damage a brokered convention could cause, several associates
190 said he was hopeful that one candidate would soon break through,
191 sparing the party such an outcome. He told a close friend recently
192 that his decision not to endorse “feels like the right thing”
193 and that he remained optimistic the race “is going to tip at some
194 point,” the friend said.
195 
196 \section{Conclusions}
197 Although Mr. Gore has expressed concerns to some associates about
198 the damage a brokered convention could cause, several associates
199 said he was hopeful that one candidate would soon break through,
200 sparing the party such an outcome. He told a close friend recently
201 that his decision not to endorse “feels like the right thing”
202 and that he remained optimistic the race “is going to tip at some
203 point,” the friend said.
204 \section{A Summary    }
205 Although Mr. Gore has expressed concerns to some associates about
206 the damage a brokered convention could cause, several associates
207 said he was hopeful that one candidate would soon break through,
208 sparing the party such an outcome. He told a close friend recently
209 that his decision not to endorse “feels like the right thing”
210 and that he remained optimistic the race “is going to tip at some
211 point,” the friend said.
212 %================================总体评价==============================
213 \section{Evaluate of the Mode}
214 
215 %======================================================================
216 \section{Strengths and weaknesses}
217 Like any model,the one present above has its strengths and
218 weaknesses. Some of the major points are presented below.
219 
220 %============================模型=优点====================================
221 \subsection{Strengths}
222 \begin{itemize}
223 \item \textbf{Applies widely}\224 This  system can be used for many types of airplanes, and it also
225 solves the interference during  the procedure of the boarding
226 airplane,as described above we can get to the  optimization
227 boarding time.We also know that all the service is automate.
228 \item \textbf{Improve the quality of the airport service}\229 Balancing the cost of the cost and the benefit, it will bring in
230 more convenient  for airport and passengers.It also saves many
231 human resources for the airline. \item \textbf{}
232 \end{itemize}
233 
234 
235 
236 
237 \begin{thebibliography}{99}
238 \addcontentsline{toc}{section}{References}
239 
240 \bibitem{1} D. E. KNUTH  ``\, The \TeX{}book \,‘‘ the American
241 Mathematical Society and Addison–Wesley
242 Publishing Company , 1984-1986.
243 \bibitem{2}Lamport, Leslie,  \LaTeX{}: `` A Document Preparation System ‘‘,
244 Addison-Wesley Publishing Company, 1986.
245 \end{thebibliography}
246 
247 %====================附录导入程序代码==========================================
248 \appendix{\textbf{\Large{Appendix A}}
249 \addcontentsline{toc}{section}{Appendix}
250 \newline
251 Here are simulation programmes we used in our model as follow.\252 
253 
254 \textbf{\textcolor[rgb]{0.98,0.00,0.00}{Input matlab source:}}
255 \lstinputlisting[language=Matlab]{./code/matlab1.m}
256 
257 \textcolor[rgb]{0.98,0.00,0.00}{\textbf{Input C++ source:}}
258 \lstinputlisting[language=C++]{./code/sudoku.cpp}

matlab1.m

function [t,seat,aisle]=OI6Sim(n,target,seated)

% OI6 分组仿真的部分
%    n  分组人数
%    target 入对的顺序
%    seated 当前座位落座情况

%   t simulation time
%   seat ,seat interference 
%   aisle ,aisle interference 
 

% Initial data
% setting passengers‘ Value:   
%                   walking          .....   1
%                   waiting          .....   2
%                   putting luggage  .....   3
%                   passing the seat .....   4
%                   sitting           .....  0
 

% on initial time, everyone is waiting,except the first one 

seat=0;
aisle=0;

status=2*ones(1,n);     
status(1)=1;

%初始时刻每个人的位置
%每个人的间距为0.6 row
pos=-(0:0.6:(n-1)*0.6);



   pri=[-1,1:n-1];
   next=[2:n,-1];


RowSpeed=trirnd(0.6,0.95,1.3,1,n);

pab=rand(1,n);
for i=1:n
    if pab(i)<0.4
       aisleTime(i)=0;
    else
        aisleTime(i)=trirnd(3.2,7.1,38.7);
    end
end

% seat interference time
seatTime=trirnd(7.4,9.7,15.5);

t=0;
while sum(status) ~=0
    
    t=t + 0.1;
    for i=1:n
        
        switch status(i)
            case {0}       
                
                 if  next(i)>0 &&abs(status(next(i))-2)<0.1       
                        status(next(i))=1;
                     end
                  
%                  disp(‘have sit down‘);

            case {1}        
                 
%                  disp(‘Walking‘);
                 
                     if  next(i)>0 &&abs(status(next(i))-2)<0.1       
                        status(next(i))=1;
                     end
                  
                     
                     pos(i)=pos(i)+RowSpeed(i)*0.1;
                 
                     if abs(pos(i)-target(1,i))<0.2  
        
                         status(i)=3;
                         if abs(aisleTime(i))<0.01  
                             aisle=aisle+1;
                         end
                         
                             if  next(i)>0 &&abs(status(next(i))-1)<0.1    
                                                                     
                                 status(next(i))=2;
                         end             
                
                      end

                 
            case {2}         
                  
%                   disp(‘Blocking‘);
                  if  next(i)>0 &&abs(status(next(i))-1)<0.1    
                                                                    
                          status(next(i))=2;
                     end 

            case {3}          %put luggage     aisle interference
                
                   disp(‘aisle interference‘);
                 
                  if abs(aisleTime(i))<0.01             
                      
                    if  n==12 && target(2,i)==1 && seated(target(1,i),2)==1
                          status(i) = 4;
                          seat=seat+1;
                      elseif  n==12 && target(2,i)==4 && seated(target(1,i),3)==1
                          status(i) = 4;
                          seat=seat+1;
                      else
                          
                           status(i)=0;
                           seated(target(1,i),target(2,i)) = 1;
                      end

                  else
                      aisleTime(i)=aisleTime(i)-0.1;
                      
                  end
                  
            case {4}             % seat interference  
                
                if abs(aisleTime(i))<0.01   % 
                    status(i)=0;
                    seated(target(1,i),target(2,i)) = 1;    
                else
                    
                    seatTime(i)=seatTime(i)-0.1;
                end
                    
                    
            
        end  %switch
    end %for

end %while
   
   
   
   

matlab2.m

 1 function randomVector = trirnd(minVal, topVal, maxVal, varargin);
 2 %TRIRND generates discrete random numbers from a triangular distribution.
 3 %   randomValue = TRIRND(minVal, topVal, maxVal);
 4 %       The distribution is defined by:
 5 %           - a minimum and a maximum value
 6 %           - a "top" value, with the highest probability
 7 %       The distribution is defined with zero probability at minVal-1 and 
 8 %       maxVal+1, and with highest probability at topVal. Hence
 9 %       every value in the range (including the maximum and minimum values)
10 %       have a non-zero probability to be included, whatever topValue is.
11 %       The output is a random integer.
12 %   randomMatrix = TRIRND(minVal, topVal, maxVal, nrow, ncolumns)
13 %       returns a (nrow x ncolumns) matrix of random integers.
14 %
15 % Written by L.Cavin, 01.08.2003, (c) CSE & ETHZ
16 % This code is free to use and modify for non-commercial purposes.
17 %
18 % NOTES:
19 % * This is a numeric approximation, so use with care in "serious"
20 %   statistical applications!
21 % * Two different algorithms are implemented. One is efficient for large
22 %   number of random points within a small range (maxVal-minVal), while the
23 %   other is efficient for large range for reasonable number of points. For
24 %   large ranges, there is a O(n^2) relation with regard to the product of 
25 %   range*number_of_points. When this product reach about a billion, the
26 %   runtime reach several minutes.
27 % * To inspect the resulting distribution, plot a histogram of the
28 %   resulting random numbers, e.g. "hist(trirnd(1,87,100,10000,1),100)".
29 
30 % Version History:
31 % ----------------
32 % Version 2.0 - 20.10.2004 -- added alternate algorithm for large ranges.
33 % Version 1.5 - 14.02.2003 -- made similar to Matlab functions (nargin order
34 %                             and checks).
35 % Version 1.0 - 01.08.2003 -- initial release.
36 
37 % check arguments...
38 if nargin < 3
39     error(‘Requires at least three input arguments.‘); 
40 end
41 nrows = 1;
42 ncols = 1;
43 if nargin > 3
44     if nargin > 4
45         nrows = varargin{1};
46         ncols = varargin{2};
47     else
48         error(‘Size information is inconsistent.‘);
49     end
50 end
51 if topVal > maxVal || topVal < minVal || minVal > maxVal
52     randomVector = ones(nrows, ncols).*NaN;
53     return;
54 end
55 
56 % go for the randomization
57 mxprob = maxVal-minVal+1;
58 if mxprob < 51 || (mxprob < 101 && nrows*ncols > 500) || (mxprob < 501 && nrows*ncols > 8000) || (mxprob < 1001 && nrows*ncols > 110000)
59     vector = ones(1,mxprob).*topVal;
60     j = (topVal-minVal+1);
61     slope = 1/j;
62     j = j -1;
63     for i = (topVal-1):-1:minVal
64         vector = [vector ones(1,floor(mxprob*slope*j)).*i];
65         j = j - 1;
66     end
67     j = (maxVal+1-topVal);
68     slope = 1/j;
69     j = j -1;
70     for i = (topVal+1):maxVal
71         vector = [vector ones(1,floor(mxprob*slope*j)).*i];
72         j = j - 1;
73     end
74     randomVector = vector(unidrnd(size(vector,2),nrows*ncols,1));
75 else
76     probs = mxprob:-1*mxprob/(topVal-minVal+1):1;
77     probs = [probs(end:-1:2) mxprob:-1*mxprob/(maxVal-topVal+1):1];
78     probs = cumsum(probs./sum(probs));
79     if nrows*ncols*mxprob > 1000000
80         % dealing with large quantities of data, hard on memory
81         randomVector = [];
82         i = 1;
83         while nrows*ncols*mxprob/i > 1000000
84             i = i * 10;
85         end
86         probs = repmat(probs, ceil(nrows*ncols/i), 1);
87         for j = 1:i
88             rnd = repmat(unifrnd(0, 1, ceil(nrows*ncols/i), 1), 1, mxprob);
89             randomVector = [randomVector sum(probs < rnd, 2)+1];
90         end
91         randomVector = randomVector(1:nrows*ncols);
92     else
93         probs = repmat(probs, nrows*ncols, 1);
94         rnd = repmat(unifrnd(0, 1, nrows*ncols, 1), 1, mxprob);
95         randomVector = sum(probs < rnd, 2)+1;
96     end
97 end
98 % generate desired matrix:
99 randomVector = reshape(randomVector, nrows, ncols);
Sudoku.cpp
  1 //============================================================================
  2 // Name        : Sudoku.cpp
  3 // Author      : wzlf11
  4 // Version     : a.0
  5 // Copyright   : Your copyright notice
  6 // Description : Sudoku in C++.
  7 //============================================================================
  8 
  9 #include <iostream>
 10 #include <cstdlib>
 11 #include <ctime>
 12 
 13 using namespace std;
 14 
 15 int table[9][9];
 16 
 17 void shuffle(int arr[], int n){
 18     
 19     int tmp, rd;
 20 
 21     //打乱数组顺序
 22     for(int i = 0; i < n; i++){
 23         rd = rand() % 9;
 24         tmp = arr[rd];
 25         arr[rd] = arr[i];
 26         arr[i] = tmp;
 27     }
 28 }
 29 
 30 bool test(int x, int y, int v){
 31     
 32     int _x = x / 3 * 3;
 33     int _y = y / 3 * 3;
 34 
 35     //测试3 * 3矩阵内是否有重复的数
 36     for(int i=_x; i<_x + 3; i++)
 37     {
 38         for(int j = _y; j < _y + 3; j++)
 39         {
 40             if(table[i][j] == v)
 41             {
 42                 return false;
 43             }
 44         }
 45     }
 46 
 47     //测试横向、纵向是否有重复的数
 48     for(int m= 0; m< 9; m++)
 49     {
 50         if(table[x][m] == v || table[m][y] == v)
 51             return false;
 52     }
 53     
 54     return true;
 55 }
 56 
 57 bool put(int line, int index){
 58     
 59     if(index > 8)
 60         return true;
 61     
 62     //如果当前方格内不等于0,则跳过处理下一个方格
 63     if(table[line][index] != 0){
 64         return put(line, index + 1);
 65     }
 66     
 67     int num[] = {1,2,3,4,5,6,7,8,9};
 68     //打乱当前准备写入数字的前后顺序
 69     shuffle(num, 9);
 70     
 71     for(int i = 0; i < 9; i++){
 72         
 73         //测试数字是否允许填入当前方格
 74         if( test(line, index, num[i]) == true ){
 75 
 76             table[line][index] = num[i];
 77             
 78             //填入成功则处理下一个方格
 79             if( put(line, index + 1) == true ){
 80                 return true;
 81             }
 82         }
 83     }
 84 
 85     table[line][index] = 0; //失败后复位
 86 
 87     return false;
 88 }
 89 
 90 bool put_line(int line){
 91 
 92     if(line > 8)
 93         return true;
 94     
 95     int b[9];
 96     
 97     //备份当前一行
 98     for(int i = 0; i < 9; i++){
 99         b[i] = table[line][i];
100     }
101 
102     if( put(line, 0) == true ){
103         //当前一行添入完成后,进入下一行再重复处理。
104         if( put_line(line + 1) == true )
105             return true;
106     }
107     
108     //恢复当前一行的值
109     for(int n = 0; n < 9; n++){
110         table[line][n] = b[n];
111     }
112     
113     return false;
114 }
115 
116 int main() {
117 
118     //表格首行填入初始值
119     for(int i = 0; i < 9; i++){
120         table[0][i] = i + 1;
121     }
122 
123     srand((unsigned int)time(NULL));
124     //打乱表格首行次序
125     shuffle((int *)&table[0], 9);
126 
127     //从第二行开始添入数字
128     while(!put_line(1))
129     {
130         //失败重新开始
131         shuffle((int *)&table[0], 9);
132     }
133     
134     //最后显示
135     for(int x = 0; x < 9; x++){
136         for(int y = 0; y < 9; y++){
137             cout << table[x][y] << " ";
138         }
139         
140         cout << endl;
141     }
142 
143     return 0;
144 }

 

MCM论文模板

标签:des   style   blog   http   color   io   os   ar   java   

原文地址:http://www.cnblogs.com/jinliangjiuzhuang/p/4010359.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!