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. RMAN冷备份异机还原

    1:环境准备 在新的服务器上安装ORACLE实例,安装过程中需要注意源服务器与目标服务器的ORACLE_SID一致,另外确保安装路径与源路径一致(不仅是安装目录,甚至包括数据文件.控制文件目录.联机重 ...

  2. .NET应用架构设计—重新认识分层架构(现代企业级应用分层架构核心设计要素)

    阅读目录: 1.背景介绍 2.简要回顾下传统三层架构 3.企业级应用分层架构(现代分层架构的基本演变过程) 3.1.服务层中应用契约式设计来解决动态条件不匹配错误(通过契约式设计模式来将问题在线下暴露 ...

  3. 笔记整理之 Bulk Insert

    之前2篇日志整理了BCP大致的用法,这次整理一下它的兄弟 Bulk Insert 的写法以及和bcp那边的结合的用法. 首先,Bulk Insert 语句要在连接了Sql Server 服务器之后才执 ...

  4. 使用Docker快速部署Storm环境

    Storm的部署虽然不是特别麻烦,但是在生产环境中,为了提高部署效率,方便管理维护,使用Docker来统一管理部署是一个不错的选择.下面是我开源的一个新的项目,一个配置好了storm与mono环境的D ...

  5. 7 Must Read Python Books

    7 Must Read Python Books I started learning Python just two years ago. Coming from a C++ and Java ba ...

  6. 如何区分/dev/input/event

    方法是把每一个/dev/input/event打开.通过ioctl函数来读取设备name,每一个设备name是固定的,可以根据name区分event.我这是查找触摸事件为例:代码如下: static ...

  7. 标题栏Menu

    标题栏menu就是指下图中红框里面的菜单按钮. 标题栏上所有的按钮或者其他元素都定义在xml文件里面,这些文件资源称为menu resource.要在标题栏添加按钮,需要在项目的/res/menu/路 ...

  8. 找不到mysql.sock,mysql.sock丢失问题解决方法

    Can 't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock '(2) "; 是你的mysql ...

  9. mysql 优化(一)

    SHOW VARIABLES like 'slow_query_log'  #查看慢查询设置  1 set GLOBAL slow_query_log_file ="d:/sql/sql_l ...

  10. java进程占用CPU资源过高分析脚本

    #!/bin/bash #输入占用CPU较高的进程号 pid=$ if [ -z $pid ] then echo "PID is NULL" exit fi #找到该进程中占用较 ...