自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

\*zyeric*/

呼啦啦

  • 博客(131)
  • 收藏
  • 关注

原创 Codeforces Round #263 (Div. 1)

56.Codeforces 461 A. Appleman and Toastman:简单的贪心.57.Codeforces 461 B. Appleman and Tree题意:给定一棵包含n个节点的树,这棵树的一些节点(至少一个)被染成黑色,现在可以删除一些边,使得删完边后的每个联通分量中恰好只有一个黑色节点.问满足条件的方案数一共有多少(对1e9+7取mod).解法:树形

2014-11-05 11:05:02 499

原创 网络教室 Xor Sum

给定n个数,求取若干个数,使得这些数异或和最大.贪心:按位从高到低进行处理,若某一个数的第i位的值是1,则将其他第i位上是1的数都与之异或,可以证明这样贪心地做是正确的,顺带提一句,这样的过程很像gauss消元.

2014-11-03 22:30:47 403

原创 网络教室 树上不同直径的数目

先预处理出一条树的直径,注意直径上中点的处理

2014-11-03 22:29:33 473

原创 432 C. Prime Swaps

题意:给定一个n的排列(n解法:每次把i和在i位置上的数尝试交换.由哥德巴赫猜想,一个数最多被分为3个质数之和.按照这个进行构造.

2014-11-03 22:17:34 598

原创 432 D. Prefixes and Suffixes

简单的后缀数组.

2014-11-03 22:16:18 402

原创 480 C. Riding in a Lift

蛮简单的dp.

2014-11-03 08:24:00 396

原创 HDU 4808 Drunk

题意:给定一个n维欧几里德空间中的一个n维向量(x1,x2,..,xn),xi>=0,sigma(xi^2)<=R^2.问xi最小值的期望.解法:注意到空间球体的强对称性,即求x方向上的期望.这可以通过积分得出.在积分的过程中注意可以假设n维球体的体积为Vn=Pn*R^n.

2014-11-03 08:22:15 1136

原创 HDU 4809 Cirno’s Present

非常值得一做的树形dp.题意:给定一棵树(n<=300),你可以给每个节点等概率地染成A,B,C三种颜色之一,对于树上的一条边,若其两个端点的颜色不一样,则断开这条边.最后对于一个特定的颜色,X为点数为奇数的联通块个数,Y是点数为偶数的联通块个数,其得分为max(0,X-Y).问最后得分的期望乘上3^n mod 1e9+7的值.解法:注意到颜色的对称性,我们只需要求出每个颜色的期望再乘上3

2014-11-03 08:20:06 1007

原创 HDU 4812 D Tree

点分治,乘法逆元.题意:给定一棵树(n<=10^5),每个节点都有权值.问是否存在一条从u到v的路径,使得路径上的点的乘积mod上(1e6+3)为给定的k.解法:树上的点分治,选取一点作为重心,则在当前的树中的答案可能有以下几种情况:1.u,v在同一棵子树中.2.u,v在不同的子树中(u,v一定经过重心).3.u,v中有一点是重心.第一种情况可以递归解决,2,3种情况需要记

2014-11-02 22:30:16 381

原创 HDU 4804 Campus Design

轮廓线动态规划.状态比较好想,注意转移状态以及位运算.状态转移方式见代码.#include #include const int MOD = 1000000007;inline void add(int &x, int y){ x += y; while (x >= MOD) x -= MOD;}int dp[2][1 << 10][25];int

2014-11-02 22:27:56 365

原创 HDU 5072 Coprime

容斥原理,从反面想,就是红蓝三角形的计数。

2014-11-02 22:26:39 312

原创 482 A. Diverse Permutation

构造#include #include const int MAXN = 100005;int a[MAXN];int main(){ int n, k; scanf("%d%d", &n, &k); a[1] = 1; int sgn = 1; for (int i = 2; i <= k + 1; i ++) { a[

2014-11-02 22:25:10 343

原创 482 B. Interesting Array

构造,ST表.#include #include const int MAXN = 100005;const int MAX_LOG = 17;struct query{ int l, r, v;};int n, m;query q[MAXN];int a[30][MAXN];int pre_log[MAXN];int st[MAXN][MAX_LOG];

2014-11-02 22:24:10 364

原创 482 C. Game with Strings

题意:给定n个长度为m的串(n<=50,m<=20),保证每个串互不相同.每次可以问目标串一个位置上的字母,问最终猜出目标串的期望次数.解法:状态压缩dp.Let dp[mask] be the expected number of questions from state mask. When we try to ask question pos in state mask, the c

2014-11-02 22:22:10 456

原创 482 D. Random Function and Tree

题意:给定一棵树,初始状态下所有树的节点都是红色,现在按照下述程序递归对树进行染色,问所有染色的方法数.染色方法:int p(){}//等可能地返回0和1int count;//全局变量,初始值为0.void paint(s){ int v = p(); if(v == 0) 将点s染为白色. else 将点s染为黑色. v = p(); if(v ==

2014-11-02 22:20:39 542

原创 477 A. Dreamoon and Sums

没什么好说的。

2014-11-02 22:18:49 435

原创 477 B. Dreamoon and Sets

没什么好说的。#include #include #include #include #include #include #include #include #include #include using namespace std;typedef long long ll;int MAIN(){ ll n, k; cin >> n >> k;

2014-11-02 22:18:03 409

原创 477 C. Dreamoon and Strings

题意:给定字符串s,t.问s串删除k个字符后,最多有多少个互不相交的子序列和p相等.解法:dp[i][j]:字符s[i]之前删除了j个字符后的答案.对于s[i]的每一位设置一个转移位点to[i],表示以s[i]开始的串匹配t的最后一个位置加上1.dp转移方程:dp[i+1][j]=max(dp[i+1][j],dp[i][j])//这一步主要是为了那些不在to[]中的位点更新值.

2014-11-02 22:16:01 798

原创 477 D. Dreamoon and Binary

好久不写CSDN了,

2014-11-02 22:14:17 665

原创 448 E. Divisors

#include #include #include using namespace std;const int maxn = 1e5;#define LL long longvector divi;vector ans;void solve(LL x,LL k){ if(x==1) { ans.push_back(1);

2014-08-04 01:05:21 651

原创 449 C. Jzzhu and Apples

/* 贪心算法,对于大素数的倍数,如果倍数的个数是奇数个,可以考虑将2*素数这个值空开,留给2来匹配 */#include #include using namespace std;//线性素数筛法const int N = 100010;int prime[N] = {0},num_prime = 0;int isNotPrime[N] = {1, 1};void prod

2014-08-04 01:01:51 358

原创 444 C DZY Loves Colors

/* 线段树,注意传递参数的写法 */#include #include using namespace std;#define LL long longconst int maxn = 1e5 + 10;LL lazy[maxn<<2];LL delta[maxn<<2];//代表一个根节点的历史改变量之和,解决一个区间被多次覆盖的问题LL sum[maxn<<2];/

2014-08-04 00:58:31 485

原创 451 E. Devu and Flowers

/* 生成函数题. 题意:有n份物品(n<=20),每份物品为fi个. 问从中取s个的方法种数. 总的方法数可以利用生成函数表示: (1+x+x^2+...+x^f1)*...(1+x+x^2+...+x^fn)中x^s的系数即为所求 该生成函数可化简为(利用几何级数):(1-x^(f1+1))*..(1-x^(fn+1))/(1-x)^n 其中分母可以表示为(1-x)^n=(1+x

2014-08-04 00:58:10 406

原创 Codeforces 441 E. Valera and Number

/* Codeforces 441 E. Valera and Number 题意:给定三个整数,x,k,p.进行k轮操作,每轮有p%的可能性将x乘上2,有(100-p)%的可能性把x加上1,问最后x的二进制表示中末尾有多少个零的期望. 解法:dp解决,dp[k][i][j]表示进行k轮后,后八位是j并且后八位之前连续的1或者0的长度.(之所以定义为八位是因为考虑到加法操作再怎么影响,也只有

2014-08-04 00:54:09 460

原创 403 D. Beautiful Pairs of Numbers

/* 题意:给定n和k,问满足1<=a1<=b1<a2<=b2<a3<=b3<...<ak<=bk<=n,并且b1-a1,b2-a2,b3-a3...bk-ak互不相同的组数. 假设x1=b1-a1,x2=b2-a2,x3=b3-a3,...,xk=bk-ak 则可以得到a1+x1+...+xk+k-1<=n,我们要求它的非负整数解 也就是要求x1+x2+...+xk<=n-a1+1的正整

2014-08-04 00:53:43 440

原创 439 D. Devu and his Brother

/* 简单三分法解决,也可以排序后简单贪心. */#include #include #include using namespace std;const int maxn = 100000 + 100;#define LL long longint n,m;LL a[maxn],b[maxn];bool cmp(int a,int b){ return a>b;

2014-07-26 00:09:31 460

原创 424 B. Megacity

/* 按距离排序后直接模拟 */#include #include #include #include using namespace std;#define LL long longstruct point{ LL x,y; int k;};bool cmp(const point &p,const point &q){ return p.x*

2014-07-26 00:07:12 604

原创 431 D. Random Task

/* 简单组合数与二分. 我们二分判定答案n. 对于一个n,我们判定从n+1到2*n的满足条件的数 其实我们就是求一个前缀,就是f(2*n)-f(n). 这一步可以直接模拟并组合数解决 */#include #include #include #define LL long longusing namespace std;LL m;int k;int a[100];

2014-07-26 00:05:55 369

原创 446 C. DZY Loves Fibonacci Numbers

/* 感叹自己的代码能力实在是很差. 非常不错的题目 给定一列数,定义操作: 从一段数从头开始逐次加上f1,f2,f3,...,f(r-l+1). 利用线段树解决. 首先将连续的Fibonacci数通项公式转化为离散化的,利用二次剩余以及乘法逆元. 那么,对于一个区间的加和操作可以理解为对一个区间几何级数系数的维护. 这个可以利用线段树轻松解决. */#include #inc

2014-07-26 00:05:46 597

原创 447 C. DZY Loves Sequences

/* 题意,给定序列,问如果给你一次机会修改一个数,则该序列的最长上升子串是什么 对于ai,我们可以预处理出ai-1往左的最长下降序列,以及ai+1向右的最长上升序列 直接维护答案即可. */#include #include #include using namespace std;const int maxn = 100000 + 100;int a[maxn];in

2014-07-26 00:00:50 437

原创 451 A. Game With Sticks

#include #include #include using namespace std;int solve(int n,int m){ if(n<m) swap(n,m); if(m==1) return 1; return 1-solve(n-1,m-1);}int main(){ int n,m; scanf("%d%d",&

2014-07-25 23:59:28 420

原创 451 B. Sort the Array

/* 直接模拟判断即可,也可以排序进行判断 注意边界情况 */#include #include #include using namespace std;int a[100100];int main(){ int n; scanf("%d",&n); for(int i=0;i<n;++i) scanf("%d",&a[i]);

2014-07-25 23:56:12 330

原创 451 D. Count Good Substrings

/* 自己想了一个比较复杂的dp过程,有四个状态... 然后看了一下rank1的代码.感觉智商被碾压了. 考虑对a,b在奇偶位置上进行计数 则长度为奇数的就是在同一类里面任意选两个(包括自身) 长度为偶数的就需要奇偶对应着选 */#include #include #include using namespace std;char s[100100];#define

2014-07-25 23:54:40 399

原创 451 C. Predict Outcome of the Game

/* 注意到对于k场比赛,如果a,b,c队胜场差是x1,x2,x3时,设a队胜场为t,则有t+t-x1+t-x1-x2=k,判断即可 注意是绝对值 */#include #define LL long longbool judge(LL n,LL k,LL d1,LL d2){ if((k+2*d1+d2)%3!=0) return 0; LL x=(k+2*

2014-07-25 23:54:28 396

原创 439 E. Devu and Birthday Celebration

/* 题目大意:有n个物品,分成f份,这f份的最大公约数是1的种类数目 记答案为P(n,f,1) 则有sigma(P(n,f,i)) = C(n-1,f-1)(n件物品分为f份的总方法数) 注意到P(n,f,i) = P(n/i,f,1). 我们可以记P(n,f,1)为g(n,f) 则有sigma(d|n) g(d,f) = C(n-1,f-1). 令右边为f(n,f) 则可以利用

2014-07-25 23:53:41 440

原创 449 D. Jzzhu and Numbers

/* 容斥原理... 题意:给定n个数(n<=10^6),ai<=10^6.问有多少种选取方式使得ai1^ai2^...^aik=0. i1<i2<...<ik 考虑对x,有多少个ai使得ai&x=x,令此等于f(x),再令g(x) = x二进制表示中1的个数 则最后的答案为sigma(0<=x<(1<<20))(-1)^g(x)*2^(f(x)). 是容斥原理逐步淘汰的形式(也就是求

2014-07-25 23:50:06 710

原创 HDU 4832 Chess

/* dp预处理再加组合数 题意:在n*m的格子上有一个棋子,它的移动规则(设初始点为(x,y)):可以移到(x+1,y),(x+2,y),(x-1,y),(x-2,y),(x,y+1),(x,y+2),(x,y-1),(x,y-2) 解法:n^2 dp预处理,再组合数求解. 先dp预处理出横向和纵向走i步的总的方法数,则最后答案为sigma(C(k,i)*e[i]*f[i]) 注

2014-07-21 20:04:56 377

原创 POJ 2482 Stars in Your Window

//矩形面积并//注意数据范围,虽然坐标x,y在int范围内,但是当x+W,y+H时,可能会超出int//当不考虑点在边界上时,矩形为(x,y)~(x+W,y+H)#include #include #include using namespace std;#define LL long longconst int maxn = 22222;struct edge{

2014-07-21 16:13:54 341

原创 HDU 4007 Dave

/* 变形的矩形面积并问题 考虑每一个点,以其为左下角,给定正方形边长为正方形作正方形,那么我们最终所求就应该是整个矩形区域覆盖次数最多的地方 扫描线解决 */#include #include #include using namespace std;const int maxn = 2222;struct edge{ int a,b,h; int s;

2014-07-21 16:11:49 434

原创 POJ 1177 Picture

/* 矩形的周长并 解决思路和矩形的面积并类似,采用扫描线解决,每一次周长的增量也就是扫描线线段长的变化量 由于一些边界情况比较难处理,考虑x方向和y方向上恰好有两个矩形相接的情形,为了简化处理,可以从x方向上扫一遍,再从y方向上扫一遍 */#include #include #include #include using namespace std;const int ma

2014-07-21 16:08:55 323

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除