算是填个坑吧 , QwQ

Day 1

第一题很水,就是考代码能力 ,直接贴代码。

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstdio>
  4. << , maxn = ;
  5. using namespace std ;
  6. int n , jv[maxn][maxn] ;
  7. inline void Init( )
  8. {
  9. freopen( "magic.in" , "r" , stdin ) ;
  10. freopen( "magic.out" , "w" , stdout ) ;
  11. }
  12.  
  13. int read( )
  14. {
  15. , ret = ;
  16. ; ch = getchar( ) ; }
  17. + ch - ' , ch = getchar( ) ;
  18. return ret * k ;
  19. }
  20.  
  21. void sov( )
  22. {
  23. , y = (+n)>> ;
  24. jv[x][y] = ;
  25. ; i <= n*n ; ++i )
  26. {
  27. && y != n )
  28. {
  29. jv[n][y+] = i ;
  30. x = n ; ++y ;
  31. continue ;
  32. }
  33. )
  34. {
  35. jv[x-][] = i ;
  36. --x ; y = ;
  37. continue ;
  38. }
  39. && y == n )
  40. {
  41. jv[x+][y] = i ;
  42. ++x ; continue ;
  43. }
  44. else
  45. {
  46. ][y+] )
  47. {
  48. jv[x-][y+] = i ;
  49. --x ; ++y ;
  50. continue ;
  51. }
  52. jv[x+][y] = i ;
  53. ++x ; continue ;
  54. }
  55. }
  56. }
  57.  
  58. void output( )
  59. {
  60. ; x <= n ; ++x )
  61. {
  62. ; y <= n ; ++y )
  63. printf( "%d " , jv[x][y] ) ;
  64. printf( "\n" ) ;
  65. }
  66. }
  67.  
  68. int main( )
  69. {
  70. Init( ) ;
  71. n = read( ) ;
  72. sov( ) ;
  73. output( ) ;
  74. fclose( stdin ) ;
  75. fclose( stdout ) ;
  76. ;
  77. }

第二题

就是求一个有向图的最小正环 , 但分析后就知道每个点只有一个出度 ,所以图中只存在简单环 ,

于是我在考场上用并查集做的 。

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstdio>
  4. << , maxn = + ;
  5. using namespace std ;
  6. ] ; //father and dis
  7.  
  8. inline void Init( )
  9. {
  10. freopen( "message.in" , "r" , stdin ) ;
  11. freopen( "message.out" , "w" , stdout ) ;
  12. }
  13.  
  14. int read( )
  15. {
  16. , ret = ;
  17. ; ch = getchar( ) ; }
  18. + ch - ' , ch = getchar( ) ;
  19. return ret * k ;
  20. }
  21.  
  22. int find( int x )
  23. {
  24. ] == x ) return x ;
  25. ] ;
  26. fa[x][] = find( fa[x][] ) ;
  27. fa[x][] += fa[fu][] ;
  28. ] ;
  29. }
  30.  
  31. void sov( )
  32. {
  33. ; x <= n ; ++x ) fa[x][] = x ;
  34. int y , root1 , root2 , ans = inf ;
  35. ; x <= n ; ++x )
  36. {
  37. y = read( ) ;
  38. root1 = find( x ) , root2 = find( y ) ;
  39. if( root1 != root2 )
  40. {
  41. fa[root1][] = root2 ;
  42. fa[root1][] += + fa[y][] ;
  43. }
  44. else
  45. ans = min( ans , fa[x][] + fa[y][] + ) ;
  46. }
  47. printf( "%d\n" , ans ) ;
  48. }
  49.  
  50. int main( )
  51. {
  52. Init( ) ;
  53. n = read( ) ;
  54. sov( ) ;
  55. fclose( stdin ) ;
  56. fclose( stdout ) ;
  57. ;
  58. }

