www.bersaty.com

02 2012 档案

摘要:个仅由红、白、蓝这三种颜色的条块组成的条块序列。请编写一个时间复杂度为O(n)的算法,使得这些条块按蓝、白、红的顺序排好例如: R,B,B,W,W,B,R,B,W排序后:B,B,B,B,W,W,W,R,Rvoid Three_color_flag(int color[], int n ) //排序为蓝,白,红 { int white = 0 ; int blue = 0 ; int red = n - 1 ; while(white <= red) { if(color[white] == WHITE)... 阅读全文
posted @ 2012-02-26 00:33 bersaty 阅读(990) 评论(0) 推荐(0) 编辑
摘要:// 马走棋盘.cpp : Defines the entry point for the console application.//#include "stdafx.h"#includeint maze[8][8],n,x,y; //x,y开始坐标,n维数 int mx[8]={-2,-2,-1,1,2,2,1,-1};//方向 int my[8]={-1,1,2,2,1,-1,-2,-2};int cnt=0;//记录路径数量 bool check(int x,int y){ return (maze[x][y]==0&&x>=0&&am 阅读全文
posted @ 2012-02-23 20:00 bersaty 阅读(510) 评论(0) 推荐(0) 编辑
摘要:void quicksort(int arry[],int left,int right){ int i=left,j=right,key=arry[left]; while(i=key) j--; arry[i]=arry[j]; while(i<j&&arry[i]<=key) i++; arry[j]=arry[i]; } arry[i]=key; if(i-left) quicksort(arry,left,i-1); if(right-i) quicksort(arry,i+1,right);} 阅读全文
posted @ 2012-02-23 18:18 bersaty 阅读(200) 评论(0) 推荐(0) 编辑
摘要:int maze[m+1][n+1];//迷宫数组int sx[m*n+1]; //保存路径int sy[m*n+1];int dx[4]={0,0,1,-1}; //方向 int dx[4]={1,-1,0,0};void gomaze(int step,int x,int y) //x,y当前坐标,step要走第几步{ int i; sx[step]=x;sy[step]=y;//保存当前坐标 if(x==m&&y==n)//走到出口,打印路径 { for(i=1;i=1&&x=1)//如果可行,递归继续 gomze(step+1,nx,ny); }} 阅读全文
posted @ 2012-02-23 18:11 bersaty 阅读(287) 评论(0) 推荐(1) 编辑
摘要:题目http://acm.hdu.edu.cn/showproblem.php?pid=1166度娘的 树状数组 http://baike.baidu.com/view/1420784.htm弄了一个下午,算是明白了点看了一些牛人的代码后的翻版。。#includeusing namespace std;int tr[500005],n;int lowbit(int a){return a&-a;}//找位置 int quy(int i) //计算前i项和 { int ans=0; for(;i>0;i-=lowbit(i)) ans+=tr[i]; retu... 阅读全文
posted @ 2012-02-06 21:30 bersaty 阅读(282) 评论(0) 推荐(0) 编辑
摘要:Catch That Cowhttp://poj.org/problem?id=3278RE了N次,终于过了,数组开小了= =。。顺便联系队列#includestruct point { int pos;}queue[200001];int head=0,tail=0;bool mat[200001]={0};int step[200001];bool is_empty(){ return head==tail; }point dequeue(){ return queue[head++];}void enqueue(point p){ queue[tail++]... 阅读全文
posted @ 2012-02-03 16:37 bersaty 阅读(201) 评论(0) 推荐(0) 编辑
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2544继续研究,dijkstra 和 bellmanford 算法#includeint main(){ int n,m,a,b,c; //freopen("in.txt","r",stdin); while(scanf("%d%d",&n,&m)!=EOF&&(n||m)) { int maze[101][101]={0}; while(m--) { scanf("%d%d%d",&a,& 阅读全文
posted @ 2012-02-01 17:33 bersaty 阅读(227) 评论(0) 推荐(0) 编辑
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1014题目看了好久,终于看完了,发现是群论里的,离散也差多忘了。。。说白了就是求生成元,求mod N的生成元,即生成元与N互质就OK了#include<iostream>int gcd(int a,int b){ if(!b) return a; return gcd(b,a%b);}int main(){ int s,m; while(scanf("%d%d",&s,&m)!=EOF) { if(gcd(s,m)==1) printf("%10d%1 阅读全文
posted @ 2012-02-01 10:46 bersaty 阅读(1396) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示