noip 2015 提高组
算是填个坑吧 , QwQ
Day 1
第一题很水,就是考代码能力 ,直接贴代码。
- #include <iostream>
- #include <cstdlib>
- #include <cstdio>
- << , maxn = ;
- using namespace std ;
- int n , jv[maxn][maxn] ;
- inline void Init( )
- {
- freopen( "magic.in" , "r" , stdin ) ;
- freopen( "magic.out" , "w" , stdout ) ;
- }
- int read( )
- {
- , ret = ;
- ; ch = getchar( ) ; }
- + ch - ' , ch = getchar( ) ;
- return ret * k ;
- }
- void sov( )
- {
- , y = (+n)>> ;
- jv[x][y] = ;
- ; i <= n*n ; ++i )
- {
- && y != n )
- {
- jv[n][y+] = i ;
- x = n ; ++y ;
- continue ;
- }
- )
- {
- jv[x-][] = i ;
- --x ; y = ;
- continue ;
- }
- && y == n )
- {
- jv[x+][y] = i ;
- ++x ; continue ;
- }
- else
- {
- ][y+] )
- {
- jv[x-][y+] = i ;
- --x ; ++y ;
- continue ;
- }
- jv[x+][y] = i ;
- ++x ; continue ;
- }
- }
- }
- void output( )
- {
- ; x <= n ; ++x )
- {
- ; y <= n ; ++y )
- printf( "%d " , jv[x][y] ) ;
- printf( "\n" ) ;
- }
- }
- int main( )
- {
- Init( ) ;
- n = read( ) ;
- sov( ) ;
- output( ) ;
- fclose( stdin ) ;
- fclose( stdout ) ;
- ;
- }
第二题
就是求一个有向图的最小正环 , 但分析后就知道每个点只有一个出度 ,所以图中只存在简单环 ,
于是我在考场上用并查集做的 。
- #include <iostream>
- #include <cstdlib>
- #include <cstdio>
- << , maxn = + ;
- using namespace std ;
- ] ; //father and dis
- inline void Init( )
- {
- freopen( "message.in" , "r" , stdin ) ;
- freopen( "message.out" , "w" , stdout ) ;
- }
- int read( )
- {
- , ret = ;
- ; ch = getchar( ) ; }
- + ch - ' , ch = getchar( ) ;
- return ret * k ;
- }
- int find( int x )
- {
- ] == x ) return x ;
- ] ;
- fa[x][] = find( fa[x][] ) ;
- fa[x][] += fa[fu][] ;
- ] ;
- }
- void sov( )
- {
- ; x <= n ; ++x ) fa[x][] = x ;
- int y , root1 , root2 , ans = inf ;
- ; x <= n ; ++x )
- {
- y = read( ) ;
- root1 = find( x ) , root2 = find( y ) ;
- if( root1 != root2 )
- {
- fa[root1][] = root2 ;
- fa[root1][] += + fa[y][] ;
- }
- else
- ans = min( ans , fa[x][] + fa[y][] + ) ;
- }
- printf( "%d\n" , ans ) ;
- }
- int main( )
- {
- Init( ) ;
- n = read( ) ;
- sov( ) ;
- fclose( stdin ) ;
- fclose( stdout ) ;
- ;
- }
后面是先拓扑去不是环里的点,在找最小的环(对每个点打标记,打个标记的点不用遍历。)
- #include <iostream>
- #include <cstdlib>
- #include <cstdio>
- #include <queue>
- << , maxn = + ;
- using namespace std ;
- queue < int > Q ;
- struct id
- {
- int nxt , in ; bool vis ;
- } node[maxn] ;
- ;
- inline void Init( )
- {
- freopen( "message.in" , "r" , stdin ) ;
- freopen( "message.out" , "w" , stdout ) ;
- }
- int read( )
- {
- , ret = ;
- ; ch = getchar( ) ; }
- + ch - ' , ch = getchar( ) ;
- return ret * k ;
- }
- void input( )
- {
- n = read( ) ;
- ; x <= n ; ++x )
- node[x].nxt = read( ) , node[node[x].nxt].in++ ;
- }
- void sov( )
- {
- ; x <= n ; ++x ) if( !node[x].in ) { Q.push( x ) ; node[x].vis = true ; }
- while( !Q.empty( ) )
- {
- int u = Q.front( ) ; Q.pop( ) ;
- int v = node[u].nxt ;
- ) { Q.push( v ) ; node[v].vis = true ; }
- } ans = inf ;
- ; x <= n ; ++x )
- {
- , j = node[x].nxt ;
- if( !node[x].vis )
- {
- while( j != x )
- {
- cnt++ ;
- node[j].vis = true ;
- j = node[j].nxt ;
- }
- ans = min( ans , cnt ) ;
- }
- }
- printf( "%d\n" , ans ) ;
- }
- int main( )
- {
- Init( ) ;
- input( ) ;
- sov( ) ;
- fclose( stdin ) ;
- fclose( stdout ) ;
- ;
- }
当然可以用tajan但我tajan最多只改到90分,就暴栈了QwQ ,不过改成bfs还是可以过,但我没写过 。
第三题就是搜索+剪枝,最开始我以为顺子越长越好,其实并不是QwQ,所以就只有45分 , 然后我就改成枚举了一下顺子的长度,然后就过了。
- #include <iostream>
- #include <cstdlib>
- #include <cstring>
- #include <cstdio>
- #define fo(a,b,c) for(int a=(b);a<=(c);a++)
- << ;
- using namespace std ;
- ] , c[] , ans ;
- inline void Init( )
- {
- freopen( "landlords.in" , "r" , stdin ) ;
- freopen( "landlords.out" , "w" , stdout ) ;
- }
- int read( )
- {
- , ret = ;
- ; ch = getchar( ) ; }
- + ch - ' , ch = getchar( ) ;
- return ret * k ;
- }
- void input( )
- {
- int a , b ;
- fo( i , , n )
- {
- a = read( ) , b = read( ) ;
- ) a = ; else if( a ) a-- ;
- s[a] ++ ;
- }
- }
- int quer( )
- {
- memset( c , , sizeof( c ) ) ;
- fo( i , , ) c[s[i]] ++ ;
- // cout<<c[1]<<" "<<c[2]<<" "<<c[3]<<" "<<c[4]<<endl;
- ;
- ] && c[]> ) c[]-- , c[] -= , tot ++ ;
- ] && c[] > ) c[] -- , c[] -= , tot ++ ;
- ] && c[] ) c[]-- , c[] -- , tot ++ ;
- ] && c[] ) c[]-- , c[]-- , tot ++ ;
- ] && c[] ) c[]-- , c[]-- , tot++ ;
- ] + c[] + c[] + c[] ;
- }
- void dfs( int now )
- {
- if( now >= ans ) return ;
- int tmp = quer( ) ;
- if( tmp + now < ans ) ans = now + tmp ;
- fo( i , , )
- {
- int j = i ;
- ) ++j ;
- )
- {
- fo( j2 , i+ , j- )
- {
- fo( k , i , j2 ) s[k] -= ;
- dfs( now + ) ;
- fo( k , i , j2 ) s[k] += ;
- }
- }
- }
- fo( i , , )
- {
- int j = i ;
- ) ++j ;
- )
- {
- fo( j2 , i+ , j- )
- {
- fo( k , i , j2 ) s[k] -= ;
- dfs( now + ) ;
- fo( k , i , j2 ) s[k] += ;
- }
- }
- }
- fo( i , , )
- {
- int j = i ;
- ) ++j ;
- )
- fo( j2 , i+ , j- )
- {
- fo( k , i , j2 ) --s[k] ;
- dfs( now + ) ;
- fo( k , i , j2 ) ++s[k] ;
- }
- }
- return ;
- }
- int main( )
- {
- Init( ) ;
- t = read( ) , n = read( );
- while( t-- )
- {
- memset( s , , sizeof(s) ) ;
- // memset( c , 0 , sizeof(c) ) ;
- ans = inf ;
- input( ) ;
- dfs( ) ;
- printf( "%d\n" , ans ) ;
- }
- fclose( stdin ) ;
- fclose( stdout ) ;
- ;
- }
day2
第一题比较简单,就是一个二分嘛 ,虽然昨年没写出来qwq(昨年用堆贪心)
- #include <iostream>
- #include <cstdlib>
- #include <cstdio>
- << , maxn = + ;
- using namespace std ;
- int l , n , m , a[maxn] ;
- inline void Init( )
- {
- freopen( "stone.in" , "r" , stdin ) ;
- freopen( "stone.out" , "w" , stdout ) ;
- }
- int read( )
- {
- , ret = ;
- ; ch = getchar( ) ; }
- + ch - ' , ch = getchar( ) ;
- return ret * k ;
- }
- void input( )
- {
- l = read( ) , n = read( ) , m = read( ) ;
- ; x <= n ; ++x ) a[x] = read( ) ;
- a[n+] = l , ++n ;
- }
- bool check( int len )
- {
- , ans = ;
- ; x <= n ; ++x )
- {
- if( a[x] - last < len ) ans++ ;
- else last = a[x] ;
- if( ans > m ) return false ;
- }
- return true ;
- }
- void sov( )
- {
- , rr = l ;
- while( ll <= rr )
- {
- ;
- ;
- ;
- }
- printf( ) ;
- }
- int main( )
- {
- Init( ) ;
- input( ) ;
- sov( ) ;
- fclose( stdin ) ;
- fclose( stdout ) ;
- ;
- }
第二题的话,就是方程式比较难推,QwQ我考场上写的记搜,结果空间复杂度算错 ,本来还是可以骗一点分的 ,
就是个dp,方程式其实还是比较好推,就是要想到一个前缀优化,然后滚一滚就可以过 。
- #include <iostream>
- #include <cstdlib>
- #include <cstdio>
- ;
- using namespace std ;
- int n , m , k ;
- ] , b[] ;
- ][][][] ;
- int main( )
- {
- scanf( "%d%d%d" , &n , &m , &k ) ;
- scanf( , b+ ) ;
- f[][][][] = , f[][][][] = ;
- ; i <= n ; ++i )
- {
- ; j <= min( i , m) ; ++j )
- {
- ; l <= k ; ++l )
- {
- ,last=(i-)&;
- if( a[i] == b[j] )
- {
- f[j][l][][now] = ( f[j-][l-][][last] + f[j-][l-][][last] ) % mod + f[j-][l][][last] ;
- f[j][l][][now] %= mod ;
- f[j][l][][now] = ( f[j][l][][last] + f[j][l][][last] ) % mod ;
- }
- else
- {
- f[j][l][][now] = (f[j][l][][last]+f[j][l][][last])%mod ;
- f[j][l][][now] = ;
- }
- // cout<<j<<" "<<l<<" "<<now<<" "<<f[j][l][1][now]<<" "<<f[j][l][0][now]<<endl;
- }
- }
- }
- printf( ][n&]+f[m][k][][n&])%mod ) ;
- ;
- }
noip 2015 提高组的更多相关文章
- NOIP 2015提高组复赛
神奇的幻方 题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,……,N*N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方法构建一个幻方: 首先将1写在第 ...
- NOIP 2015 提高组 Day2
期望得分:100+10+60=170 实际得分:100+10+35=145 http://www.cogs.pro/cogs/page/page.php?aid=16 T1 跳石头 时间限制:1 s ...
- NOIP 2015 提高组 Day1
期望得分:100+100+100=300 实际得分:100+100+45=245 T3 相似的代码 复制过去 没有改全,痛失55分 http://www.cogs.pro/cogs/page/page ...
- NOIP 2008提高组第三题题解by rLq
啊啊啊啊啊啊今天已经星期三了吗 那么,来一波题解吧 本题地址http://www.luogu.org/problem/show?pid=1006 传纸条 题目描述 小渊和小轩是好朋友也是同班同学,他们 ...
- [NOIp 1998 提高组]Probelm 2 连接多位数【2011百度实习生笔试题】
/*====================================================================== [NOIp 1998 提高组]Probelm 2 连接 ...
- NOIP 2014 提高组 题解
NOIP 2014 提高组 题解 No 1. 生活大爆炸版石头剪刀布 http://www.luogu.org/problem/show?pid=1328 这是道大水题,我都在想怎么会有人错了,没算法 ...
- NOIP 2001 提高组 题解
NOIP 2001 提高组 题解 No 1. 一元三次方程求解 https://vijos.org/p/1116 看见有人认真推导了求解公式,然后猥琐暴力过的同学们在一边偷笑~~~ 数据小 暴力枚举即 ...
- 最优贸易 NOIP 2009 提高组 第三题
题目描述 C 国有 n 个大城市和 m 条道路,每条道路连接这 n 个城市中的某两个城市.任意两个 城市之间最多只有一条道路直接相连.这 m 条道路中有一部分为单向通行的道路,一部分 为双向通行的道路 ...
- NOIP 2006 提高组 t1 能量项链
题目描述 在Mars星球上,每个Mars人都随身佩带着一串能量项链.在项链上有N颗能量珠.能量珠是一颗有头标记与尾标记的珠子,这些标记对应着某个正整数.并且,对于相邻的两颗珠子,前一颗珠子的尾标记一定 ...
随机推荐
- 向OC类中添加默认的协议实现(ProtocolKit)
以forkingdog的PorotocolKit举例 举例 ProtocolKit Protocol extension for Objective-C Usage Your protocol: @p ...
- 黑马程序员-------.net基础知识二
变量 变量代表着一块内存空间,我们可以通过变量名称想内存存/取数据,有变量就不需要我们记忆复杂的内存地址. 向内存中申请一块内存空间的语法: 数据类型 变量名; 变量类型 变量类型 存储位置 自动 ...
- Windows Server以服务方式部署Tomcat
部署免安装版Tomcat7,步骤如下: 解压Tomcat7到指定目录之后,通过命令行定位到 apache-tomcat-7.0.53\bin 目录下面,然后输入 service.bat install ...
- 2D image convolution
在学习cnn的过程中,对convolution的概念真的很是模糊,本来在学习图像处理的过程中,已对convolution有所了解,它与correlation是有不同的,因为convolution = ...
- 定时显示div
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org ...
- bzoj 1902: Zju2116 Christopher lucas定理 && 数位DP
1902: Zju2116 Christopher Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 172 Solved: 67[Submit][Stat ...
- Windows XP系统安装SQL Server 2005(开发版)图解
转自Windows XP系统安装SQL Server 2005(开发版)图解 安装前提:由于有些从网上的下载的项目需要导入SQL Server 2005的数据文件,因此,今天便安装了这个数据库,我的系 ...
- Learning WCF Chapter1 Creating a New Service from Scratch
You’re about to be introduced to the WCF service. This lab isn’t your typical “Hello World”—it’s “He ...
- menuconfig选项
打开一个典型的openwrt中package目录下都能发现两个相同点: ? package/<name> /Makefile ? package/<name> /patches ...
- javascript时间、随机数
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...