后面是先拓扑去不是环里的点,在找最小的环(对每个点打标记,打个标记的点不用遍历。)

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstdio>
  4. #include <queue>
  5. << , maxn = + ;
  6. using namespace std ;
  7. queue < int > Q ;
  8. struct id
  9. {
  10. int nxt , in ; bool vis ;
  11. } node[maxn] ;
  12. ;
  13.  
  14. inline void Init( )
  15. {
  16. freopen( "message.in" , "r" , stdin ) ;
  17. freopen( "message.out" , "w" , stdout ) ;
  18. }
  19.  
  20. int read( )
  21. {
  22. , ret = ;
  23. ; ch = getchar( ) ; }
  24. + ch - ' , ch = getchar( ) ;
  25. return ret * k ;
  26. }
  27.  
  28. void input( )
  29. {
  30. n = read( ) ;
  31. ; x <= n ; ++x )
  32. node[x].nxt = read( ) , node[node[x].nxt].in++ ;
  33. }
  34.  
  35. void sov( )
  36. {
  37. ; x <= n ; ++x ) if( !node[x].in ) { Q.push( x ) ; node[x].vis = true ; }
  38. while( !Q.empty( ) )
  39. {
  40. int u = Q.front( ) ; Q.pop( ) ;
  41. int v = node[u].nxt ;
  42. ) { Q.push( v ) ; node[v].vis = true ; }
  43. } ans = inf ;
  44. ; x <= n ; ++x )
  45. {
  46. , j = node[x].nxt ;
  47. if( !node[x].vis )
  48. {
  49. while( j != x )
  50. {
  51. cnt++ ;
  52. node[j].vis = true ;
  53. j = node[j].nxt ;
  54. }
  55. ans = min( ans , cnt ) ;
  56. }
  57.  
  58. }
  59. printf( "%d\n" , ans ) ;
  60. }
  61.  
  62. int main( )
  63. {
  64. Init( ) ;
  65. input( ) ;
  66. sov( ) ;
  67. fclose( stdin ) ;
  68. fclose( stdout ) ;
  69. ;
  70. }

当然可以用tajan但我tajan最多只改到90分,就暴栈了QwQ ,不过改成bfs还是可以过,但我没写过 。

第三题就是搜索+剪枝,最开始我以为顺子越长越好,其实并不是QwQ,所以就只有45分 , 然后我就改成枚举了一下顺子的长度,然后就过了。

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <cstdio>
  5. #define fo(a,b,c) for(int a=(b);a<=(c);a++)
  6. << ;
  7. using namespace std ;
  8. ] , c[] , ans ;
  9.  
  10. inline void Init( )
  11. {
  12. freopen( "landlords.in" , "r" , stdin ) ;
  13. freopen( "landlords.out" , "w" , stdout ) ;
  14. }
  15.  
  16. int read( )
  17. {
  18. , ret = ;
  19. ; ch = getchar( ) ; }
  20. + ch - ' , ch = getchar( ) ;
  21. return ret * k ;
  22. }
  23.  
  24. void input( )
  25. {
  26. int a , b ;
  27. fo( i , , n )
  28. {
  29. a = read( ) , b = read( ) ;
  30. ) a = ; else if( a ) a-- ;
  31. s[a] ++ ;
  32. }
  33. }
  34.  
  35. int quer( )
  36. {
  37. memset( c , , sizeof( c ) ) ;
  38. fo( i , , ) c[s[i]] ++ ;
  39. // cout<<c[1]<<" "<<c[2]<<" "<<c[3]<<" "<<c[4]<<endl;
  40. ;
  41. ] && c[]> ) c[]-- , c[] -= , tot ++ ;
  42. ] && c[] > ) c[] -- , c[] -= , tot ++ ;
  43. ] && c[] ) c[]-- , c[] -- , tot ++ ;
  44. ] && c[] ) c[]-- , c[]-- , tot ++ ;
  45. ] && c[] ) c[]-- , c[]-- , tot++ ;
  46. ] + c[] + c[] + c[] ;
  47. }
  48.  
  49. void dfs( int now )
  50. {
  51. if( now >= ans ) return ;
  52. int tmp = quer( ) ;
  53. if( tmp + now < ans ) ans = now + tmp ;
  54. fo( i , , )
  55. {
  56. int j = i ;
  57. ) ++j ;
  58. )
  59. {
  60. fo( j2 , i+ , j- )
  61. {
  62. fo( k , i , j2 ) s[k] -= ;
  63. dfs( now + ) ;
  64. fo( k , i , j2 ) s[k] += ;
  65. }
  66. }
  67.  
  68. }
  69. fo( i , , )
  70. {
  71. int j = i ;
  72. ) ++j ;
  73. )
  74. {
  75. fo( j2 , i+ , j- )
  76. {
  77. fo( k , i , j2 ) s[k] -= ;
  78. dfs( now + ) ;
  79. fo( k , i , j2 ) s[k] += ;
  80. }
  81. }
  82. }
  83.  
  84. fo( i , , )
  85. {
  86. int j = i ;
  87. ) ++j ;
  88. )
  89. fo( j2 , i+ , j- )
  90. {
  91. fo( k , i , j2 ) --s[k] ;
  92. dfs( now + ) ;
  93. fo( k , i , j2 ) ++s[k] ;
  94. }
  95. }
  96. return ;
  97. }
  98.  
  99. int main( )
  100. {
  101. Init( ) ;
  102. t = read( ) , n = read( );
  103. while( t-- )
  104. {
  105. memset( s , , sizeof(s) ) ;
  106. // memset( c , 0 , sizeof(c) ) ;
  107. ans = inf ;
  108. input( ) ;
  109. dfs( ) ;
  110. printf( "%d\n" , ans ) ;
  111. }
  112.  
  113. fclose( stdin ) ;
  114. fclose( stdout ) ;
  115. ;
  116. }

