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 ...
随机推荐
- Selenium系列之--02 不同浏览器获取Xpath的方法
一.Chrome浏览器 1.1 获取XPath 1. 使用浏览器打开需测试的网址,然后点击[F12]按钮,打开开发者调试工具: 2. 点击开发者工具中第一行的第一个对话框Elements,这时就看 ...
- poj2488--A Knight's Journey(dfs,骑士问题)
A Knight's Journey Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 31147 Accepted: 10 ...
- 暴力破解unix/linux平台上采用crypt加密的口令
# coding=utf-8 ''' 暴力破解crypt模块加密的密码 ''' import crypt import optparse usage = 'Usage: %prog [optinos] ...
- Linux上ln命令详细说明及软链接和硬链接的区别
硬链接(hard link) UNIX文件系统提供了一种将不同文件链接至同一个文件的机制,我们称这种机制为链接.它可以使得单个程序对同一文件使用不同的名字.这样的好处是文件系 统只存在一个文件的副本, ...
- Spring Cloud Sleuth 中id的使用
Spring Cloud Sleuth采用的是Google的开源项目Dapper的专业术语. Span:基本工作单元,发送一个远程调度任务 就会产生一个Span,Span是一个64位ID唯一标识的,T ...
- centOS安装mysql---glibc方式
写在前面: 首先,centos是自己集成mysql的.但是我要用的服务器人家没给装. 其次,centos是可以yum安装mysql的,我很高兴而且轻松的用yum把mysql安装上了.但是,运行的时候很 ...
- 实现静默安装APK的方法
需要满足的条件: 内置到ROM.即APK包的安装位置是/system/app下. 下面以 test.apk 为例,演示这个操作.需要准备一台已经获得 Root 权限的手机. 1.通过 USB 连接手机 ...
- 并不对劲的bzoj4868: [Shoi2017]期末考试
传送门-> 三分裸题. 发现答案只和最后一个科目公布成绩的时间有关. 科目公布成绩的时间越早,老师们的不愉快度越高,这个时间越晚,学生们的不愉快度越高. 它看上去像个单峰的,那么就三分好了. 判 ...
- 小程序-文章:微信小程序常见的UI框架/组件库总结
ylbtech-小程序-文章:微信小程序常见的UI框架/组件库总结 1.返回顶部 1. 想要开发出一套高质量的小程序,运用框架,组件库是省时省力省心必不可少一部分,随着小程序日渐火爆,各种不同类型的小 ...
- asp.net mvc 多字段排序
以下代码可实现多字段排序,通过点击列标题,实现排序. 控制器: public ActionResult Index(string sortOrder) { ViewBag.FirstNameSortP ...