自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

Grush

从今天开始blog只用于保存代码

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

原创 hdu 3466Proud Merchants(01背包 单机调度问题)

题目链接:【hdu 3466】这题的核心部分就是这样子的for(int i=0; i<n; i++){ for(int j=m; j>=h[i].q; j--) { dp[j]=max(dp[j], dp[j-h[i].p]+h[i].v); }}令x1 = q1-p1  x2 = q2-p2,假设一开始没有排序,按输入的顺序操作,那肯定是先买1号商品,再买2号商品如果x

2015-12-15 10:46:23 529

原创 hdu 2955Robberies(01背包 概率计算)

题目链接:【hdu 2955】#include #include #include #include #include using namespace std;double dp[10010], p[110], P;int n, m[110];int main(){ int T; scanf("%d", &T); while(T--) { memset(dp, 0

2015-12-14 19:59:54 430

原创 hdu 5597GTW likes function(欧拉函数)

题目链接:【hdu 5597】f(n)=sum((-1)^k * 2^(2n-2k) * C(k, 2n-k+1))   0这个公式化简之后就是f(x) = x+1简单证明一下首先要知道C(m,n)+C(m+1, n) = C(m+1, n+1)#include #include #include #include #include using namespa

2015-12-13 22:02:22 591

原创 hdu 5596GTW likes gt(最好倒着思考)

题目链接:【hdu 5596】#include #include #include #include #include using namespace std;struct node{ int id, di;}a[50010];int time[50010];int main(){ int T; cin>>T; while(T--) { memset(tim

2015-12-13 16:52:08 337

原创 hdu 4284Travel(状压dp 或 floyd+dfs)

题目链接:【hdu 4284】一、floyd+dfs#include #include #include #include #include using namespace std;#define inf 0x3f3f3f3fstruct T{ int id, ci, di;}p[110];int f[110][110], vis[110], h;bool dfs(

2015-12-11 20:32:22 355

