A 直接线段树过的 两遍 貌似大多是标记过的。。注意long long

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define LL long long
#define N 100100
LL s[N<<],lz[N<<],st[N<<],lzt[N<<];
LL a[N];
struct node
{
int l,r;
LL d;
}p[N];
void build(int l,int r,int w)
{
if(l==r)
{
st[w] = a[l];
return;
}
int m = (l+r)>>;
build(l,m,w<<);
build(m+,r,w<<|);
}
void down(int w,int m,int f)
{
if(f)
{
if(lz[w])
{
s[w<<]+=lz[w]*(m-m/);
s[w<<|]+=lz[w]*(m/);
lz[w<<] +=lz[w];
lz[w<<|]+=lz[w];
lz[w] = ;
}
}
else
{
if(lzt[w])
{
st[w<<]+=lzt[w]*(m-m/);
st[w<<|]+=lzt[w]*(m/);
lzt[w<<] += lzt[w];
lzt[w<<|] += lzt[w];
lzt[w] = ;
}
}
}
void update(int a,int b,LL d,int l,int r,int w,int f)
{
if(a<=l&&b>=r)
{
if(f)
{
s[w]+=(r-l+);
lz[w]++;
}
else
{
st[w]+=(r-l+)*d;
lzt[w]+=d;
}
return ;
}
down(w,r-l+,f);
int m = (l+r)>>;
if(a<=m)
update(a,b,d,l,m,w<<,f);
if(b>m)
update(a,b,d,m+,r,w<<|,f);
}
LL query(int p,int l,int r,int w,int f)
{
if(l==r)
{
if(f)
return s[w];
else return st[w];
}
down(w,r-l+,f);
int m = (l+r)>>;
if(p<=m)
return query(p,l,m,w<<,f);
else return query(p,m+,r,w<<|,f);
}
int main()
{
int i,k,n,m;
cin>>n>>m>>k;
for(i = ; i <= n ;i++)
cin>>a[i];
build(,n,);
for(i = ; i <= m ;i++)
cin>>p[i].l>>p[i].r>>p[i].d;
while(k--)
{
int x,y;
cin>>x>>y;
update(x,y,,,m,,);
}
for(i = ; i <= m ; i++)
{
p[i].d = query(i,,m,,)*p[i].d;
if(p[i].d)
{
update(p[i].l,p[i].r,p[i].d,,n,,);
}
}
for(i = ; i < n ;i++)
{
cout<<query(i,,n,,)<<" ";
}
cout<<query(n,,n,,)<<endl;
return ;
}

B floyd的变形 倒着更新 每次加一个节点 然后利用floyd的dp性质对所有的点对距离进行更新

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define N 510
#define LL long long
int a[N][N],b[N],q[N];
LL w[N][N],s[N];
int main()
{
int i,j,n,e;
cin>>n;
for(i = ; i <= n ;i++)
{
for(j = ; j <= n ;j++)
{
cin>>a[i][j];
w[i][j] = a[i][j];
}
}
for(i = ; i <= n ;i++)
{
cin>>b[i];
}
int g = ;
for(i = n ; i>= ; i--)
{
LL ans=;
g++;
q[g] = b[i];
for(j = ; j <= n ;j++)
for(e = ; e <= n ;e++)
w[j][e] = min(w[j][b[i]]+w[b[i]][e],w[j][e]);
for(j = ; j <= g ; j++)
for(e = ; e <= g ; e++)
{
//w[q[j]][q[e]] = min(w[q[j]][b[i]]+w[b[i]][q[e]],w[q[j]][q[e]]);
ans+=w[q[j]][q[e]];
}
s[i] = ans;
}
for(i = ; i <= n ; i++)
cout<<s[i]<<" ";
return ;
}

C  搜索+dp

刚开始只往 dp方向 想了  想着先dp出最短的 再倒 回去符合情况的状态保存下来 找次数  貌似时间复杂度 以及代码难写度都很高 正确性也不能保证。。果断没写

