Codeforces Round #179 (Div. 1)
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)的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #179 (Div. 1 + Div. 2)
A. Yaroslav and Permutations 值相同的个数不能超过\(\lfloor \frac{n + 1}{2} \rfloor\). B. Yaroslav and Two Stri ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- 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 ...
随机推荐
- 【Mongodb教程 第一课 补加课】 Failed to connect to 127.0.0.1:27017, reason: errno:10061 由于目标计算机积极拒绝,无法连接
1:启动MongoDB 2014-07-25T11:00:48.634+0800 warning: Failed to connect to 127.0.0.1:27017, reason: errn ...
- 机器学习和深度学习笔记(Matlab语言实现)
不多说,直接上干货! 这里,对于想用matlab语言来做的朋友,强烈推荐 http://www.cnblogs.com/tornadomeet/
- SQL Server中一些有用的日期sql语句
SQL Server中一些有用的日期sql语句 1.一个月第一天的 SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0) 2.本周的星期一 SELECT DA ...
- HDU1007(求近期两个点之间的距离)
一年前学长讲这题的时候,没听懂.自己搜解题报告也看不懂,放了一年. 现在对分治和递归把握的比一年前更加熟悉,这题也就攻克了. 题意:给你一堆点让你求近期两点之间距离的一半,假设用暴力的话O(n*n)明 ...
- Vim升华之树形目录插件NERDTree安装图解【转】
本文转载自:http://www.linuxidc.com/Linux/2013-06/86048.htm 无意中看到实验室的朋友使用的vim竟然能在左边显示树形目录,感觉很方便,这样子文件夹有什么文 ...
- JFreeChart生成饼形图(3) (转自 JSP开发技术大全)
JFreeChart生成饼形图(3) (转自 JSP开发技术大全) 14.3 利用JFreeChart生成饼形图 通过JFreeChart插件,即可以生成普通效果的饼形图,也可以生成3D效果的饼形图: ...
- 工作笔记——sqlserver引号的运用
一. sqlserver引号问题:因为要使用远程连接,所以sql语句要用单引号括起来 SELECT * FROM OPENQUERY ([192.168.***.***] ,'select * fro ...
- linux环境下oracle静默安装
一.安装环境 1.linux版本:redhat6.3_x86_64 2.oracle版本:Oracle Database 11g Enterprise Edition Release 11.2.0.3 ...
- 逆向分析一个完整的C++程序包含寄存器与参数传递详解
最近在分析C++ dump 文件的时候觉得有必要将一些必要的反汇编东西总结一下以备别人参考,自己有时间的时候也可以进行更多的改进.下面通过一个简单的C++代码转成汇编代码后的详细解释说明一下C++和汇 ...
- Code Project精彩系列(转)
Code Project精彩系列(转) Code Project精彩系列(转) Applications Crafting a C# forms Editor From scratch htt ...