NOIp2016 十连测 round1
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的更多相关文章
- noip2016十连测round1
A:String Master 题目:所谓最长公共子串,比如串 A:"abcde",串 B:"jcdkl",则它们的最长公共子串为串 "cd" ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- noip2016十连测round3
A:平均数 题意:有一天,小 A 得到了一个长度为 n 的序列. 他把这个序列的所有连续子序列都列了出来,并对每一个子序列都求了其平均值,然后他把这些平均值写在纸上,并对它们进行排序,最后他报出了第 ...
- noip2016十连测round2
A: Divisors 题意:给定 m 个不同的正整数 a 1 ,a 2 ,...,a m ,请对 0 到 m 每一个 k 计算,在区间 [1,n] 里有多少正整数 是 a 中恰好 k 个数的约数. ...
- Problem C: [noip2016十连测第五场]travel (构造+贪心)
题面 https://www.lydsy.com/JudgeOnline/upload/201610/statements(1).pdf 题解 好神仙的贪心-- 首先无解的情况很容易判断,就是\(l= ...
- bzoj 5216 [Lydsy2017省队十连测]公路建设 线段树维护 最小生成树
[Lydsy2017省队十连测]公路建设 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 93 Solved: 53[Submit][Status][ ...
- bzoj 5216: [Lydsy2017省队十连测]公路建设
5216: [Lydsy2017省队十连测]公路建设 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 66 Solved: 37[Submit][St ...
- 提高十连测day3
提高十连测day3 A 我们可以枚举两个 $ 1 $ 之间的相隔距离,然后计算形如 $ 00100100 \cdots $ 的串在原串中最⻓⼦序列匹配即可,复杂度 $ O(n^2) $ .寻找 $ S ...
- ZROI2019 提高十连测
额 掰手指头一数 特么又是第三年十连测了= = 2017一场没打 那时候好像一场比赛也就100人左右 2018前几场还都好好补了 后来开始放飞自我了 这时候一场有150人还多了 2019想让今年的No ...
随机推荐
- [转]oracle 实施方法论学习心得
本周由部门新入职的同事为我们分享oracle实施方法论,本次重点围绕项目启动会来做介绍,并着重介绍了oracle与我们不一样的地方.收获颇丰,简单总结几个值得学习借鉴的要点: 1. 细节 ...
- Ignite 配置更新Oracle JDBC Drive
如果使用Oracle 12C 作为Ignite 的Repository的话,在Repository Createion Wizard的配置过程中,会出现ORA-28040:No matc ...
- Python基础2
入门知识拾遗 一.作用域 对于变量的作用域,执行声明并在内存中存在,该变量就可以在下面的代码中使用. if 1==1: name = 'yuxiaozheng' print name 外层变量,可以被 ...
- Oracle索引梳理系列(六)- Oracle索引种类之函数索引
版权声明:本文发布于http://www.cnblogs.com/yumiko/,版权由Yumiko_sunny所有,欢迎转载.转载时,请在文章明显位置注明原文链接.若在未经作者同意的情况下,将本文内 ...
- IntelliJ IDEA 配置运行程序
IntelliJ IDEA 对于Javaer开发来说还是很nice的,就是第一次用可能配置项有点生疏,这里就记录一下IntelliJ IDEA 配置运行程序. 1. 点击Edit Config... ...
- 设置DIV可编辑
<div id="move" contentEditable="true">可编辑</div> 设置contentEditable属性可 ...
- Shell基础学习小结
0 shell基础概念 Shell是解释性语言,使用脚本编程语言的好处是,它们多半运行在比编译型语言还高的层级,能够轻易处理文件与目录之类的对象:缺点是它们的效率通常不如编译型语言.Shell命令有本 ...
- JS重载
Js 不支持函数的重载,可以用相同的名字在同一作用区域,定义两个函数,而不会引起错误,但真正使用的是最后一个. Js 不会验证传递给函数的参数个数是否和函数定义的参数的个数相同,开发人员定义的函数都可 ...
- http协议进阶(三)http报文
一.报文流 http报文是在http应用程序之间发送的数据块(也可称为数据包).这些数据块以一些文本的元信息(meta-information)开头,描述了报文的内容及含义,后面跟着 可选的数据部分, ...
- android第一行代码-1.项目结构
0.项目结构 一个简单的android项目结构大致如下 入口就是MainActivity这个类,如果对于一个陌生的项目,最好的办法是看AndroidMainifest.xml,如下 <?xml ...