原创 codeforces 606D. Lazy Student(#335 逆最小生成树)

题目链接:【codeorces 606D】#include #include #include #include #include using namespace std;#define inf 100010#define ll __int64int link[inf], vis[inf];struct node{ int w, id;}a[inf], b[inf];

2015-12-10 23:00:13 597

原创 poj 1011Sticks(搜索 剪枝超级多 经典)

题目链接:【poj 1011】#include #include #include #include #include using namespace std;int a[100], vis[100], n, sum;int next[100];bool cmp(int a, int b){ return a>b;}bool dfs(int len, int now,

2015-12-09 22:54:49 442

原创 poj 2488A Knight's Journey(搜索 记录路径)

题目链接:【poj 2488】#include #include #include #include #include using namespace std;int f[8][2]={-1,-2,1,-2,-2,-1,2,-1,-2,1,2,1,-1,2,1,2};int vis[30][30], li, n, m, flag;struct node{ int x, y;

2015-12-09 18:04:58 326

原创 poj 1321棋盘问题(搜索)

题目链接;【poj 1321】#include #include #include #include #include using namespace std;char str[10][10];int row[10], n, col[10];__int64 ans;void dfs(int x, int k){ if(k==0) { ans++; return

2015-12-08 19:57:54 309

原创 poj 1088滑雪(记忆化搜索)

题目链接:【poj 1088】#include #include #include #include #include #include using namespace std;int dp[110][110], a[110][110];int f[4][2] = {0,1,1,0,0,-1,-1,0};int n, m;bool is_ok(int x, int y){

2015-12-08 16:52:49 313

原创 hdu 1274展开字符串(搜索)

题目链接:【hdu 1274】#include #include #include #include #include using namespace std;char str[300];int len;int dfs(int pos){ int e,i; for(i=pos; i<len; i++) { if(str[i]==')') break; int k

2015-12-08 15:54:26 340

原创 hdu 1274展开字符串(用栈来实现的)

题目链接:【hdu 1274展开字符串】#include #include #include #include #include #include using namespace std;char str[300], si[2500000], sl[2500000];int main(){ int n; scanf("%d", &n); while(n--) {

2015-12-07 21:54:55 424

原创 hdu 1237简单计算器(栈的简单应用)

题目链接:【hdu 1237简单计算器】#include #include #include #include #include #include using namespace std;int main(){ double x; char c; while(~scanf("%lf", &x)) { c=getchar();//空格的输入方式 if(c=='\n

2015-12-07 19:03:28 286

原创 codeforces 380E. Sereja and Dividing(#223div1)(易超时巧妙求和)

题目链接:【E. Sereja and Dividing】输入大小为n的数组b[n],求ans = 函数g([b[i],b[i+1],b[i+2],b[i+3]……b[j] ],x)的意思是先从从i~j中选一个数k,然后计算  tmp=(b[k]+x)/ 2,x=tmp,b'[k] = tmp,i~j每一个都选过去之后能得到的最大的b'[]最直接的方法就是将i~j之间的b从小到大排序,

2015-12-04 21:38:18 473

原创 codeforces 603A. Alternative Thinking(数学找规律 或者 dp)

题目链接:【A. Alternative Thinking】输入一串长为n的01串,翻转其中的一段,所谓的翻转就是0变1,1变0,求最终最长01交替的序列长度样例1:10000011   翻转后得到  10100011   最终的长度就是5  (红色部分)方法一:数学找规律原先相邻的变化后仍然相邻,所以我们可以先算出原本就相邻的最长是多少,一个子串翻转后,我们的要求是最长交替01串

2015-12-03 20:23:16 961

原创 codeforces 380D. Sereja and Cinema(#223div1 组合数学)

题目链接:【D. Sereja and Cinema】电影院有n个位置,每个位置两边都有一个放东西的地方,当一个人进来之后他会立即占有位置两边空着的储物格,要是他到的时候,座位的两边的储物格都已经被占有了,那这个人就会离开输入n(1样例:60 1 0 0 0 6有一种情况绝对会有一个人会离开,a,b,c位置相邻,对应的进入顺序是ai,bi,ci,如果bi比ai,ci都大

2015-12-02 19:37:33 432

转载 stl之pair,map,vector区别

本文转自:http://www.linuxidc.com/Linux/2014-10/107621.htmpair定义于头文件utility中,主要的作用是将两个数据组合成一个数据,两个数据可以是同一类型或者不同类型。pair类型提供的操作:pair p1;pair p1(v1,v2);make_pair(v1,v2);p1 p1 == p2;p.fir

2015-12-02 15:43:00 5767

原创 codeforces 600E. Lomsat gelral(教育场 树形dp)

题目链接:【E. Lomsat gelral】一棵树有n(1一棵树的控制颜色的定义:在节点k的子树中,不存在另一种颜色出现的总次数大于颜色ci,那么ci就是以k为根的树的控制颜色,也就是说一棵树可以有多个控制颜色求以节点v为根的树的控制颜色总和样例41 2 3 41 22 32 4这一题难点以及特点就是向上一层递归时要用map[ i ][ ci ][ num

2015-12-02 14:58:11 826

原创 codeforces 600C. Make Palindrome(贪心)

题目链接:【C. Make Palindrome】Educational Codeforces Round 2输入一串字符串,用最少的步数把它变成回文串,得到的回文串字典序最小先改变一些字母,然后改变顺序,改变顺序不算步数回文串的特点是左右对称,当长度是偶数时,串上的字母的个数全都是偶数个,当长度是奇数时,串上字母有且仅有一个是奇数个所以我们可以先用数组num[]记录字符串

2015-11-30 19:44:38 522

原创 codeforces 380A. Sereja and Prefixes(折半查找)

题目链接: Codeforces Round #223 (Div. 1)  【A. Sereja and Prefixes】n个操作,类型1,将一个数加到数组后面,类型2,将前l个数字复制c遍,然后加到数组后面m次询问,每次输出第x个位置的数值每次操作时用type[]记录类型,len[i]来记录第di次操作的总长度二分查找位置x,找到这个位置后,如果属于类型1就直接输出,如

2015-11-29 22:56:56 468

原创 codeforces 381E Sereja and Brackets(线段树)

题目链接:【E. Sereja and Brackets】    线段树输入一串括号串,m次询问,每次输出区间[l,r]之间配对的括号最多是多少配对的括号是‘()’,除此之外全不是配对的a[i]表示到i为止一共有多少括号对b[i]表示到i为止有多少‘(’没有配对先遍历一遍,记录数组a,b,那么区间[l,r]的括号对数就是a[r] - a[l-1] - numnum就是在'(

2015-11-29 20:02:31 342

原创 codeforces 589C Polycarp's Masterpiece(分治 折半搜索)

【2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)】给你一个字符串s, n次操作,每次把最后一个字母放到最前面放k次, 得到一个新的字符串,把新的字符串添加到原来的字符串的后面m次询问,问你在l~r之间字母c出现的次数是多少

2015-11-26 22:28:49 508

原创 Codeforces Round #223 (Div. 2) D

【D. Sereja and Tree】一棵树的特点就是当节点是2^x时,它就有两个儿子,否则就只有一个儿子输入n,表示树有n层,即深度是n,接下来是m次询问(一开始是一棵空树)每次输入有两种操作1、1 t l r x    =>  第t层的第l个节点到第r个节点之间的值是x2、2 t v  =>  求第t层第v个数的子树中包含的不同的值的个数先预处理出每个节点后面的左二子

2015-11-23 20:54:53 295

原创 树形dp之删边

【Codeforces Round #263 (Div. 2) D. Appleman and Tree】一棵由n个点组成的树,标号为0~n-1输入n-1个数字pi,表示pi与i+1相连输入n个数xi,xi=0表示这个节点是白色,xi=1表示这个节点是黑色删掉一些边,使得得到的子树有且仅有一个黑点v是父节点, u是子节点dp[ i ][ 0 ]表示经过一系列的删边操作之后,

2015-11-22 16:57:26 581

原创 树形dp之树的分治

【点的分治】【POJ 1741 Tree】已知一棵有n个点的树,以及每两个相邻点之间的距离,求两个的之间的最小距离可以先看一看论文《分治算法在树的路径问题中的应用 》树的重心:删掉这个点之后,最大子树包含的节点最少先找到重心,计算每一个点到重心的距离,用数组dis[ ]记录,我们要求的是点的对数,没必要知道是哪几个点所以将dis[ ]排序,如果dis[i] + dis[j]

2015-11-22 16:11:17 271

原创 极角排序题集

【codeforces 598 C】#include #include #include #include #include #include using namespace std;#define inf 10000000//将每个值都都扩大inf倍,防止卡精度 const double pi = acos(-1.0)*inf;struct node{ int id;

2015-11-14 20:53:08 373

原创 Educational Codeforces Round 1

【A. Tricky Sum】【B. Queries on a String】【C. Nearest vectors】【D. Igor In the Museum】【E. Chocolate Bar】【F. Cut Length】

2015-11-14 20:27:51 362

原创 树形dp题集之树的直径

【codeforces 592D】#include using namespace std;#define inf 130000vectoradj[inf];int vis[inf];int sizee[inf], dis[inf];void dfs(int p, int u){ sizee[u] = 0; if(vis[u]) sizee[u]=1; for(int i

2015-11-06 22:29:44 1332

原创 Codeforces Round #329 (Div. 2)

【A. 2Char】在n个字符串中,任选x个组成一长串,最终得到的长串最多由两个字母组成问最终得到的长串的最大长度是多少两个for循环,26个字母两两组合【B. Anton and Lines】直线的方程式是y = k*x+b输入x1, x2以及n个直线方程式的k,b问x1 y1 = k1*x1+b1  y2 = k1*x2+b1y1' = k2*x1+b2

2015-11-05 20:32:58 373

原创 Codeforces Round #328 (Div. 2)

【A. PawnChess】【B. The Monster and the Squirrel】正n变形,顶点顺时针标记为1~n,从1开始画对角线,如果在画一条对角线时要跟另一条对角线交叉,那么就不要延伸出去,与另一条对角线相交于一点就好问你在这个正n变形里面有几块空间通过画图找规律可以知道是(n-2)*(n-2)【C. The Big Race】W跟B这两个人走一步

2015-11-01 21:54:04 470

原创 Codeforces Round #262

div. 2【A. Vasya and Socks】#include using namespace std;int main(){ int n,m; scanf("%d%d", &n, &m); int last=0; int ans=0; while(n) { n--; last++; ans++; if(last == m) { last

2015-10-30 21:32:03 323

原创 Codeforces Round #322 (Div. 2)

【A. Vasya the Hipster】#include #include #include #include #include #include #include #include #include #include using namespace std;typedef long long ll;const int N =

2015-10-26 21:21:16 358

原创 Codeforces Round #323

div. 2【A. Asphalting Roads】#include #include int h[100],v[100];int k[3000];int main(){ int n; memset(h,0,sizeof(h)); memset(v,0,sizeof(v)); scanf("%d",&n); int flag=0,l=0; for(int i=1;i

2015-10-26 21:12:55 393

原创 Codeforces Round #324

这一场就只有div. 2,没有div. 1【A. Olesya and Rodion】#include #include #include #include #include using namespace std;int main(){ int n,m; scanf("%d%d",&n,&m); if(n==1 && m==10) { printf("-1\n

2015-10-26 21:04:22 254

原创 Codeforces Round #325

div. 2【A. Alena's Schedule】#include #include #include #include #include using namespace std;int main(){ int a,n,flag=0,ff=0,ans=0; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&a

2015-10-26 20:54:16 206

原创 Codeforces Round #326

div. 2【A. Duff and Meat】【B. Duff in Love】【C. Duff and Weight Lifting】【D. Duff in Beach】【E. Duff in the Army】【F. Duff in Mafia】div. 1【E. Duff as a Queen】【F

2015-10-26 20:47:21 368

原创 Codeforces Round #327

div. 2【A. Wizards' Duel】【B. Rebranding】【C. Median Smoothing】【D. Chip 'n Dale Rescue Rangers】【E. Three States】div. 1【D. Top Secret Task】【E. Birthday】

2015-10-26 20:28:56 287

原创 hash

【UVA 10125】Sumsets在一串大小为s的数列中,是否存在a + b + c = d, 如果存在,输出最大的d,否则输出no solution这题的数据很水,直接暴力也是能过的#include using namespace std;#define maxn 500510#define inf 0x7FFFFFFFint p[1005];int head[maxn]

2015-10-24 10:08:19 276

原创 143 - ZOJ Monthly, October 2015

【AAnt】 比赛的时候公式推出来了,可是取模那一块弄错了,一直wa假设另外两条边是x,y那么最短的路线就是len = x^2 + y^2 + n^2 + 2*x*y这个公式分成三个部分求s1 = sum(x^2 + y^2)s2 = sum(n^2)s3 = sum(2*x*y)假设n=3n        x     y3        3    3

2015-10-23 19:58:21 343

原创 中途相遇法

【FZU  2178】礼物分配#include #include #include #include #include #include #include using namespace std;int v[35],w[35];vectorvec[40];int main() { int n,t; scanf("%d",&t); while(t--) { sc

2015-10-22 21:07:50 926

空空如也

空空如也

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

TA关注的人

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