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 ...
随机推荐
- nagios 安装配置(包含nrpe端)全 (三)
四.系统的配置: 1.介绍 在配置过程中涉及到的几个定义有:主机.主机组,服务.服务组.联系人.联系人组,监控时间.监控命令等. 最重要的有四点: 第一:定义监控哪些主机.主机组.服务和服务组: 第二 ...
- Python函数参数传递
Python中函数参数的传递是采用传值方式,但是和C/C++有所不同 C/C++方式 void fun(int a) { a = 10; } void main() { int c =3; fun(c ...
- iOS学习之动画效果的实现
// // ViewController.m // UI-动画练习 // // Created by jzq_mac on 15/7/22. // Copyright (c) 2015年 jz ...
- 五------Jsp九大内置对象。
Jsp九大内置对象,当中最基本的是前五个对象. 5-1 out对象 out对象是JSPWriter类的实例.是向client输出内容经常使用的对象. out对象经常使用的方法例如以下: 1.out.p ...
- Android之——AIDL深入
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/47071927 在上一篇博文<Android之--AIDL小结>中,我们 ...
- [Tue, 11 Aug 2015 ~ Mon, 17 Aug 2015] Deep Learning in arxiv
Image Representations and New Domains inNeural Image Captioning we find that a state-of-theart neura ...
- [IT学习]华为全连接大会2017
1.5分钟.3分钟.1分钟倒计时. 2.20万盏纽约街头的油灯接入电网,类比未来的公司IT系统会接入云? 3.1943年,全球只要5台计算机.不会的,但是会有5多云? 4.与航空业的联盟类比,云计算的 ...
- 大括号对struct进行初始化
1 partial initialization 即所谓的部分初始化. 这个时候,无论该struct变量是static的还是automic的,未显式初始化的成员都会被初始化为默认值.
- iOS7 push/pop转场动画
前言 iOS 7之后,苹果提供了自定义转场动画的API,我们可以自己去定义任意动画效果.本篇为笔者学习push.pop自定义转场效果的笔记,如何有任何不正确或者有指导意见的,请在评论中留下您的宝贵意见 ...
- list:[::5]
0-99的数列 L = [0, 1, 2, 3, ..., 99] 所有数,每5个取一个 >>> L[::5] [0, 5, 10, 15, 20, 25, 30, 35, 40, ...