没有合适的资源?快使用搜索试试~ 我知道了~
PTA编程啊啊啊啊啊啊啊啊啊
资源推荐
资源详情
资源评论
7-1 快速排序
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int q[N];
void quick_sort(int q[], int l, int r) {
if (l >= r) return;
int i = l - 1, j = r + 1, x = q[l + r >> 1];
while (i < j) {
do i ++ ; while (q[i] < x);
do j -- ; while (q[j] > x);
if (i < j) swap(q[i], q[j]);
}
quick_sort(q, l, j), quick_sort(q, j + 1, r);
}
int main() {
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) {
scanf("%d",&q[i]);
}
quick_sort(q,0,n-1);
for(int i=0;i<n-1;i++) {
printf("%d ",q[i]);
}
printf("%d",q[n-1]);
return 0;
}
7-2 棋盘覆盖问题
#include <iostream>
#include<fstream>
#include <iomanip>
#define MAX 1025
using namespace std;
int board[MAX][MAX];
int tile=1;
void ChessBoard(int tr,int tc,int dr,int dc,int size)
{ if(
size==1
) return; //递归出口
int t=tile++; //取一个 L 型骨,其牌号为 tile
int s=size/2; //分割棋盘
//考虑左上角象限
if(
dr<tr+s && dc<tc+s
) //特殊方格在此象限中
ChessBoard ( tr, tc, dr, dc, s )
;
else //此象限中无特殊方格
{
board[tr+s-1][tc+s-1]=t
; //用 t 号 L 型骨牌覆盖右下角
ChessBoard ( tr, tc, tr+s-1, tc+s-1, s )
; //将右下角作为特殊方格继续处理该象限
}
//考虑右上角象限
if(
dr<tr+s && dc>=tc+s
)
ChessBoard ( tr, tc+s, dr, dc, s )
; //特殊方格在此象限中
else //此象限中无特殊方格
{
board[tr+s-1][tc+s]=t
; //用 t 号 L 型骨牌覆盖左下角
ChessBoard ( tr, tc+s, tr+s-1, tc+s, s )
; //将左下角作为特殊方格继续处理该象限
}
//处理左下角象限
if(
dr>=tr+s && dc<tc+s
) //特殊方格在此象限中
ChessBoard ( tr+s, tc, dr, dc, s )
;
else //此象限中无特殊方格
{
board[tr+s][tc+s-1]=t
; //用 t 号 L 型骨牌覆盖右上角
ChessBoard ( tr+s, tc, tr+s, tc+s-1, s )
; //将右上角作为特殊方格继续处理该象限
}
//处理右下角象限
if(
dr>=tr+s && dc>=tc+s
) //特殊方格在此象限中
ChessBoard ( tr+s, tc+s, dr, dc, s )
;
else //此象限中无特殊方格
{
board[tr+s][tc+s]=t
; //用 t 号 L 型骨牌覆盖左上角
ChessBoard ( tr+s, tc+s, tr+s, tc+s, s )
; //将左上角作为特殊方格继续处理该象限
}
}
int main()
{
int dr,dc,size;
int j,i;
cin>>size;
cin>>dr>>dc;
ChessBoard(0,0,dr,dc,size);
for(i=0;i<size;i++){
cout<<left;
for(j=0;j<size;j++)
{
cout<<setfill(' ')<<setw(5)<<board[i][j];
}
cout<<endl;
}
return 0;
}
剩余11页未读,继续阅读
资源评论
蜡笔不小心了
- 粉丝: 2
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功