摘要: ACM是我的另一个情人,对其依依不舍。这种曾经一起战斗岁月不会忘记,可惜还没深入就要退役了。早知我们就早点相见 阅读全文
posted @ 2014-03-16 22:36 fangguo 阅读(201) 评论(1) 推荐(0) 编辑
摘要: 思路:直接用优先队列优化bfs。#include#include#include#include#include#include#include#include#include#define Maxn 100010#define inf 1 g;int ans,n,ha[255],Exp[15];char s[13];int tar;struct QT{ int val,st; int operator temp.st; }};priority_queue q;int bfs(int temp){ int i,j,str; while(!q.empty()) q.... 阅读全文
posted @ 2013-12-26 17:19 fangguo 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 思路:用并查集即可,每次合并的时候将小的集合合并到大的集合上去。理论上的平均复杂度是n*lgn*lgn。#include#include#include#include#include#include#define Maxn 100010#define LL long long#define Mod 1000000007int sz[Maxn],fa[Maxn];using namespace std;priority_queue q[Maxn];void init(){ for(int i=0;isz[y]){ q[x].push(s1); q[x].pus... 阅读全文
posted @ 2013-12-19 17:32 fangguo 阅读(209) 评论(0) 推荐(0) 编辑
摘要: #include#include#include#include#include#define Maxn 100using namespace std;int dp[1<<21],num[Maxn],bag[Maxn][Maxn],g,b,s,now[22];bool vi[Maxn];int dfs(int S,int now[]){ if(vi[S]) return dp[S]; if(S==0) return 0; int a[22],c[22]; int i,j,f; int ans=-10000000; int num=0; vi[S]=1;... 阅读全文
posted @ 2013-10-29 14:00 fangguo 阅读(288) 评论(0) 推荐(0) 编辑
摘要: 思路:树状数组统计。待验证,不知道是否对。#include#include#include#include#include#define lowbit(x) (x&(-x))#define Maxn 200010using namespace std;int C[Maxn],vi[Maxn],pre[Maxn],n,num[Maxn],ans[Maxn],ov[Maxn];struct Qu{ int l,r,i;}q[Maxn];int cmp(Qu a,Qu b){ return a.r<b.r;}void update(int pos,int val){ while(p.. 阅读全文
posted @ 2013-10-28 19:24 fangguo 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 思路:已知当前的总长度和为len,当前的伤害为sum,伤害次数为 num.那么对下一个点的伤害值sum=sum+2*len+num;这个是通过(x+1)^2展开化简就能得到。#include#include#include#include#include#define Maxn 100010#define LL __int64#define inf 1e12using namespace std;LL num[Maxn],cnt[Maxn],n,k;bool OK(LL x){ LL suma,sumb,ans,po,i,numa; LL j=n; suma=sumb=an... 阅读全文
posted @ 2013-10-17 15:31 fangguo 阅读(286) 评论(0) 推荐(0) 编辑
摘要: 思路:直接通过斜率优化进行求解。#include#include#include#include#include#define Maxn 1000010using namespace std;__int64 sum[Maxn];__int64 num[Maxn];int que[Maxn*4];int main(){ int n,k,head,rear,x; int i,j; double ans; while(scanf("%d%d",&n,&k)!=EOF){ ans=0; for(i=1;i=(sum[i]-sum[que[head]]... 阅读全文
posted @ 2013-10-14 21:36 fangguo 阅读(182) 评论(0) 推荐(0) 编辑
摘要: 思路:很普通的斜率dp#include#include#include#include#define Maxn 10010#define LL intusing namespace std;LL dp[Maxn][2],num[Maxn];int que[Maxn*10];inline LL getleft(int x,int j,int k){ return dp[j][x]+num[j+1]*num[j+1]-(dp[k][x]+num[k+1]*num[k+1]);}inline LL getright(int j,int k){ return 2*(num[j+1]-num... 阅读全文
posted @ 2013-10-14 21:34 fangguo 阅读(202) 评论(0) 推荐(0) 编辑
摘要: 思路:dp[i]=dp[j]+(sum[i]-sum[j])^2+m;剩下的就是普通斜率dp做法。#include#include#include#include#include#define Maxn 500010#define LL __int64using namespace std;LL dp[Maxn],num[Maxn],sum[Maxn];int que[Maxn*2];LL getleft(int j,int k){ return dp[j]+sum[j]*sum[j]-(dp[k]+sum[k]*sum[k]);}LL getright(int j,int k){ ... 阅读全文
posted @ 2013-10-14 10:27 fangguo 阅读(160) 评论(0) 推荐(0) 编辑
摘要: 思路:dp[i][x]=dp[j][x-1]+val[i]-val[j]-sum[j]*sum[i]+sum[j]*sum[j];其中val[i]表示1~~i是一段的权值。然后就是普通斜率dp做法。#include#include#include#include#include#define Maxn 1010#define LL __int64using namespace std;LL dp[Maxn][Maxn],num[Maxn],sum[Maxn],val[Maxn];int que[Maxn*10];LL getleft(int x,int j,int k){ return ... 阅读全文
posted @ 2013-10-14 09:52 fangguo 阅读(163) 评论(0) 推荐(0) 编辑