自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(51)
  • 收藏
  • 关注

原创 hdu 5883 欧拉路

点击打开链接#include #include #include #include using namespace std;const int N=1e5+7;int n,m;int val[N];int deg[N]; int main(){ int t; cin>>t; while(t--) { cin>>n>>m; memset(deg,0,sizeo

2016-09-30 14:45:38 411

原创 poj 1037 经典计数dp+字典序

点击打开链接#include #include #include #define up 0#define down 1using namespace std;typedef long long ll;const int Mod=1e9+7;const int M =35;ll dp[M][M][2];//dp[i][j][up] i根中的第j根开头 前两个为升序的

2016-09-29 18:58:09 384

原创 CF 372D Dijkstra+模拟

点击打开链接先判断无解情况: 情况1:不加'0'边时 最短路d[t]情况2:加入'0'边时,使'0'边的权为最小的1 此时最小d[t]>L 无解剩下的情况都为有解 因为(s,t)的路径路径只剩下 d[t]不断对最短路径中的'0'边进行松弛使之达到L 此时判断最短路是等于L(松弛后的次短路变为最短路可能小于L)#include #include #include usi

2016-09-29 16:51:16 555

原创 CF the little match girl (贪心!!!)

点击打开链接解放1#include #include #include #include #include using namespace std;const int M=1e5+20; char a[M];int n;int num[10]={6,2,5,5,4,5,6,3,7,6};//组成数字i需要多少根木棒 bool check(long long cnt,in

2016-09-28 21:10:30 340

原创 CF 715A Plus and a square root(数学构造)

点击打开链接#include #include #include #include #include using namespace std;const int Mod=1e9+7;const int M=1e5+1;long long a[M];//a[i]第i层时要升级时的数字long long ans[M]; // 第i层需要加的次数 int main(){

2016-09-28 16:36:30 517

原创 CF Gym101102C 线段树(最值)+模拟

点击打开链接每次更新 判断名次即:最值编号是否改变 如果改变,则记录改变的时间#include #include #include #include #include using namespace std;const int M=1e5+20;struct Seg{ long long score; int num; }seg[M*4];//节点保存最大值和对

2016-09-28 09:01:20 597

原创 CF Gym 字符串字典序

点击打开链接#include #include #include #include #include using namespace std;const int M=1e5+20;char a[M];int n;int pos[27];//字符出现的最早位置 int main(){ int t; cin>>t; while(t--) { char c

2016-09-27 20:47:08 406

原创 hdu 1576 乘法逆元(入门)

点击打开链接#include #include #include using namespace std;const long M=9973;long x,y;long gcd(long a,long b){ if(a%b==0) return b; else { return gcd(b,a%b); }}void exgcd(long a,long b){

2016-09-26 20:12:43 466

原创 hdu 2669 exgcd(水)

点击打开链接#include #include #include using namespace std;const int M=1e5+20;long x,y;long gcd(long a,long b){ if(a%b==0) return b; else { return gcd(b,a%b); }}void extgcd(long a,long b)

2016-09-26 18:58:07 398

原创 hdu 1671 Trie(水)

点击打开链接#include #include #include #include using namespace std;const int M=1e4+20;typedef struct Trie{ Trie *next[10]; int pre; bool word;}trie;trie *root;char s[M][11];bool flag;void

2016-09-25 21:36:44 292

原创 hdu 5904 LCIS(简单dp)

点击打开链接#include #include #include #include using namespace std;const int M=1e6+20;int a[M],b[M];//consists of consecutive values in increasing order//递增的值要是连续的 易得递推方程为 dp[a[i]]=max(dp[a[i],d

2016-09-24 22:44:40 427

原创 codeforce 719b 贪心

点击打开链接  n个蝗虫,共两种颜色,要求摆出rbr...或者brb...这种交错的样子,可以交换任意俩,或者改变一个的颜色,求操作最小次数。//变换后的序列要么位brbr... 要么位rbrb...//原序列和最终序列的某个位置不同 这个位置就肯定要操作一次  //统计错位位置 //若和b错位位置有5个,和r错位位置有3个 则应该交换3次 改变两次 即可 

2016-09-24 10:03:42 863

原创 hdu 5890 01背包(bitset优化)

点击打开链接#include #include #include #include #include #include using namespace std;const int M=55;int a[M],n;bool check[M][M][M];//打表//超时 int dp[M][11][100];//dp[i][j][k]前i个数的取j个之和和能否达到k j<=1

2016-09-23 15:31:02 619

原创 poj 1655树的重心入门

点击打开链接树的重心定义为:找到一个点,,使以它为根的子树中最大的子树节点数最少,那么这个点就是这棵树的重心,删去重心后,剩下的森林中最大子树的节点数最小#include #include #include #include using namespace std;const int M=410000;int dp[M];//dp[i]以i为root

