Claris大爷出的一套模拟题。问别人要到了一份题,加深了自己NOIp要滚粗的感觉。

Matser

zzDP题,我只能说我第一遍写的时候还写崩了QAQ。

//master
//by Cydiater
//2016.10.21
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <ctime>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long
#define up(i,j,n)		for(int i=j;i<=n;i++)
#define down(i,j,n)		for(int i=j;i>=n;i--)
#define FILE "master"
#define cmax(a,b)	a=max(a,b)
#define cmin(a,b) 	a=min(a,b)
const int MAXN=305;
const int oo=0x3f3f3f3f;
inline int read(){
	char ch=getchar();int x=0,f=1;
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int N,K,f[MAXN][MAXN][MAXN][2];
char s1[MAXN],s2[MAXN];
namespace solution{
	void init(){
		N=read();K=read();
		scanf("%s",s1+1);
		scanf("%s",s2+1);
	}
	void DP(){
		memset(f,0,sizeof(f));
		up(i,1,N)up(j,1,N)up(k,0,K){
			f[i][j][k][0]=max(f[i][j-1][k][0],f[i-1][j][k][0]);
			if(k>0)cmax(f[i][j][k][1],f[i-1][j-1][k-1][1]+1);
			if(s1[i]==s2[j]){
				cmax(f[i][j][k][1],f[i-1][j-1][k][1]+1);
			}
			cmax(f[i][j][k][0],f[i][j][k][1]);
		}
	}
	void output(){
		cout<<f[N][N][K][0]<<endl;
	}
}
int main(){
	freopen(FILE".in","r",stdin);
	freopen(FILE".out","w",stdout);
	using namespace solution;
	init();
	DP();
	output();
	return 0;
}

Tour

通过这道题学到了bitset的简单用法,很实用。

那道题的时候想了想搞到了70分的做法,卡在了如何$O(1)$求三元环的算法上,事实证明不一定要$O(1)$,用bitset小优化一下就行了。

这道题充分说明了降维思想的重要性。

//tour
//by Cydiater
//2016.10.21
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <ctime>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <bitset>
#include <cstdio>
using namespace std;
#define ll long long
#define up(i,j,n)		for(int i=j;i<=n;i++)
#define down(i,j,n)		for(int i=j;i>=n;i--)
#define FILE "tour"
#define LENGTH 1500
#define bs bitset<LENGTH>
const int MAXN=1505;
const int oo=0x3f3f3f3f;
inline int read(){
	char ch=getchar();int x=0,f=1;
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int N,LEN,cnt[MAXN];
bool mat[MAXN][MAXN];
char s[MAXN];
ll ans=0;
struct BITSET{
	bs v;
}Match[MAXN];
namespace solution{
	inline int lowbit(int i){return i&(-i);}
	void init(){
		N=read();LEN=(N-1)/LENGTH+1;
		memset(cnt,0,sizeof(cnt));
		up(i,1,N){
			scanf("%s",s+1);
			up(j,1,N)if((mat[i][j]=s[j]-'0')==1)cnt[i]++;
			int now=1;
			up(j,1,LEN){
				bs S(0),tmp;
				up(k,now,min(N,now+LENGTH-1))
					if(mat[i][k])
						Match[i].v[k-now]=1;;
				now+=LENGTH;
			}
		}
	}
	int get(int x,int y){
		return (Match[x].v&Match[y].v).count();
	}
	void slove(){
		up(i,1,N)up(j,i+1,N)if(i!=j&&mat[i][j]){
			ans+=(ll)(cnt[i]-1)*(ll)(cnt[j]-1)*2LL;
			ans-=get(i,j)*2LL;
		}
	}
	void output(){
		cout<<ans<<endl;
	}
}
int main(){
	freopen(FILE".in","r",stdin);
	freopen(FILE".out","w",stdout);
	using namespace solution;
	init();
	slove();
	output();
	//cout<<"Time has passed:"<<1.0*clock()/1000<<"s!"<<endl;
	return 0;
}

Walk

做的时候最没有头绪的一道题。需要在原图上加点建立一个新图,新建的分别代表$[0,2^{20}-1]$上的每一个点,然后每个点向其二进制下有且只要以为不为1的连边,然后对于原图上的每个点,指向对应的新点一条边权为1的边,然后反向连一条边权为0的边。然后大力BFS,需要注意的是每次应该把所有与其距离为0的都加入队列中。

//walk
//by Cydiater
//2016.10.23
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
using namespace std;
#define ll long long
#define up(i,j,n)		for(int i=j;i<=n;i++)
#define down(i,j,n)		for(int i=j;i>=n;i--)
#define FILE "walk"
const int MAXN=2e6+5;
const int oo=0x3f3f3f3f;
inline int read(){
	char ch=getchar();int x=0,f=1;
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int N,M,V[1300000],LINK[1300000],len=0,head,tail,q[1300000],dis[1300000];
bool vis[1300000];
struct edge{
	int y,next,v;
}e[MAXN*10];
namespace solution{
	inline void insert(int x,int y,int v){e[++len].next=LINK[x];LINK[x]=len;e[len].y=y;e[len].v=v;}
	void init(){
		N=read();M=read();
		up(i,1,N)V[i]=read();
		up(i,1,M){
			int x=read(),y=read();
			insert(x,y,1);
		}
		up(i,0,(1<<20)-1){
			up(j,0,19)if(((1<<j)&(i))==(1<<j)){
				int x=i,y=i^(1<<j);
				insert(N+1+x,N+1+y,0);
			}
		}
		up(i,1,N){
			insert(i,N+1+V[i],1);
			insert(N+1+V[i],i,0);
		}
	}
	void ADD(int node){
		q[++tail]=node;vis[node]=1;
		for(int i=LINK[node];i;i=e[i].next)if(!vis[e[i].y]&&!e[i].v){
			dis[e[i].y]=dis[node];
			ADD(e[i].y);
		}
	}
	void slove(){
		memset(vis,0,sizeof(vis));
		memset(dis,0,sizeof(dis));
		head=1;tail=0;q[++tail]=1;
		dis[1]=0;vis[1]=1;
		for(;head<=tail;head++){
			int node=q[head];
			for(int i=LINK[node];i;i=e[i].next)if(!vis[e[i].y]){
				dis[e[i].y]=dis[node]+e[i].v;
				ADD(e[i].y);
			}
		}
		up(i,2,N)if(dis[i]==0)dis[i]=-1;
	}
	void output(){
		up(i,1,N)printf("%d\n",dis[i]);
	}
}
int main(){
	freopen(FILE".in","r",stdin);
	freopen(FILE".out","w",stdout);
	using namespace solution;
	init();
	slove();
	output();
	return 0;
}

NOIp2016 十连测 round1的更多相关文章

  1. noip2016十连测round1

    A:String Master 题目:所谓最长公共子串,比如串 A:"abcde",串 B:"jcdkl",则它们的最长公共子串为串 "cd" ...

  2. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  3. noip2016十连测round3

    A:平均数 题意:有一天,小 A 得到了一个长度为 n 的序列. 他把这个序列的所有连续子序列都列了出来,并对每一个子序列都求了其平均值,然后他把这些平均值写在纸上,并对它们进行排序,最后他报出了第 ...

  4. noip2016十连测round2

    A: Divisors 题意:给定 m 个不同的正整数 a 1 ,a 2 ,...,a m ,请对 0 到 m 每一个 k 计算,在区间 [1,n] 里有多少正整数 是 a 中恰好 k 个数的约数. ...

  5. Problem C: [noip2016十连测第五场]travel (构造+贪心)

    题面 https://www.lydsy.com/JudgeOnline/upload/201610/statements(1).pdf 题解 好神仙的贪心-- 首先无解的情况很容易判断,就是\(l= ...

  6. bzoj 5216 [Lydsy2017省队十连测]公路建设 线段树维护 最小生成树

    [Lydsy2017省队十连测]公路建设 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 93  Solved: 53[Submit][Status][ ...

  7. bzoj 5216: [Lydsy2017省队十连测]公路建设

    5216: [Lydsy2017省队十连测]公路建设 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 66  Solved: 37[Submit][St ...

  8. 提高十连测day3

    提高十连测day3 A 我们可以枚举两个 $ 1 $ 之间的相隔距离,然后计算形如 $ 00100100 \cdots $ 的串在原串中最⻓⼦序列匹配即可,复杂度 $ O(n^2) $ .寻找 $ S ...

  9. ZROI2019 提高十连测

    额 掰手指头一数 特么又是第三年十连测了= = 2017一场没打 那时候好像一场比赛也就100人左右 2018前几场还都好好补了 后来开始放飞自我了 这时候一场有150人还多了 2019想让今年的No ...

随机推荐

  1. 思考:用开发移动app的观念来开发网站

    首先祝大家新年快乐.万事如意. 开发网站程序也有一些年头了,从最初的静态HTML+ JS,到后来的WebForm,然后过渡到现在的MVC. 由于最近做一些技术调研,也接触了很多移动开发,iOS和And ...

  2. Windows下使用Xshell建立反向隧道

    反向隧道是一个进行内网穿透的简单而有用的方法.在Linux下通过OpenSSH和AutoSSH可以很容易地建立稳定的反向隧道.但是在Windows下,还能看到有人特意装个Cygwin来运行这些工具…… ...

  3. VIEW SERVER STATE permission was denied on object 'server', database 'master'

    今天一同事反馈使用SQL Server 2012 Management Studio连接SQL Server 2014后,选择数据库中某个表,然后单击右键时,就会遇到下面错误: 这个错误初看以为是权限 ...

  4. .NET/ASP.NET MVC(模块化开发AraeRegistration)

    阅读目录: 1.开篇介绍 2.AreaRegistration注册路由(传递路由上下文进行模块化注册) 1]开篇介绍 ASP.NET Routing 路由功能非常强大,设计的也很巧妙:如果说ASP.N ...

  5. SQL Server 2008 R2——统计各部门某年入职人数

    =================================版权声明================================= 版权声明:原创文章 谢绝转载  请通过右侧公告中的“联系邮 ...

  6. Linux 如何实现 VLAN - 每天5分钟玩转 OpenStack(12)

    LAN 表示 Local Area Network,本地局域网,通常使用 Hub 和 Switch 来连接 LAN 中的计算机.一般来说,两台计算机连入同一个 Hub 或者 Switch 时,它们就在 ...

  7. Start Instance 操作详解 - 每天5分钟玩转 OpenStack(31)

    本节通过日志文件详细分析 instance start 操作. 下面是 start instance 的流程图 向 nova-api 发送请求 nova-api 发送消息 nova-compute 执 ...

  8. Centos 6.5 Zookeeper 安装

    tar -xvf zookeeper-3.4.8.tar.gz 修改配置文件 测试 上传启动脚本,内容如下: #!/bin/bash #chkconfig:2345 20 90 #descriptio ...

  9. Ubuntu 部署Postgresql

    安装组件 客户端安装 sudo apt-get install postgresql-client 服务器安装 sudo apt-get install postgresql postgresql-c ...

  10. vb上位机模拟电压监测系统

    vb作为一种古老的语言,在工作中已经用不到了,但这门语言也是我在校期间研究比较多的一种,基本的通讯,数据库,界面等模块已经比较了解,马上要进单位实习了,研究的是电机的变频器,软件这块,希望在以后的工作 ...