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. CREATE FILE encountered operating system error 5(Access is denied.)

    这篇博文主要演示"CREATE FILE encountered operating system error 5(Access is denied.)"错误如出现的原因(当然只是 ...

  2. Java环境变量的配置

    1.JAVA_HOMEjdk的路径,我的是安装在C:\Program Files (x86)\Java\jdk1.6.0_182.CLASSPATH .;%JAVA_HOME%\lib\dt.jar; ...

  3. Linux下使用 Memory Analyzer

    一. 安装Memory Analyzer Tool 打开eclipse >> Help >> Install New Software >> 点击Work With ...

  4. PHP-SplDoublyLinkedList

    <?php /** * @package a doubly linked list test * @author zhaoyingnan<zhaoyn@bbtree.com> * @ ...

  5. 推荐一款 chrome SSH 插件 - Secure Shell

    http://blog.csdn.net/jizhongchun/article/details/8519413 导读:我就是一个Chrome Fans.最近发现一款google官方出的SSH插件 - ...

  6. UI自动化,你值得拥有

    去年春节联欢晚会,为了那张“敬业福”,全家都卯足了劲儿“咻一咻”,连节目都顾不上看了.当时我就想,要是能自动化该多好,不停点击屏幕,屏幕不疼手还疼呢,何况还不好分心,生怕错过了“敬业福”.玩“咻一咻” ...

  7. Hibernate一对多关联

    一对多双向关联关系:(Dept/Emp的案例) 既可以根据在查找部门时根据部门去找该部门下的所有员工,又能在检索员工时获取某个员工所属的部门. 步骤如下: 1.构建实体类(部门实体类加set员工集合) ...

  8. Struts2 使用jQuery实现Ajax

    在jQuery中将Ajax相关的操作进行封装,使用时只需在合适的地方调用Ajax相关的方法即可,相比而言,使用jQuery实现Ajax更加简洁,方便 1.$.Ajax()可以通过发送Http请求加载远 ...

  9. aop

    做aop做一些事情::: package cn.happy.spring04aop; public interface ISomeService { public void doSomeThing() ...

  10. winform窗体控件(全)

    回顾跟补充下除了昨天那常用6个其他的winform窗体控件作用 1:Button:按钮 (1)AutoSize:如果是True的情况下,内容将会撑开:False的话会另起一行 (2)Enabled: ...