day2

第一题比较简单,就是一个二分嘛 ,虽然昨年没写出来qwq(昨年用堆贪心)

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstdio>
  4. << , maxn = + ;
  5. using namespace std ;
  6. int l , n , m , a[maxn] ;
  7.  
  8. inline void Init( )
  9. {
  10. freopen( "stone.in" , "r" , stdin ) ;
  11. freopen( "stone.out" , "w" , stdout ) ;
  12. }
  13.  
  14. int read( )
  15. {
  16. , ret = ;
  17. ; ch = getchar( ) ; }
  18. + ch - ' , ch = getchar( ) ;
  19. return ret * k ;
  20. }
  21.  
  22. void input( )
  23. {
  24. l = read( ) , n = read( ) , m = read( ) ;
  25. ; x <= n ; ++x ) a[x] = read( ) ;
  26. a[n+] = l , ++n ;
  27. }
  28.  
  29. bool check( int len )
  30. {
  31. , ans = ;
  32. ; x <= n ; ++x )
  33. {
  34. if( a[x] - last < len ) ans++ ;
  35. else last = a[x] ;
  36. if( ans > m ) return false ;
  37. }
  38. return true ;
  39. }
  40.  
  41. void sov( )
  42. {
  43. , rr = l ;
  44. while( ll <= rr )
  45. {
  46. ;
  47. ;
  48. ;
  49. }
  50. printf( ) ;
  51. }
  52.  
  53. int main( )
  54. {
  55. Init( ) ;
  56. input( ) ;
  57. sov( ) ;
  58. fclose( stdin ) ;
  59. fclose( stdout ) ;
  60. ;
  61. }

第二题的话,就是方程式比较难推,QwQ我考场上写的记搜,结果空间复杂度算错 ,本来还是可以骗一点分的 ,

就是个dp,方程式其实还是比较好推,就是要想到一个前缀优化,然后滚一滚就可以过 。

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstdio>
  4. ;
  5. using namespace std ;
  6. int n , m , k ;
  7. ] , b[] ;
  8. ][][][] ;
  9. int main( )
  10. {
  11. scanf( "%d%d%d" , &n , &m , &k ) ;
  12. scanf( , b+ ) ;
  13. f[][][][] = , f[][][][] = ;
  14. ; i <= n ; ++i )
  15. {
  16. ; j <= min( i , m) ; ++j )
  17. {
  18. ; l <= k ; ++l )
  19. {
  20. ,last=(i-)&;
  21. if( a[i] == b[j] )
  22. {
  23. f[j][l][][now] = ( f[j-][l-][][last] + f[j-][l-][][last] ) % mod + f[j-][l][][last] ;
  24. f[j][l][][now] %= mod ;
  25. f[j][l][][now] = ( f[j][l][][last] + f[j][l][][last] ) % mod ;
  26. }
  27. else
  28. {
  29. f[j][l][][now] = (f[j][l][][last]+f[j][l][][last])%mod ;
  30. f[j][l][][now] = ;
  31. }
  32. // cout<<j<<" "<<l<<" "<<now<<" "<<f[j][l][1][now]<<" "<<f[j][l][0][now]<<endl;
  33. }
  34. }
  35. }
  36. printf( ][n&]+f[m][k][][n&])%mod ) ;
  37. ;
  38. }
  1.  

