CH Round #58 - OrzCC杯noip模拟赛day2
A:颜色问题
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题
题解:算一下每个仆人到它的目的地的时间取max即可
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 1500000
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,f[maxn],head[maxn];
struct edge{int go,next;}e[maxn];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();
for1(i,n)
{
int x=read();
e[i].go=i;e[i].next=head[x];head[x]=i;
f[i]=inf;
}
for1(i,n)
{
int x=read();
for(int j=head[x];j;j=e[j].next)
{
int y=e[j].go;
if(y>=i)f[y]=min(f[y],y-i+);else f[y]=min(f[y],n-i+y+);
}
}
int ans=;
for1(i,n)ans=max(ans,f[e[i].go]);
printf("%d\n",ans==inf?-:ans);
return ;
}
B:树的问题
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/树的问题
题解:如果x和y的LCA不是其中任意一个,那么答案显然是s[x]+s[y],画一下图就知道
否则不妨设LCA(x,y)=x,则ans=n-(s[son[x]]-s[y]) 其中son[x]是 x 走向 y的第一个点,画一下图就可以知道。。。
而son[x]不能dfs求,只要把y倍增上去即可。需要思考一下。
具体看代码
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 300000
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,m,head[maxn],tot,fa[maxn],s[maxn],f[maxn][],dep[maxn];
struct edge{int go,next;}e[*maxn];
inline void insert(int x,int y)
{
e[++tot].go=y;e[tot].next=head[x];head[x]=tot;
e[++tot].go=x;e[tot].next=head[y];head[y]=tot;
}
void dfs(int x)
{
s[x]=;
for1(i,)
if((<<i)<=dep[x])f[x][i]=f[f[x][i-]][i-];
else break;
for(int i=head[x],y;i;i=e[i].next)
if(!dep[y=e[i].go])
{
dep[y]=dep[x]+;
f[y][]=x;
dfs(y);
s[x]+=s[y];
}
}
bool lca(int x,int y)
{
int ans=;
if(dep[x]<dep[y])swap(x,y);
int t=dep[x]-dep[y];
for0(i,)
if(t&(<<i))x=f[x][i];
return x==y;
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();m=read();
for1(i,n-)insert(read(),read());
dep[]=;
dfs();
while(m--)
{
int x=read(),y=read();
if(dep[x]>dep[y])swap(x,y);
if(!lca(x,y))printf("%d\n",s[x]+s[y]);
else
{
int t=dep[y]-dep[x]-,w=y;
for0(i,)if(t&(<<i))w=f[w][i];
printf("%d\n",n-(s[w]-s[y]));
}
}
return ;
}
C:比赛问题
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/比赛问题
题解:刚开始把题看简单了,直接一个n*m*k*k的DP。。。还感叹怎么这么水。。。
后来发现这k*k个方格的状态是有后效性的T_T
然后发现好像可以状压得70,但我感觉我写不出来或者写出来调不出来,然后就交了错误的程序弃疗了。。。
最后居然有40QAQ
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 150
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,x,y,xx,yy,f[maxn][maxn];
bool a[maxn][maxn],b[maxn][maxn];
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();m=read();k=read();x=read();y=read();xx=read();yy=read();
for1(i,k)for1(j,k)
{
char ch=' ';
while(ch!=''&&ch!='')ch=getchar();
a[i][j]=ch=='';
}
for1(i,n)for1(j,m)
{
char ch=' ';
while(ch!='B'&&ch!='W')ch=getchar();
b[i][j]=ch=='W';
}
memset(f,,sizeof(f));
f[x][y]=;
for1(i,k)
for1(j,k)
if(a[i][j]&&b[x+i-][y+j-])f[x][y]++;
for2(i,x,xx)
for2(j,y,yy)
if(i!=x||j!=y)
{
int tmp=;
for1(ii,k-)
for1(jj,k)
if(a[ii][jj]&&!a[ii+][jj]&&b[i+ii-][j+jj-])tmp++;
for1(jj,k)if(a[k][jj]&&b[i+k-][j+jj-])tmp++;
f[i][j]=min(f[i][j],f[i-][j]+tmp);
tmp=;
for1(ii,k)
for1(jj,k-)
if(a[ii][jj]&&!a[ii][jj+]&&b[i+ii-][j+jj-])tmp++;
for1(ii,k)if(a[ii][k]&&b[i+ii-][j+k-])tmp++;
f[i][j]=min(f[i][j],f[i][j-]+tmp);
//cout<<i<<' '<<j<<' '<<f[i][j]<<endl;
}
printf("%d\n",f[xx][yy]);
return ;
}
CH Round #58 - OrzCC杯noip模拟赛day2的更多相关文章
- 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...
- 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...
- 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...
- 【强联通分量缩点】【最长路】【spfa】CH Round #59 - OrzCC杯NOIP模拟赛day1 队爷的讲学计划
10分算法:对于城市网络为一条单向链的数据, 20分算法:对于n<=20的数据,暴力搜出所有的可能路径. 结合以上可以得到30分. 60分算法:分析题意可得使者会带着去的城市也就是这个城市所在强 ...
- 【离散化】【扫描线】CH Round #59 - OrzCC杯NOIP模拟赛day1 队爷的新书
//上图绿色扫描线右侧少画了一条扫描线. 很多区间把数轴分成了很多段,看哪个点的(区间覆盖数*该点权值)最大. 显然在某个区间的右端点的答案是最优的. 排序后 用扫描线从左到右扫描,维护每个点的覆盖数 ...
- CH Round #59 - OrzCC杯NOIP模拟赛day1
第一题:队爷的新书 题意简述:给定n个闭区间,求出一个数p使它与包含它的区间数的积最大,输出这个积. 分析:使用一个差分数组g,每个区间[l,r],l位置加1,r+1的位置减1,从前往后统计,得到对于 ...
- CH Round #49 - Streaming #4 (NOIP模拟赛Day2)
A.二叉树的的根 题目:http://www.contesthunter.org/contest/CH%20Round%20%2349%20-%20Streaming%20%234%20(NOIP 模 ...
- CH Round #55 - Streaming #6 (NOIP模拟赛day2)
A.九九归一 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2355%20-%20Streaming%20%236%20(NOIP模拟赛day2)/九九归一 题 ...
- CH Round #55 - Streaming #6 (NOIP模拟赛day2)解题报告
T1九九归一 描述 萌蛋在练习模n意义下的乘法时发现,总有一些数,在自乘若干次以后,会变成1.例如n=7,那么5×5 mod 7=4,4×5 mod 7=6,6×5 mod 7=2,2×5 mod 7 ...
随机推荐
- Android 6.0 双卡拨号
相关 api getCallCapablePhoneAccountsAdded in API level 23 Android 5.0 之前的版本 Call from second sim 获取 si ...
- PL/SQL 批量SQL
批量SQL包括: FORALL语句 BULK COLLECT子句 FORALL语句 FORALL具有如下结构: FORALL loop_counter IN bounds_clause [SAVE E ...
- 【转】伟大的RAC和MVVM入门(一)
原文:http://www.sprynthesis.com/2014/12/06/reactivecocoa-mvvm-introduction/ 翻译自ReactiveCocoa and MVV ...
- SSL VPN 详解
SSL VPN是专栏VPN系列技术原理的最后一篇,SSL VPN作为远程接入型的VPN,已经具备非常广阔的前景,它的主要适应场景是取代L2TP Over IPSec,但功能要比L2TP Over IP ...
- gulp-htmlmin可以压缩html的gulp插件
通过一条命令用Npm安装gulp-htmlmin: npm install gulp-htmlmin --save-dev 安装完毕后,打开gulpfile.js文件,我们里面编写一个task用来专门 ...
- 完整的 dataType=text/plain jquery ajax 登录验证
Html: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <m ...
- linux负载均衡
1.linux lvs nat实现负载均衡 添加两块网卡并开启路由管道 > /proc/sys/net/ipv4/ip_forward //开始路由管道 安装ipvsadm yum instal ...
- Getopt::Long 模块的简单使用
用法简介 1.带值参数传入程序内部 ※参数类型:整数, 浮点数, 字串 GetOptions( 'tag=s' => \$tag ); ‘=’表示此参数一定要有参数值, 若改用’:'代替表示参数 ...
- 运用BeanUtils构建通用的查询 更新方法(个人拙作,不喜勿喷)
------------------------------------更新方法----------------------------------- public void update(Strin ...
- 性能测试实践-linux
需求:线上系统性能优化,查找服务器和线上系统瓶颈 根据线上经验数据及期望值定量 数据 up down 线上数据 50 500 测试数据 100 500~2000+ 测试数据 200 500~200 ...