2011年7月8日

sicily 1002. Anti-prime Sequences

摘要: // 题意: 给出n,m,d,元素的取值从n到m,要求满足在序列中任意(2,3,...d)个数的和都不是素数,// 如果存在则输出字典序最小的序列,其中 1<=n<m<=1000, 2<=d<=10#include<iostream> // DFS #include<stdio.h>#include<cstring>#include <math.h>using namespace std;int n,m,d;int arr[1010],vis[1010],ok;int is_prime(int a){ for(int 阅读全文

posted @ 2011-07-08 21:22 sysu_mjc 阅读(240) 评论(0) 推荐(0) 编辑

sicily 1935. 二叉树重建

摘要: #include <iostream> //根据先序遍历序列和中序遍历序列建立二叉树,并按层遍历#include <string>using namespace std;string str1,str2;int n;struct Node { char ch; Node *left,*right;}node[5000];Node* built(int s1,int t1,int s2,int t2) //根据先序遍历序列和中序遍历序列建二叉树{ int m=n++; //声明为局部变量 node[m].ch=str1[s1]; ... 阅读全文

posted @ 2011-07-08 20:56 sysu_mjc 阅读(398) 评论(2) 推荐(0) 编辑

sicily 1156. Binary tree

摘要: #include<iostream> //给出一棵二叉树,输出前序遍历序列#include<stack>using namespace std;struct node{ char c; int l,r;}tree[1010];int vis[1010],rt[1010];void add(int p,char c,int l,int r) //满足vis[p]==1且rt[p]==1 是根结点{ tree[p].c=c; vis[p]=1; if(l>0) { tree[p].l=l;vis[l]=1;rt[l]=0; //左右结点可以确定不是根结点 } if(r 阅读全文

posted @ 2011-07-08 18:22 sysu_mjc 阅读(237) 评论(0) 推荐(0) 编辑

sicily 1934. 移动小球

摘要: //刘汝佳的《算法竞赛入门经典》P95#include<iostream>//双向链表,强调小球之间的相对顺序,而非绝对顺序usingnamespacestd;intl[500010],r[500010];//l[i],r[i]分别记录编号i的小球的左边left和右边right的小球编号voidlink(intx,inty)//x,y成为邻居,即right[x]=y;left[y]=x,x在y左边{r[x]=y;l[y]=x;}intmain(){intt,n,m,tag,x,y;cin>>t;while(t--){cin>>n>>m;for(i 阅读全文

posted @ 2011-07-08 14:21 sysu_mjc 阅读(314) 评论(0) 推荐(0) 编辑

导航