noip 2015 提高组的更多相关文章

  1. NOIP 2015提高组复赛

    神奇的幻方 题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,……,N*N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方法构建一个幻方: 首先将1写在第 ...

  2. NOIP 2015 提高组 Day2

    期望得分:100+10+60=170 实际得分:100+10+35=145 http://www.cogs.pro/cogs/page/page.php?aid=16 T1 跳石头 时间限制:1 s  ...

  3. NOIP 2015 提高组 Day1

    期望得分:100+100+100=300 实际得分:100+100+45=245 T3 相似的代码 复制过去 没有改全,痛失55分 http://www.cogs.pro/cogs/page/page ...

  4. NOIP 2008提高组第三题题解by rLq

    啊啊啊啊啊啊今天已经星期三了吗 那么,来一波题解吧 本题地址http://www.luogu.org/problem/show?pid=1006 传纸条 题目描述 小渊和小轩是好朋友也是同班同学,他们 ...

  5. [NOIp 1998 提高组]Probelm 2 连接多位数【2011百度实习生笔试题】

    /*====================================================================== [NOIp 1998 提高组]Probelm 2 连接 ...

  6. NOIP 2014 提高组 题解

    NOIP 2014 提高组 题解 No 1. 生活大爆炸版石头剪刀布 http://www.luogu.org/problem/show?pid=1328 这是道大水题,我都在想怎么会有人错了,没算法 ...

  7. NOIP 2001 提高组 题解

    NOIP 2001 提高组 题解 No 1. 一元三次方程求解 https://vijos.org/p/1116 看见有人认真推导了求解公式,然后猥琐暴力过的同学们在一边偷笑~~~ 数据小 暴力枚举即 ...

  8. 最优贸易 NOIP 2009 提高组 第三题

    题目描述 C 国有 n 个大城市和 m 条道路,每条道路连接这 n 个城市中的某两个城市.任意两个 城市之间最多只有一条道路直接相连.这 m 条道路中有一部分为单向通行的道路,一部分 为双向通行的道路 ...

  9. NOIP 2006 提高组 t1 能量项链

    题目描述 在Mars星球上,每个Mars人都随身佩带着一串能量项链.在项链上有N颗能量珠.能量珠是一颗有头标记与尾标记的珠子,这些标记对应着某个正整数.并且,对于相邻的两颗珠子,前一颗珠子的尾标记一定 ...

随机推荐

  1. 向OC类中添加默认的协议实现(ProtocolKit)

    以forkingdog的PorotocolKit举例 举例 ProtocolKit Protocol extension for Objective-C Usage Your protocol: @p ...

  2. 黑马程序员-------.net基础知识二

    变量 变量代表着一块内存空间,我们可以通过变量名称想内存存/取数据,有变量就不需要我们记忆复杂的内存地址. 向内存中申请一块内存空间的语法:   数据类型 变量名; 变量类型 变量类型 存储位置 自动 ...

  3. Windows Server以服务方式部署Tomcat

    部署免安装版Tomcat7,步骤如下: 解压Tomcat7到指定目录之后,通过命令行定位到 apache-tomcat-7.0.53\bin 目录下面,然后输入 service.bat install ...

  4. 2D image convolution

    在学习cnn的过程中,对convolution的概念真的很是模糊,本来在学习图像处理的过程中,已对convolution有所了解,它与correlation是有不同的,因为convolution = ...

  5. 定时显示div

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org ...

  6. bzoj 1902: Zju2116 Christopher lucas定理 && 数位DP

    1902: Zju2116 Christopher Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 172  Solved: 67[Submit][Stat ...

  7. Windows XP系统安装SQL Server 2005(开发版)图解

    转自Windows XP系统安装SQL Server 2005(开发版)图解 安装前提:由于有些从网上的下载的项目需要导入SQL Server 2005的数据文件,因此,今天便安装了这个数据库,我的系 ...

  8. 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 ...

  9. menuconfig选项

    打开一个典型的openwrt中package目录下都能发现两个相同点: ? package/<name> /Makefile ? package/<name> /patches ...

  10. javascript时间、随机数

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...