2016-09-23 13:21:57 410

原创 codeforces 716B字符串水题

点击打开链接#include #include #include #include using namespace std;const int M=51000+20;char s[M];char ans[M];//记录应该补充的字符 int vis[M];int main(){ while(scanf("%s",s)!=EOF) { int len=strl

2016-09-22 18:34:02 680

原创 poj 1743后缀数组入门

http://poj.org/problem?id=1743求最长不重叠字串: 转化为判断性问题求最值 二分长度k 即满足h[i]>=k的后缀为一组 该组中最大编号差>=k则不重叠,满足条件#include #include #include #include const int inf=31000;const int M=20101;int wa[20010],wb[200

2016-09-22 13:07:16 342

原创 poj 1947Rebuilding Roads树形dp(背包)

点击打开链接#include #include #include #include #include using namespace std;const int inf=1<<20;const int M=1100;vector e[M];int n,p,root;int deg[M];//直接相连的子节点个数 int vis[M];int fa[M];int dp[

2016-09-22 10:04:36 339

原创 poj 2774 后缀数组(模板题)

点击打开链接模板#include #include #include #include using namespace std;const int M =1e6+20;int len,len1,len2;char s[M];int sa[M];//sa[i]排名i的后缀编号 int c[M];//计数数组 c[i]=j表示关键字<=i的有j个 int t1[M]

2016-09-21 19:09:31 567

原创 hdu 1247 Trie入门题

点击打开链接判断有多少单词恰好是由两个单词拼接成#include #include #include #include using namespace std;const int M=26;char s[51000][50];typedef struct Trie{ Trie *next[M];//节点的子树 bool word;//单词节点标记 }Trie;Trie

2016-09-20 16:48:32 332

原创 hdu 5444 遍历树+模拟

点击打开链接题意:树的结构固定 现在给树的节点赋值 they always number the room number from the east-most position to the west. //先左子树然后根最后右子树:即按照树的中序遍历顺序给树赋值1~nThe sequence is written as follows, it will go straig

2016-09-20 14:54:58 354

原创 hdu 1054 树的最小点覆盖

点击打开链接资料定义2对于图G=(V,E)来说, 最小点覆盖 指的是从V中取尽量少的点组成一个集合,使得E中所有的边都与取出来的点相连。也就是说,设V‘是图G的一个顶点覆盖,则对于图中的任意一条边(u,v),要么u属于集合V’,要么v属于集合V‘。在V‘中除去任何元素后V’不在是顶点覆盖,则V‘是极小顶点覆盖。称G的所有顶点覆盖中顶点个数最少的覆盖为最小点覆盖。//最小点覆盖:

2016-09-20 12:58:48 726

原创 hdu 5441 离线处理+并查集

参考点击打开链接#include #include #include #include #include using namespace std;const int M=2*1e6+20;struct Query{ int x,id; bool operator < ( const Query& a )const { retur

2016-09-19 21:02:49 368

原创 hdu 2196树形dp经典 树的最长路

点击打开链接#include #include #include #include #include using namespace std;const int M=1e5+20;int n;int vis[M];struct Node{ int v,w; Node(int a,int b) { v=a; w=b; }};vector e[2*M];//双

2016-09-19 19:48:34 366

原创 hdu 5900 区间dp

点击打开链接#include #include #include #include using namespace std;const int M=310;typedef long long ll;ll val[M],key[M],sum[M];int table[M][M];//table[i][j] 表示i到j是否都能消完 int can[M][M];//i,j是否互质

2016-09-19 18:20:17 292

原创 hdu 3652 数位dp模版题

点击打开链接#include #include using namespace std;const int M =15;int s[M];int dp[M][M][3];// dp[i][mod][staus] 枚举到第i位时 余数为mod 状态为staus // staus:枚举到第i位 没出现13且末尾不为1,没出现13但末尾为1,出现过13 int dfs(int

2016-09-18 21:58:27 361

原创 hdu 5879 小数极限(水)

点击打开链接#include #include #include #include #include using namespace std;const int M=1e6+10;const double pi=3.14159; double dp[M+10];char str[M];int main(){ dp[1]=1; for(int i=2;i<M;i++)

2016-09-17 20:32:52 362

原创 hdu 5878 二分+打表

点击打开链接#include #include #include #include #include using namespace std;long long a[6000]={1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,24,25,27,28,30,32,35,36,40,42,45,48,49,50,54,56,60,63,64,70,

2016-09-17 20:30:07 1357

原创 hdu 5024 记忆化搜索

点击打开链接#include #include #include #include #include using namespace std;const int M=110;int n,m,ans;int dp[M][M][8][2];//dp[x][y][d][k] 以当前(x,y)为起点,当前方向为d 转弯次数为k时最远能走多远 char g[M][M];const

