躺在前面
第一次尝试着和同学一起写了一次,然而时间紧迫,最后都没写出来多少题=-=
被C这个破模拟题给搞的晕头转向的
me只写了前四道,都不算很难,代码如果写的比较简洁不会超过40行
A:
题意
小A和小B玩游戏,小A在开局前会选择一个数,小B在开局前也会选择一个数,接下来会给出一堆带有数字的卡片。小A将会获取数字和他所选相同的卡牌,小B也是。
询问是否有一种选择方案使得卡牌被选完并且两人所得卡牌数相等。
题解
真的水,只需要判断一下就可以。。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;
int a[105] , N ;
bool ok = true ;
int main(){
scanf( "%d" , &N ) ;
for( int i = 1 ; i <= N ; i ++ )
scanf( "%d" , &a[i] ) ;
sort( a + 1 , a + N + 1 ) ;
if( N&1 ) ok = false ;
for( int i = 2 ; i <= N/2 ; i ++ )
if( a[i] != a[i-1] ) ok = false ;
if( a[N/2] == a[N/2+1] ) ok = false ;
for( int i = N/2+2 ; i <= N ; i ++ )
if( a[i] != a[i-1] ) ok = false ;
if( ok ){
printf("YES\n%d %d" , a[1] , a[N] ) ;
} else printf( "NO" ) ;
}
B:
题意
给你一个由大小写英文字母组成的字符串,询问在字符串中选出最长的字串满足(字串中全是小写字母且不重复,字串的字母间不能夹有大写字母
题解
其实也很简单= =
O(n)滚一遍就好了
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std ;
char a[250] ;
int N , ans , now ;
bool vis[26] ;
int main(){
scanf( "%d" , &N ) ;
scanf( "%s" , a + 1 ) ;
for( int i = 1 ; i <= N ; i ++ ){
if( a[i] >= 'a' && a[i] <= 'z' ){
if( !vis[ a[i] - 'a' ] ) now ++ ;
vis[ a[i] - 'a' ] = true ;
} else {
ans = max( ans , now ) ;
memset( vis , false , sizeof ( vis ) ) ;
now = 0 ;
}
}
printf( "%d" , ans ) ;
}