结果填空:青蛙爬井
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main ( )
{
int h= 60405 ;
int u= 105 ;
int d= 35 ;
int ans= 0 ;
while ( h)
{
ans++ ;
h-= u;
if ( h<= 0 )
{
cout<< ans<< endl;
break ;
}
h+= d;
}
}
D - 程序设计:找质数
# include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int N= 1000010 ;
int vis[ N] , book[ N] , k;
void prime ( )
{
vis[ 1 ] = 1 ;
k= 0 ;
for ( int i= 2 ; i<= 1000000 ; i++ )
{
if ( vis[ i] == 0 )
{
book[ ++ k] = i;
for ( int j= 2 * i; j<= N; j+= i)
vis[ j] = 1 ;
}
}
}
int main ( )
{
int t, n;
prime ( ) ;
scanf ( "%d" , & t) ;
while ( t-- )
{
scanf ( "%d" , & n) ;
for ( int i= 1 ; i<= k; i++ )
{
if ( vis[ n- book[ i] ] == 0 )
{
printf ( "%d %d\n" , book[ i] , n- book[ i] ) ;
break ;
}
}
}
}
A Math Problem
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll vis[ 30 ] ;
ll qs ( ll a, ll b)
{
ll ans= 1 ;
while ( b)
{
if ( b% 2 == 1 )
ans= ans* a;
a= a* a;
b= b/ 2 ;
}
return ans;
}
int main ( )
{
ll n;
while ( ~ scanf ( "%lld" , & n) )
{
for ( ll i= 1 ; i<= 15 ; i++ )
{
if ( qs ( i, i) > n)
{
cout<< i- 1 << endl;
break ;
}
}
}
}
[蓝桥杯2017初赛]贪吃蛇长度
# include <bits/stdc++.h>
using namespace std;
char a[ 60 ] [ 60 ] ;
int ans;
int main ( )
{
for ( int i= 0 ; i< 20 ; i++ )
gets ( a[ i] ) ;
for ( int i= 0 ; i< 20 ; i++ )
for ( int j= 0 ; j< 51 ; j++ )
{
if ( a[ i] [ j] == '#' )
ans++ ;
if ( a[ i] [ j] == '@' )
ans+= 2 ;
}
ans+= 2 ;
printf ( "%d\n" , ans) ;
}
[蓝桥杯2017初赛]购物单
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char a[ 10 ] , b[ 10 ] ;
double sum, n, c;
int l;
int main ( )
{
for ( int i= 1 ; i<= 50 ; i++ )
{
scanf ( "%s" , a) ;
scanf ( "%lf" , & n) ;
scanf ( "%s" , b) ;
l= strlen ( b) ;
if ( l== 3 )
{
c= b[ 0 ] - '0' ;
c*= 10 ;
}
else if ( l== 4 )
{
if ( b[ 0 ] > '0' && b[ 0 ] <= '9' )
{
c= b[ 0 ] - '0' ;
c*= 10 ;
c+= b[ 1 ] - '0' ;
}
else c= 50 ;
}
sum+= n* ( c/ 100 ) ;
}
printf ( "%lf\n" , sum) ;
}
[蓝桥杯2017初赛]等差素数列
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N= 100000 ;
int vis[ N] , book[ N] ;
void prime ( )
{
vis[ 1 ] = 1 ;
int k= 0 ;
for ( int i= 2 ; i<= N; i++ )
{
if ( ! vis[ i] )
{
book[ ++ k] = i;
for ( int j= 2 * i; j<= N; j+= i)
vis[ j] = 1 ;
}
}
}
int main ( )
{
prime ( ) ;
for ( int i= 1 ; i<= 10000 ; i++ )
{
for ( int j= 1 ; j<= 10000 ; j++ )
{
int k;
for ( k= 1 ; k<= 9 ; k++ )
{
if ( vis[ book[ j] + k* i ] == 0 )
continue ;
else break ;
}
if ( k== 10 )
{
printf ( "%d" , i) ;
return 0 ;
}
}
}
}