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颗能量珠.能量珠是一颗有头标记与尾标记的珠子,这些标记对应着某个正整数.并且,对于相邻的两颗珠子,前一颗珠子的尾标记一定 ...
随机推荐
- php 遍历一个文件夹下的所有文件和子文件夹
<?php function my_scandir($dir) { $files=array(); if(is_dir($dir)) { if($handle=opendir($dir)) { ...
- C++ static全局变量与全局变量的区别/static全局函数与全局函数的区别
全局变量(外部变量)的说明之前再冠以static 就构成了静态的全局变量.全局变量本身就是静态存储方式, 静态全局变量当然也是静态存储方式.这两者在存储方式上并无不同.这两者的区别虽在于非静态全局变量 ...
- 我用C#调用C编译的dll中有这样一个函数,函数大概的功能就是把数据保存到buf缓冲区中:
我用C#调用C编译的dll中有这样一个函数,函数大概的功能就是把数据保存到buf缓冲区中: C/C++ code ? 1 int retrieve(int scanno,void* buf); 在 ...
- Rsync和FastDFS
在做分布式文件存储的时候,常常用到两个工具,Rsync和FastDFS:这两者本质的区别在于前者的实时性相面相对较差,需要手工编写脚本同步,然后在放到定时任务(cron)中:FastDFS自动实现同组 ...
- avalon中require的实现
var plugins = { loader: function(builtin) { window.define = builtin ? innerRequire.define : otherDef ...
- bootstrap table 服务器分页
1.封装MODEL using System;using System.Collections.Generic;using System.Linq;using System.Text;using Sy ...
- 带你了解世界最先进的手势识别技术 -- 微软,凌感,Leap...
转载 今天为大家解释一下现有的几种主要的手势识别技术,为你揭开手势识别技术的神秘面纱. 概述 谈起手势识别技术,由简单粗略的到复杂精细的,大致可以分为三个等级:二维手型识别.二维手势识别.三维手势识别 ...
- 【简译】JavaScript闭包导致的闭合变量问题以及解决方法
本文是翻译此文 预先阅读此文:闭合循环变量时被认为有害的(closing over the loop variable considered harmful) JavaScript也有同样的问题.考虑 ...
- Android 使用LinearLayout.getChildAt(i)获取一个线性布局的view,并实现content中实现方法
1.定义接口content的方法,如ok,cancle; 2.在View的处理类myview中实现content的方法. 3.通过contently.getChildAt(i)的方法获得View v; ...
- logstash date插件
[elk@dr-mysql01 api-access]$ date Wed Nov 30 19:21:35 CST 2016 [elk@dr-mysql01 api-access]$ [elk@dr- ...