上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 22 下一页
摘要: 思路:主要就是模拟这些操作,用链表果断超时。改用堆栈模拟就过了#include#include#include#include#include#include#include#include#include#include#include#include#define Maxn 1000010#define Maxm 300010#define LL __int64#define Abs(x) ((x)>0?(x):(-x))#define lson(x) (x br,af;int main(){ int i,j,u,v,n,x; char str[3]; int brz,a... 阅读全文
posted @ 2013-08-23 15:31 fangguo 阅读(175) 评论(0) 推荐(0) 编辑
摘要: 思路:用map将每个字符串与一个数字进行对应,然后暴力统计就好了#include#include#include#include#include#include#include#include#define Maxn 2010using namespace std;int fr[Maxn][Maxn],mul[Maxn][Maxn],Max[Maxn];char str[Maxn][20];map g;vector head[Maxn*2];vector ans[Maxn*2];int cmp(int a,int b){ return strcmp(str[a],str[b])<0;}i 阅读全文
posted @ 2013-08-22 19:02 fangguo 阅读(214) 评论(0) 推荐(0) 编辑
摘要: 思路:dp[i][x][y]表示第i个序列中,右脚在x位置,左脚在y位置时,其最小花费。那么dp[i][x][y]=min(dp[i-1][a[i]][y]+cost[a[i]][x],dp[i-1][x][a[i]]+cost[a[i]][y]);题目连接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=32#include#include#include#include#include#include#incl 阅读全文
posted @ 2013-08-22 18:51 fangguo 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 思路:黑书的例题#include#include#include#include#include#define Maxn 20#define mul(a) ((a)*(a))using namespace std;int dp[16][9][9][9][9];int s[10][10],val[10][10];int S(int x1,int y1,int x2,int y2){ return mul(s[x2][y2]-s[x2][y1-1]-s[x1-1][y2]+s[x1-1][y1-1]);}int main(){ int n,m,i,j; double avg; ... 阅读全文
posted @ 2013-08-22 08:54 fangguo 阅读(176) 评论(0) 推荐(0) 编辑
摘要: 思路:黑书的例题#include#include#include#include#define Maxn 1010using namespace std;int dp[Maxn][Maxn],v[Maxn][Maxn];char str[Maxn];void Out(int s,int e){ if(s>e) return ; if(s==e) { if(str[s-1]=='('||str[s-1]==')') printf("()"); else printf("[]"); ... 阅读全文
posted @ 2013-08-20 16:28 fangguo 阅读(266) 评论(0) 推荐(0) 编辑
摘要: 思路:就是个比较裸的LCA了,不过要注意的是,如果a和b的公共祖先是a,那么答案就是farther[a]。#include#include#include#include#include#include#include#include#define Maxn 300010using namespace std;int vi[Maxn],pre[Maxn];int dep[Maxn],sec[Maxn],farther[Maxn];int e,Md;char str[Maxn][70],ans[Maxn][70];vector head[Maxn];map g;void init(){ M... 阅读全文
posted @ 2013-08-20 13:55 fangguo 阅读(206) 评论(0) 推荐(0) 编辑
摘要: 思路:分等号左边和右边进行搜索#include#include#include#include#include#define LL __int64using namespace std;char str[20];int n,ans;void right(LL sum,LL now,int cnt){ if(cnt==n) { if(sum==now) ans++; return ; } if(sum==0) return ; if(sum>=now*10+(LL)(str[cnt]-'0')) ... 阅读全文
posted @ 2013-08-20 13:53 fangguo 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 思路:考的是字符串的编辑距离。在蓝桥杯2012年决赛上出现过。#include#include#includeusing namespace std;int dp[200050][20];char targ[20],ans;int Min(int a,int b,int c){ int temp; temp=a0) strcpy(targ,str2); } else { strcpy(targ,str2); ans=t;... 阅读全文
posted @ 2013-08-19 19:20 fangguo 阅读(190) 评论(0) 推荐(0) 编辑
摘要: 思路:这题和1227的求法一样,只不过1227是小数据,暴力下,就能进行预处理。这题的预处理区间期望cost[i][j]需要利用单调性。即假使以pos位置为安排的点,那么这个区间在其左边的概率为l,右边的概率为r,总期望为sum。如果将安排点从pos放到pos-1该区间增加的期望为r*(p[pos].x-p[pos-1].x)减少的期望为l*(p[pos].x-p[pos-1].x)如果减少的超过增加的,那么pos-1就比pos好。#include#include#include#include#include#define Maxn 1010using namespace std;doubl 阅读全文
posted @ 2013-08-17 21:01 fangguo 阅读(201) 评论(0) 推荐(0) 编辑
摘要: 思路:主要就是要把一个每个城市拆为两个点,建一条容量为1,费用为-inf的边,保证每个城市都会被遍历。/*最小费用最大流*/#include#include#include#include#includeusing namespace std;const int Maxn = 1010;const int inf = 1000010;struct Edge{ int v; int val; int cost; int next;}edge[Maxn*100];int head[Maxn],n,g[Maxn][Maxn],m,k;int e;int pre[Maxn], ... 阅读全文
posted @ 2013-08-17 16:50 fangguo 阅读(126) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 22 下一页