随笔分类 -  zoj

摘要:状态压缩dp#include#include#include#define maxn 4100using namespace std;int map[13][13];int dp[maxn][510];int gcd(int x,int y){ return y==0?x:gcd(y,x%y)... 阅读全文
posted @ 2014-04-22 16:59 Yours1103 阅读(220) 评论(0) 推荐(0)
摘要:一道区间更新、查询的题;但是线段树不能做插入;后来才知道用splay;splay用来做区间查询的话,先将l-1旋转到根节点,然后把r+1旋转到根节点的右节点;这样的话,根节点的右节点的左子树就是我们要的区间;我的代码是网上大神的代码改了一下过来的,存着做模板;#include#include#include#define maxn 2000009#define lch(rt) son[rt][0]#define rch(rt) son[rt][1]using namespace std;int son[maxn][2],fa[maxn],size[maxn],val[maxn],st[maxn 阅读全文
posted @ 2014-03-04 13:42 Yours1103 阅读(198) 评论(0) 推荐(0)
摘要:3757一个模拟题,简单,但容易错;3758 大素数判定就行;#include#include#include#define maxn 100009using namespace std;int ans[3];int hit[maxn];int in[maxn];int ball[maxn];bool vis[maxn];int main(){ int n,m; int p,q; while(scanf("%d%d",&n,&m)!=EOF) { ans[0]=0; ans[1]=0; memset(vis,0,sizeof v... 阅读全文
posted @ 2014-03-02 23:11 Yours1103 阅读(268) 评论(0) 推荐(0)
摘要:很简单但很虐心的一道题;我感觉自己的算法没错,但是老是过不了;= =但是还是把代码贴出来;我的方法,用并查集的方式做一课树,然后对树进行遍历;有多少棵树就有多少个点剩余;#include#include#include#define inf 1000000000#define maxn 2009using namespace std;struct node{ int x; int y; int p; int sum; int son[5]; bool operator =4)flag=0; return flag;}void dfs(int root)... 阅读全文
posted @ 2014-03-02 23:07 Yours1103 阅读(272) 评论(0) 推荐(0)
摘要:题目给我们四个点,要求我们以这四个点为圆心,形成四个相切的圆;求他们的半径和;首先我们从他们中间选出三个点,以这三个点为圆心的三个圆最大可以两两互相相切;证明:假设这三个圆的半径分别为a,b,c,那么形成的三条边分别长为:a+b,a+c,b+c,他们两两之和大于第三边;然后从第四个点出发的圆必定和前面三个的一个或多个相切;所以这个问题就转化成为三对边和的比较;代码: 1 #include 2 #include 3 #include 4 using namespace std; 5 double dis(double x1,double y1,double x2,double y2) 6 { 7 阅读全文
posted @ 2013-11-11 19:45 Yours1103 阅读(123) 评论(0) 推荐(0)
摘要:又是个水题,刚刚开始没有用搜索,因为对于反素数有:n=2^t1*3^t2^5^t3*7^t4..... 这里有 t1>=t2>=t3>=t4。而且相同的因数的情况下,素数越不同越好。哪知道这个方法错了! = =。看来还得中规中矩得用dfs。我觉得还可以优化下,感觉搜索干了很多无用的活儿。搜索还得好好练练啊... 1 #include 2 #define LL long long 3 using namespace std; 4 int prim[16] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47 }; 阅读全文
posted @ 2013-08-25 21:31 Yours1103 阅读(177) 评论(0) 推荐(0)