2016-09-16 18:37:20 301

原创 hdu 5025 bfs+状态压缩

点击打开链接#include #include #include #include #include using namespace std;const int M=110;int n,m,ans;char g[M][M];int snum,snake[M][M];// 记录snake的位置 int sx,sy;int vis[M][M][15][1<<6];//vis[

2016-09-16 16:30:28 331

原创 poj 2528线段树应用+离散化

点击打开链接#include #include #include #include using namespace std;const int M=1e5+20;long long data[M*4],lazy[M*4],x[M<<2];//lazy标记 int vis[M],ans;//记录颜色 struct point{ int l,r; }q[M]; struct

2016-09-16 15:16:58 295

原创 hdu 5493线段树+模拟

点击打开链接字典序最小 从高度最小的开始安排 尽量靠前排 如果是前面有k个人 则第i个人排在第k+1个空位上如果是后面有k个人 则第i个人排在第x+1个空位上因为已经排好了前i-1个人 第i个人后面有k个空位置 第i个人也占了一个位置则剩下的空位有n-(i-1)-k-1个 则x=n-i-k  字典序最小取k=min(k,x)即可  因为放左边时 i+k0

2016-09-16 11:01:18 247

原创 hdu 3966 树链刨分 模版题

点击打开链接参考资料:点击打开链接 点击打开链接核心:对树进行刨分 ,刨分完后 ,每条链就相当于一段区间,用线段树等数据结构维护。#include #include #include #include #include #include #define L(u) (u<<1) #define R(u) (u<<1|1) using namespace st

2016-09-14 22:08:45 343

原创 hdu 5023 线段树区间更新+位运算

点击打开链接题意:把区间(l,r)图上某种颜色 颜色会覆盖, 询问区间(L,R)被图上那些种类颜色思路: 第一步很简单就用线段树中区间更新Set操作修改(l,r)的颜色  第二步询问(L,R)被图上那种颜色时 由于颜色种类#include #include #include #include using namespace std;const int M=1e7+20;lo

2016-09-14 13:44:51 449

原创 hdu 1698 线段树区间更新入门(lazy标记)

点击打开链接#include #include #include #include using namespace std;const int M=1e5+20;long long sum[M*4],lazy[M*4];//lazy标记 struct node{ int l,r; int mid() { return (l+r)>>1; } }seg[M<<2];

2016-09-14 12:45:28 779

原创 hdu 5876 求补图上的最短路

点击打开链接//利用map求出补图的边 然后就可以bfs算了..#include #include #include #include #include #include #include using namespace std;const int inf=1<<20;const int M = 2e5+5;int n,m;map e[M];int dis[M];

2016-09-13 20:11:08 290

原创 hdu 5747 Aaronson贪心水

点击打开链接#include #include #include #include #include using namespace std;const int inf=1<<20;const int M = 1e5+5;int main(){ int t; cin>>t; while(t--) { long long ans=0;

2016-09-13 19:34:00 367

原创 poj 3468 线段树(区间更新)模板题

题目链接  点击打开链接以下为参考链接点击打开链接点击打开链接线段树单点更新和区间更新的区别:1.每个结点中多了一个add值,代表该结点以下的结点需要增加的值;2.build函数中,如果在建树的过程中就赋值给num,那么在建完树之后不要忘记pushup,因为此时只是叶子结点有值,上面的值都为空;这个在区间更新中很常用,因为区间更新中如果输

2016-09-13 19:03:31 440

原创 hdu 5877 离散化+树状数组+dfs序

点击打开链接参考点击打开链接第一个要求u 是v 的祖先,那么可以dfs,遍历到v时,要使上方的都是满足第一条件的u,即遍历完某个节点u的子树时,这时u不可能是任何节点的祖先 删除u的影响,这样就能保证所有有影响的都是祖先。要求w[u]*w[v]#include #include #include #include #include using namespace std;

2016-09-13 17:09:34 355

原创 hdu 3887 DFS序+树状数组

点击打开链接DFS序的意义:对一棵树进行DFS遍历,一个结点最多到达两次,一次入,一次出,而这之间的结点标号均为它的子树结点的标号。所以只要用某种方法快速查询其左右标号内含的区间中,比它小的标号个数即可//#pragma comment(linker, "/STACK:1024000000,1024000000") //开大栈 防止dfs爆栈 #include #inc

2016-09-12 20:44:33 379

原创 UVA 11020 Multiset应用

点击打开链接#include #include #include #include #include using namespace std;const int M =15010;struct Point{ int x; int y; bool operator<(const Point& t)const { return x<t.x|| (x==t.x && y<t

2016-09-11 17:00:00 235

空空如也

空空如也

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

TA关注的人

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