# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N= 1e5 + 5 ;
ll mod= 1e9 + 7 ;
ll sum[ N] ;
int a[ N] ;
vector< int > vec;
int main ( )
{
int n;
scanf ( "%d" , & n) ;
for ( int i= 0 ; i< n; i++ ) {
int x;
scanf ( "%d" , & x) ;
a[ x] = 1 ;
}
for ( int i= 1 ; i<= n; i++ ) {
if ( a[ i] == 0 ) {
vec. push_back ( i) ;
}
}
printf ( "%d\n" , vec. size ( ) ) ;
for ( int i= 0 ; i< vec. size ( ) ; i++ ) {
printf ( "%d\n" , vec[ i] ) ;
}
return 0 ;
}
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N= 1e5 + 5 ;
ll mod= 1e9 + 7 ;
ll sum[ N] ;
int a[ N] ;
vector< int > vec;
int main ( )
{
int n;
string s= "I want to take the MS's rocket to live in the MS's ice castle." ;
for ( int i= 0 ; i< s. size ( ) ; i++ ) {
int c= s[ i] ;
if ( i) cout<< " " ;
cout<< c;
}
return 0 ;
}
不想写,可以建个二维数组把0 到9 存一下
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N= 1e5 + 5 ;
ll mod= 1e9 + 7 ;
int a[ N] ;
vector< int > vec;
int main ( )
{
int n;
scanf ( "%d" , & n) ;
while ( n-- ) {
ll x;
scanf ( "%lld" , & x) ;
ll b= 1 ;
ll k= 0 ;
ll t= 1 ;
ll sum= 0 ;
while ( b<= x) {
sum= ( sum% mod+ ( b- t) * k) % mod;
t= b;
b*= 2 ;
k++ ;
}
if ( x> ( b/ 2 ) ) sum= ( sum% mod+ ( x- ( b/ 2 ) ) * k) % mod;
cout<< sum<< endl;
}
return 0 ;
}
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N= 1e5 + 5 ;
ll mod= 1e9 + 7 ;
int a[ N] ;
vector< int > vec;
int main ( )
{
int n;
while ( ~ scanf ( "%d" , & n) ) {
n++ ;
int c= n% 3 ;
if ( c== 0 )
cout<< "PangPang will get the gold nugget!" << endl;
else cout<< "Brother Chao will get the gold nugget!" << endl;
}
return 0 ;
}
前缀和+ 双指针
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N= 1e4 + 5 ;
ll mod= 1e9 + 7 ;
ll sum[ N] ;
int a[ N] ;
int main ( )
{
int n; int x;
while ( ~ scanf ( "%d" , & x) ) {
for ( int i= 1 ; i<= x; i++ ) {
scanf ( "%d" , & a[ i] ) ;
sum[ i] = sum[ i- 1 ] + a[ i] ;
}
int l= 1 , r= x;
double maxn= ( sum[ r] - sum[ l- 1 ] ) * 1.0 / ( r- l+ 1 ) ;
while ( l< r) {
double c;
if ( a[ l] > a[ r] ) {
r-- ;
c= ( sum[ r] - sum[ l- 1 ] ) * 1.0 / ( r- l+ 1 ) ;
maxn= max ( maxn, c) ;
} else if ( a[ l] < a[ r] ) {
l++ ;
c= ( sum[ r] - sum[ l- 1 ] ) * 1.0 / ( r- l+ 1 ) ;
maxn= max ( maxn, c) ;
}
else {
r-- ;
l++ ;
c= ( sum[ r] - sum[ l- 1 ] ) * 1.0 / ( r- l+ 1 ) ;
maxn= max ( maxn, c) ;
}
}
ll g= maxn;
cout<< g<< endl;
}
return 0 ;
}
KMP算法
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N= 5e5 + 5 ;
ll mod= 1e9 + 7 ;
int prefix[ N] ;
int firstplace;
void prefix_table ( string s) {
prefix[ 0 ] = - 1 ;
int i = 0 , len = - 1 ;
while ( i < s. size ( ) ) {
if ( len == - 1 || s[ i] == s[ len] ) {
i++ , len++ ;
prefix[ i] = len;
}
else len = prefix[ len] ;
}
}
int ans_kmp ( string s, string t) {
int i = 0 , len = 0 ;
bool flag = false ;
int ans = 0 ;
prefix_table ( s) ;
while ( i < t. size ( ) ) {
if ( len == - 1 || s[ len] == t[ i] ) i++ , len++ ;
else len = prefix[ len] ;
if ( len == s. size ( ) ) {
if ( flag == false ) firstplace = i - s. size ( ) + 1 ;
ans++ ;
len = prefix[ len] ;
flag = true ;
}
}
if ( flag) return ans;
else return - 1 ;
}
int main ( )
{
int n;
ios:: sync_with_stdio ( false ) ;
cin>> n;
string k;
while ( n-- ) {
string a, b;
cin>> a>> b;
int c= ans_kmp ( b, a) ;
k = string ( b. rbegin ( ) , b. rend ( ) ) ;
int d= ans_kmp ( k, a) ;
if ( c== - 1 && d== - 1 ) {
cout<< "xyh nb" << endl;
}
else
cout<< "lyh nb" << endl;
}
return 0 ;
}