看了题解说是搜索+dp  想到用bfs保存状态求次数最小 貌似遇到组合就会卡 组合求 次数的地方一直没写对 之后参考别人的 应该是每次符合情况的都要加上而不只是入队的那颗加  挺好的一题

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
#define LL long long
#define mod 1000000007
#define INF 0xfffffff
LL c[][];
int vis[][][];
LL dp[][][];
struct node
{
int num,a,b,d;
};
int n,k;
void init()
{
int i,j;
for(i = ; i <= n ;i++)
{
c[i][] = ;
}
for(i = ; i <= n; i++)
{
for(j = ; j <= i ; j++)
{
c[i][j] = (c[i-][j]+c[i-][j-])%mod;
}
}
}
void bfs(int c1,int c2)
{
int i,j;
queue<node>q;
node tt;
memset(vis,-,sizeof(vis));
tt.num = ;tt.d = ;
tt.a = c1;tt.b = c2;
vis[][c1][c2] = ;
dp[][c1][c2] = ;
q.push(tt);
int minz = INF;
while(!q.empty())
{
node st = q.front();q.pop();
if(st.a==c1&&st.b==c2&&st.d==) minz = min(minz,st.num);
for(i = ; i <= st.a ; i++)
for(j = ; j <= st.b ; j++)
{
int a1 = c1-st.a+i;
int b1 = c2-st.b+j;
if(i+j>=&&i*+j*<=k)
{
if(vis[st.d^][a1][b1]==-)
{
vis[st.d^][a1][b1] = vis[st.d][st.a][st.b]+;
tt.num = st.num+;
tt.a = a1;tt.b = b1;
tt.d = st.d^;
q.push(tt);
dp[st.d^][a1][b1] = (dp[st.d^][a1][b1]+((dp[st.d][st.a][st.b]*c[st.a][i])%mod*c[st.b][j])%mod)%mod;
}
else if(vis[st.d^][a1][b1]==vis[st.d][st.a][st.b]+)
dp[st.d^][a1][b1] = (dp[st.d^][a1][b1]+((dp[st.d][st.a][st.b]*c[st.a][i])%mod*c[st.b][j])%mod)%mod;
}
}
}
if(minz!=INF)
cout<<minz<<"\n"<<dp[][c1][c2]<<endl;
else
printf("-1\n0\n");
}
int main()
{
int i;
cin>>n>>k;init();
int c1=,c2=;
for(i = ; i <= n ;i++)
{
int a;
cin>>a;
if(a==)
c1++;
else c2++;
}
bfs(c1,c2);
return ;
}

Codeforces Round #179 (Div. 1)的更多相关文章

  1. Codeforces Round #179 (Div. 1) A. Greg and Array 离线区间修改

    A. Greg and Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/295/pro ...

  2. Codeforces Round #179 (Div. 2) B. Yaroslav and Two Strings (容斥原理)

    题目链接 Description Yaroslav thinks that two strings s and w, consisting of digits and having length n  ...

  3. Codeforces Round #179 (Div. 1 + Div. 2)

    A. Yaroslav and Permutations 值相同的个数不能超过\(\lfloor \frac{n + 1}{2} \rfloor\). B. Yaroslav and Two Stri ...

  4. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  5. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  6. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  7. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  8. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  9. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

随机推荐

  1. 搜索学术论文訪问google的能用的几个IP地址

    google搜索引擎打不开时的解决的方法,谷歌(google)的IP是多少? google IP镜像. 这里搜集了几个经过測试可用的IP,用来在不能域名訪问google的时候进行訪问 更新一个最新的. ...

  2. csv读入数据,用julia/matplotlib/pyplot 画矢量图导入word中

    这是是用julia来实现画图.julia有三个画图库:Winston.Gadfly.PyPlot 这里用的是pyplot,事实上他是基于matplotlib的 1.首先在juno里安装两个库 juno ...

  3. Spring中注解

    @Autowired :spring注解 @Resource :J2EE注解 @Transactional(rollbackFor=Exception.class):指定回滚 @RequestMapp ...

  4. 3.NetDh框架之缓存操作类和二次开发模式简单设计(附源码和示例代码)

    前言 NetDh框架适用于C/S.B/S的服务端框架,可用于项目开发和学习.目前包含以下四个模块 1.数据库操作层封装Dapper,支持多种数据库类型.多库实例,简单强大: 此部分具体说明可参考博客: ...

  5. 嵌入式linux 实现mdev SD卡和U盘自己主动挂载和卸载的方法 mdev.conf

    首先先參考这些博客做一些了解:http://linux.chinaunix.net/techdoc/install/2009/11/18/1144936.shtml http://www.cnblog ...

  6. nhibernate的关系

    用nhibernate,觉得比较难把握的是其中表间的关系. 我用的是Fluently Nhibernate,直接用代码,而不是XML来书写代码与数据表的映射.其中表间关系有3种: 1.Referenc ...

  7. autofac如何注册静态方法里的接口对象

    标题可能是不准确的,因为我不知道如何描述.不知道的原因,是对依赖注入一知半解. Autofac可以自动注册对象实例到接口,人所尽知.而在asp.net mvc中,这个实例化的工作,通常在每个控制器的构 ...

  8. YTU 2414: C语言习题 字符串排序

    2414: C语言习题 字符串排序 时间限制: 1 Sec  内存限制: 128 MB 提交: 656  解决: 305 题目描述 输入n个字符串,将它们按字母由小到大的顺序排列并输出.编写三个函数实 ...

  9. 织梦首页TAG标签页的仿制

    1,tag标签的作用:主要是为了能够使得用户可以更加精确的找寻到自己所需内容.这种TAG搜索方式,比分类搜索更加的精确.具体以及节省时间. 2,怎么能够合理的优化TAG标签? A:明白网站的TAG标签 ...

  10. idea新建springmvc+spring+mybaties项目1

    1,点击file,选择module,新建项目 2,选择maven -- >maven-archetype-webapp 3,输入GroupId,ArtifactId,点击next 4,选择本地m ...