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 ...
随机推荐
- WWDC-UIKit 中协议与值类型编程实战
本文为 WWDC 2016 Session 419 的部分内容笔记.强烈推荐观看. 设计师来需求了 在我们的 App 中,通常需要自定义一些视图.例如下图: 我们可能会在很多地方用到右边为内容,左边有 ...
- Java Socket 学习笔记
TCP协议的Socket编程 Socket:英文中的意思是插座.两个Java应用程序可以通过一个双向的网络通信连接实现数据交换,这个双向链路的一端称为一个Socket.Java中所有关于网络编程的类都 ...
- uploadify插件实现多个图片上传并预览
使用uploadify插件可方便实现图片上传功能.兼容ie6.ie7. 上传成功之后使用插件的回调函数读取json数据,根据url实现图片预览. 效果图: 点击浏览文件上传图片,图片依次在右侧显示预览 ...
- JAVA导出Excel封装
1.数据bean public class ExcelBean { private String name; private String sheetName; private ExcelTitle[ ...
- EF结合SqlBulkCopy在项目中的使用
这是我第一次写博客,由于水平有限,写不出什么好东西,还望见谅. 我现在参与的这个项目采用的是EF框架,方便了数据库的访问.但在实际中,发现项目中导入市县Excel数据耗时太长,于是趁这段时间专门研究了 ...
- Android开发文摘集合1
作者:张明云 原标题:Android 开发中,有哪些坑需要注意? 作者github主页:zmywly8866.github.io/ 在Android library中不能使用switch-case语句 ...
- 前端过滤XSS攻击
日常开发过程中,对于存在用户交互的一些门户网站等,过滤xss攻击是必不可少的. 此处主要记录下我在工作过程中的简单处理方法. 前端过滤XSS攻击, 我这里用的是开源工程 js-xss,官网地址:htt ...
- 内网映射到公网工具 --- ngrok
ngrok可以将内网映射到公网上,这样就可以在公网上访问你的网络服务. 该工具通常在进行app开发和微信开发时比较有用,这样就可避免在公网服务器上单独部署项目,通过映射,直接连接本地服务即可进行开发. ...
- Android开发--二维码开发应用(转载!)
android项目开发 二维码扫描 基于android平台的二维码扫描项目,可以查看结果并且链接网址 工具/原料 zxing eclipse 方法/步骤 首先需要用到google提供的zxin ...
- LENGTH和LENGTHB函数,substrb截取也是同一个道理。
oracle 利用 LENGTH和LENGTHB函数区分中英文(2009-02-07 10:49:29) 转载▼ 标签: it 分类: oracle 前一段时间,我一朋友问我怎么得出这个字符串是中文还 ...