A - Not
B - Product Max
C - Ubiquity
容斥
a
n
s
=
1
0
n
−
2
∗
9
n
+
8
n
ans=10^n-2*9^n+8^n
a n s = 1 0 n − 2 ∗ 9 n + 8 n
#include <bits/stdc++.h>
using namespace std;
const int N= 1e9 + 7 ;
int n;
inline int read ( )
{
int Num= 0 , f= 1 ; char ch= getchar ( ) ;
while ( ch< '0' || ch> '9' ) { if ( ch== '-' ) f= - 1 ; ch= getchar ( ) ; }
while ( ch>= '0' && ch<= '9' ) { Num= ( Num<< 1 ) + ( Num<< 3 ) + ch- '0' ; ch= getchar ( ) ; }
return Num* f;
}
inline int abs ( int x) { return x> 0 ? x: - x; }
inline void write ( int x)
{
char F[ 200 ] ;
int tep= abs ( x) , cn= 0 ;
if ( x< 0 ) putchar ( '-' ) ;
while ( tep)
{
F[ cn++ ] = ( char ) tep% 10 ;
tep/ = 10 ;
}
while ( cn) putchar ( F[ -- cn] ) ;
}
long long ksm ( int x, int y)
{
long long ans1= x;
long long ans2= 1 ;
while ( y)
{
if ( y& 1 ) ans2= ans1* ans2% N;
ans1= ans1* ans1% N;
y>>= 1 ;
}
return ans2;
}
int main ( )
{
cin>> n;
if ( n== 1 ) {
puts ( "0" ) ; return 0 ;
}
if ( n== 2 )
{
puts ( "2" ) ; return 0 ;
}
long long ans= ksm ( 10 , n) % N;
ans= ( ans- 2 * ksm ( 9 , n) % N) % N;
ans= ( ans+ ksm ( 8 , n) % N) % N;
printf ( "%lld" , ( ans+ N) % N) ;
return 0 ;
}
D - Redistribution
背包
d
p
[
i
]
[
j
]
表
示
选
i
个
元
素
,
组
成
j
的
方
案
数
dp[i][j]表示选i个元素,组成j的方案数
d p [ i ] [ j ] 表 示 选 i 个 元 素 , 组 成 j 的 方 案 数 暴力枚举
O
(
n
3
)
O(n^3)
O ( n 3 ) 能过 尽管n是2000
#include <bits/stdc++.h>
using namespace std;
int n;
const int N= 1e9 + 7 ;
long long dp[ 2010 ] [ 2010 ] ;
int main ( )
{
cin>> n;
for ( int i= 3 ; i<= n; i++ ) dp[ 1 ] [ i] = 1 ;
for ( int i= 2 ; i<= ( n/ 3 + 1 ) ; i++ )
{
for ( int j= 3 * i; j<= n; j++ )
for ( int k= 3 ; k<= j- ( 3 * ( i- 1 ) ) ; k++ )
dp[ i] [ j] = dp[ i] [ j] + dp[ i- 1 ] [ j- k] % N;
}
long long ans= 0 ;
for ( int i= 1 ; i<= n; i++ )
ans= ans+ dp[ i] [ n] % N;
printf ( "%lld\n" , ans% N) ;
return 0 ;
}
E - Dist Max
在第一象限,所以都大于0 那么直接以x+y为关键字 排序 这样只是最靠近原点的一种情况,还有一种情况是另外一个对角(就像正方形一样) 所以
a
b
s
(
x
−
1
e
9
)
abs(x-1e9)
a b s ( x − 1 e 9 ) 再做一遍就行了
#include <bits/stdc++.h>
using namespace std;
const int N= 2e5 + 10 ;
struct node{
int x, y;
long long t;
} f[ N] ;
int n;
inline bool mycmp ( node x, node y) { return x. t> y. t; }
inline int read ( )
{
int Num= 0 , f= 1 ; char ch= getchar ( ) ;
while ( ch< '0' || ch> '9' ) { if ( ch== '-' ) f= - 1 ; ch= getchar ( ) ; }
while ( ch>= '0' && ch<= '9' ) { Num= ( Num<< 1 ) + ( Num<< 3 ) + ch- '0' ; ch= getchar ( ) ; }
return Num* f;
}
int main ( )
{
n= read ( ) ;
for ( int i= 1 ; i<= n; i++ )
{
f[ i] . x= read ( ) , f[ i] . y= read ( ) ;
f[ i] . t= f[ i] . x+ f[ i] . y;
}
sort ( f+ 1 , f+ 1 + n, mycmp) ;
long long ans= ( long long ) abs ( f[ 1 ] . x- f[ n] . x) + abs ( f[ 1 ] . y- f[ n] . y) ;
for ( int i= 1 ; i<= n; i++ )
{
f[ i] . x= abs ( f[ i] . x- 1000000000 ) ; f[ i] . t= f[ i] . x+ f[ i] . y;
}
sort ( f+ 1 , f+ 1 + n, mycmp) ;
ans= max ( ( long long ) abs ( f[ 1 ] . x- f[ n] . x) + abs ( f[ 1 ] . y- f[ n] . y) , ans) ;
printf ( "%lld" , ans) ;
return 0 ;
}
F - Contrast
直接把b反过来,随便翻一下,如果都翻不了,就无解(当然也有更严谨的做法,比如记录a区间的开始到结尾,从其他位置选)
#include <bits/stdc++.h>
using namespace std;
const int N= 2e5 + 10 ;
int a[ N] , b[ N] ;
int n;
int t[ N] , t1[ N] ;
inline int read ( )
{
int Num= 0 , f= 1 ; char ch= getchar ( ) ;
while ( ch< '0' || ch> '9' ) { if ( ch== '-' ) f= - 1 ; ch= getchar ( ) ; }
while ( ch>= '0' && ch<= '9' ) { Num= ( Num<< 1 ) + ( Num<< 3 ) + ch- '0' ; ch= getchar ( ) ; }
return Num* f;
}
int tot= 200 , flag= 0 ;
int main ( )
{
n= read ( ) ; int Bit= 1 , _bit= n;
for ( int i= 1 ; i<= n; i++ ) a[ i] = read ( ) ;
for ( int i= 1 ; i<= n; i++ ) b[ n- i+ 1 ] = read ( ) ;
for ( int i= 1 ; i<= n; i++ )
if ( a[ i] == b[ i] )
{
if ( b[ Bit] != a[ i] && b[ i] != a[ Bit] )
swap ( b[ Bit++ ] , b[ i] ) ;
else if ( b[ _bit] != a[ i] && a[ _bit] != b[ i] )
swap ( b[ _bit-- ] , b[ i] ) ;
else
{
puts ( "No" ) ;
return 0 ;
}
}
puts ( "Yes" ) ;
for ( int i= 1 ; i<= n; i++ )
printf ( "%d " , b[ i] ) ;
return 0 ;
return 0 ;
}