1108.电梯
# include <iostream>
# include <algorithm>
# include <cmath>
using namespace std;
const int N= 110 ;
int nums[ N] ;
int main ( ) {
int n;
cin>> n;
int res= 0 ;
for ( int i= 1 ; i<= n; i++ ) {
cin>> nums[ i] ;
int t= nums[ i] - nums[ i- 1 ] ;
if ( t> 0 ) res+= t* 6 ;
else res+= abs ( t* 4 ) ;
res+= 5 ;
}
cout<< res;
}
1011.世界杯投注
# include <iostream>
# include <algorithm>
using namespace std;
double list[ 3 ] [ 3 ] ;
char num[ ] = "WTL" ;
int main ( ) {
double sum= 1 ;
for ( int i= 0 ; i< 3 ; i++ )
{
double res= 0 ;
int t= 0 ;
for ( int j= 0 ; j< 3 ; j++ ) {
cin>> list[ i] [ j] ;
if ( list[ i] [ j] > res) {
res= list[ i] [ j] ;
t= j;
}
}
cout<< num[ t] << " " ;
sum*= res;
}
printf ( "%.2lf" , ( sum* 0.65 - 1 ) * 2 ) ;
}
1014.排队等候 **
由于队伍的性质,我们用queue维护每一个窗口,由于本题不存在入队时间先后顺序,所有人都在同一时间排队
,每个队列仅需存储每个人办理业务完成的时间 那么再8:00开门时,每个人的入队只分为两种情况 1.黄线内人数不够,即人数<=n*m
此时只需要找寻人数最少窗口入队即可 2.黄线内人数已满,即人数>n*m
此时该顾客只需要选择最早完成业务的窗口即可可根据队头元素存储的完成时间进行选择
# include <iostream>
# include <cstring>
# include <queue>
# include <unordered_map>
using namespace std;
int n, m, k, Q;
queue< int > q[ 20 ] ;
unordered_map< int , int > has;
int finish[ 20 ] ;
int main ( ) {
cin>> n>> m>> k>> Q;
for ( int i= 1 ; i<= k; i++ ) {
int cur_time, t= 0 ;
cin>> cur_time;
for ( int j= 0 ; j< n; j++ ) {
if ( i<= n* m) {
if ( q[ j] . size ( ) < q[ t] . size ( ) ) t= j;
}
else {
if ( q[ j] . front ( ) < q[ t] . front ( ) ) t= j;
}
}
if ( i> n* m) q[ t] . pop ( ) ;
finish[ t] += cur_time;
q[ t] . push ( finish[ t] ) ;
if ( finish[ t] - cur_time< 540 ) has[ i] = finish[ t] ;
}
while ( Q-- ) {
int x;
cin>> x;
if ( ! has. count ( x) ) cout<< "Sorry" << endl;
else printf ( "%02d:%02d\n" , has[ x] / 60 + 8 , has[ x] % 60 ) ;
}
}
1031.U形helloworld
# include <iostream>
# include <cstring>
using namespace std;
const int N= 100 ;
char c[ N] [ N] ;
int main ( ) {
string str;
cin>> str;
int n= str. size ( ) ;
int n1= ( n+ 2 ) / 3 ;
int n2= n+ 2 - 2 * n1;
int k= 0 ;
for ( int i= 0 ; i< n1; i++ ) c[ i] [ 0 ] = str[ k++ ] ;
for ( int i= 1 ; i< n2; i++ ) c[ n1- 1 ] [ i] = str[ k++ ] ;
for ( int i= n1- 2 ; i>= 0 ; i-- ) c[ i] [ n2- 1 ] = str[ k++ ] ;
for ( int i= 0 ; i< n1; i++ ) {
for ( int j= 0 ; j< n2; j++ ) {
if ( c[ i] [ j] ) cout<< c[ i] [ j] ;
else cout<< " " ;
}
cout<< endl;
}
}
1041.独一无二
# include <iostream>
# include <unordered_map>
using namespace std;
const int N= 1e5 + 10 ;
int nums[ N] ;
int main ( ) {
int n;
cin>> n;
unordered_map< int , int > has;
for ( int i= 0 ; i< n; i++ ) {
cin>> nums[ i] ;
has[ nums[ i] ] ++ ;
}
bool flag = false ;
for ( int i= 0 ; i< n; i++ ) {
if ( has[ nums[ i] ] == 1 ) {
flag= true ;
cout<< nums[ i] ;
break ;
}
}
if ( ! flag) cout<< "None" ;
}
1042.洗牌机
# include <iostream>
# include <algorithm>
# include <cstring>
using namespace std;
int pos[ 54 ] ;
string num[ 54 ] = { "S1" , "S2" , "S3" , "S4" , "S5" , "S6" , "S7" , "S8" , "S9" , "S10" , "S11" , "S12" , "S13" ,
"H1" , "H2" , "H3" , "H4" , "H5" , "H6" , "H7" , "H8" , "H9" , "H10" , "H11" , "H12" , "H13" ,
"C1" , "C2" , "C3" , "C4" , "C5" , "C6" , "C7" , "C8" , "C9" , "C10" , "C11" , "C12" , "C13" ,
"D1" , "D2" , "D3" , "D4" , "D5" , "D6" , "D7" , "D8" , "D9" , "D10" , "D11" , "D12" , "D13" ,
"J1" , "J2" } ;
int main ( ) {
int k;
cin>> k;
for ( int i= 0 ; i< 54 ; i++ ) cin>> pos[ i] ;
string res[ 54 ] ;
while ( k-- ) {
for ( int i= 0 ; i< 54 ; i++ ) {
res[ pos[ i] - 1 ] = num[ i] ;
}
for ( int i= 0 ; i< 54 ; i++ ) num[ i] = res[ i] ;
}
cout<< res[ 0 ] ;
for ( int i= 1 ; i< 54 ; i++ ) cout<< " " << res[ i] ;
}
1047.课程学生列表
# include <iostream>
# include <cstring>
# include <algorithm>
# include <unordered_map>
# include <vector>
using namespace std;
const int N= 2510 ;
int n, k;
vector< string> stu[ N] ;
int main ( ) {
cin>> n>> k;
for ( int i= 0 ; i< n; i++ ) {
string s;
s. resize ( 4 ) ;
scanf ( "%s" , & s[ 0 ] ) ;
int num;
scanf ( "%d" , & num) ;
while ( num-- ) {
int clas;
scanf ( "%d" , & clas) ;
stu[ clas] . push_back ( s) ;
}
}
for ( int i= 1 ; i<= k; i++ ) {
printf ( "%d %d\n" , i, stu[ i] . size ( ) ) ;
sort ( stu[ i] . begin ( ) , stu[ i] . end ( ) ) ;
for ( auto item : stu[ i] ) printf ( "%s\n" , item. c_str ( ) ) ;
}
}
1054.主导颜色
# include <iostream>
# include <unordered_map>
using namespace std;
int main ( )
{
int n, m;
scanf ( "%d%d" , & n, & m) ;
unordered_map< int , int > cnt;
for ( int i = 0 ; i < n * m; i ++ )
{
int x;
scanf ( "%d" , & x) ;
if ( ++ cnt[ x] > n * m / 2 )
{
printf ( "%d\n" , x) ;
break ;
}
}
return 0 ;
}
1056.老鼠和大米
# include <iostream>
# include <unordered_map>
# include <vector>
# include <cmath>
using namespace std;
const int N= 1010 ;
int w[ N] ;
vector< int > res[ N] ;
int Rank[ N] ;
int main ( ) {
int n, m;
cin>> n>> m;
for ( int i= 0 ; i< n; i++ ) cin>> w[ i] ;
vector< int > cur ( n) ;
for ( int i= 0 ; i< n; i++ ) cin>> cur[ i] ;
for ( int i= 0 ; i< ceil ( ( double ) n/ m) ; i++ ) {
vector< int > next;
for ( int j= 0 ; j< cur. size ( ) ; ) {
int item= j;
int k;
for ( k= 1 ; k< m && ( j+ k) < cur. size ( ) ; k++ ) {
if ( w[ cur[ j+ k] ] > w[ cur[ item] ] ) res[ i] . push_back ( cur[ item] ) , item= j+ k;
else res[ i] . push_back ( cur[ j+ k] ) ;
}
next. push_back ( cur[ item] ) ;
j+= k;
}
cur= next;
}
if ( cur. size ( ) == 1 ) res[ ( int ) ceil ( ( double ) n/ m) ] . push_back ( cur[ 0 ] ) ;
int cnt= 1 ;
for ( int i= ceil ( ( double ) n/ m) ; i>= 0 ; i-- ) {
for ( auto item: res[ i] ) {
Rank[ item] = cnt;
}
cnt+= res[ i] . size ( ) ;
}
cout<< Rank[ 0 ] ;
for ( int i= 1 ; i< n; i++ ) cout<< " " << Rank[ i] ;
}
1062.才华和德行
# include <iostream>
# include <cstring>
# include <vector>
# include <algorithm>
using namespace std;
const int N= 1e5 + 10 ;
struct People {
int id, vir, tal, sum;
bool operator < ( const People & t) const {
if ( t. sum!= sum) return sum> t. sum;
else if ( t. vir != vir) return vir> t. vir;
else return id< t. id;
}
} people[ N] ;
vector< People> Rank[ 4 ] ;
int main ( ) {
int n, L, H;
cin>> n>> L>> H;
for ( int i= 0 ; i< n; i++ ) {
int id, vir, tal;
scanf ( "%d %d %d" , & id, & vir, & tal) ;
if ( tal< L || vir< L) continue ;
people[ i] = { id, vir, tal, vir+ tal} ;
if ( vir>= H && tal>= H) Rank[ 0 ] . push_back ( people[ i] ) ;
else if ( vir>= H && tal< H) Rank[ 1 ] . push_back ( people[ i] ) ;
else if ( vir< H && tal< H && vir>= tal) Rank[ 2 ] . push_back ( people[ i] ) ;
else Rank[ 3 ] . push_back ( people[ i] ) ;
}
int res= 0 ;
for ( int i= 0 ; i< 4 ; i++ ) res+= Rank[ i] . size ( ) ;
cout<< res<< endl;
for ( int i= 0 ; i< 4 ; i++ ) {
auto t= Rank[ i] ;
sort ( t. begin ( ) , t. end ( ) ) ;
for ( auto it: t) cout<< it. id<< " " << it. vir<< " " << it. tal<< endl;
}
}
1065.A+B和C
# include <iostream>
using namespace std;
int main ( ) {
int n;
cin>> n;
for ( int i= 1 ; i<= n; i++ ) {
cout<< "Case #" << i<< ": " ;
long double a, b, c;
cin>> a>> b>> c;
if ( a+ b> c) cout<< "true" ;
else cout<< "false" ;
cout << endl;
}
}
1069.数字黑洞
# include <iostream>
# include <vector>
# include <algorithm>
using namespace std;
vector< int > num1, num2;
bool check ( int n) {
vector< int > num;
while ( n) num. push_back ( n% 10 ) , n/= 10 ;
while ( num. size ( ) < 4 ) num. push_back ( 0 ) ;
for ( int i= 1 ; i< 4 ; i++ ) {
if ( num[ i] != num[ i- 1 ] ) return false ;
}
return true ;
}
int get ( vector< int > num) {
int res= 0 ;
for ( int i= 0 ; i< num. size ( ) ; i++ ) {
res= res* 10 + num[ i] ;
}
return res;
}
int main ( ) {
int n;
cin>> n;
if ( check ( n) )
{
printf ( "%04d - %04d = 0000" , n, n) ;
return 0 ;
}
int res= n;
if ( res== 6174 ) printf ( "7641 - 1467 = 6174" ) ;
while ( res!= 6174 ) {
vector< int > cur;
while ( res) cur. push_back ( res% 10 ) , res/= 10 ;
while ( cur. size ( ) < 4 ) cur. push_back ( 0 ) ;
sort ( cur. begin ( ) , cur. end ( ) ) ;
int a = get ( cur) ;
reverse ( cur. begin ( ) , cur. end ( ) ) ;
int b= get ( cur) ;
if ( a< b) swap ( a, b) ;
res= a- b;
printf ( "%04d - %04d = %04d\n" , a, b, res) ;
}
}
1080.研究生入学 **
本题关键在于处理并列排名学生的录取情况,如果按名次遍历,难以处理题目所给的分数相同无视名额条件录取的特殊情况 思路是先对学生成绩进行排序,每一次处理一个成绩相同的学生区间,对于这个区间,由于这些学生成绩相同,具有相等权利的选择权
,枚举每个学生的志愿,如果学校名额未满,就先作标记,当该区间处理完后,统一将学生加入对应的学校即可。
# include <iostream>
# include <vector>
# include <algorithm>
# include <cstring>
using namespace std;
const int N= 40010 , M= 110 , K= 5 ;
int n, m, k;
int cnt[ M] ;
int wish[ N] ;
vector< int > unt[ M] ;
struct Person
{
int id, ge, gi;
int wish[ K] ;
int total ( ) const
{
return ge + gi;
}
bool operator < ( const Person & t) const
{
if ( total ( ) != t. total ( ) ) return total ( ) > t. total ( ) ;
return ge > t. ge;
}
bool operator == ( const Person & t) const
{
return ge == t. ge && gi == t. gi;
}
} p[ N] ;
int main ( ) {
scanf ( "%d%d%d" , & n, & m, & k) ;
for ( int i= 0 ; i< m; i++ ) scanf ( "%d" , & cnt[ i] ) ;
for ( int i= 0 ; i< n; i++ ) {
scanf ( "%d%d" , & p[ i] . ge, & p[ i] . gi) ;
for ( int j= 0 ; j< k; j++ ) scanf ( "%d" , & p[ i] . wish[ j] ) ;
p[ i] . id= i;
}
sort ( p, p+ n) ;
memset ( wish, - 1 , sizeof wish) ;
for ( int i= 0 ; i< n; ) {
int j= i+ 1 ;
while ( j< n && p[ i] == p[ j] ) j++ ;
for ( int t= i; t< j; t++ ) {
for ( int u= 0 ; u< k; u++ ) {
int w= p[ t] . wish[ u] ;
if ( cnt[ w] > unt[ w] . size ( ) ) {
wish[ t] = w;
break ;
}
}
}
for ( int t= i; t< j; t++ ) {
if ( wish[ t] != - 1 ) unt[ wish[ t] ] . push_back ( p[ t] . id) ;
}
i= j;
}
for ( int i= 0 ; i< m; i++ ) {
if ( unt[ i] . size ( ) ) {
sort ( unt[ i] . begin ( ) , unt[ i] . end ( ) ) ;
printf ( "%d" , unt[ i] [ 0 ] ) ;
for ( int j= 1 ; j< unt[ i] . size ( ) ; j++ ) printf ( " %d" , unt[ i] [ j] ) ;
}
printf ( "\n" ) ;
}
return 0 ;
}
1083.成绩单
# include <iostream>
# include <vector>
# include <algorithm>
# include <cstring>
using namespace std;
const int N= 110 ;
struct Person {
string name, id;
int score;
bool operator < ( const Person & t) const {
return score> t. score;
}
} p[ N] ;
int n;
int main ( ) {
int g1, g2;
cin>> n;
for ( int i= 0 ; i< n; i++ ) {
cin>> p[ i] . name>> p[ i] . id>> p[ i] . score;
}
sort ( p, p+ n) ;
cin>> g1>> g2;
bool flag= false ;
for ( int i= 0 ; i< n; i++ ) {
if ( p[ i] . score>= g1&& p[ i] . score<= g2) {
flag= true ;
cout<< p[ i] . name<< " " << p[ i] . id<< endl;
}
}
if ( ! flag) cout<< "NONE" << endl;
}
1092.买还是不买
# include <iostream>
# include <cstring>
# include <unordered_map>
using namespace std;
unordered_map< char , int > has;
int main ( ) {
string s1, s2;
cin>> s1>> s2;
for ( int i= 0 ; i< s1. size ( ) ; i++ ) has[ s1[ i] ] ++ ;
for ( int i= 0 ; i< s2. size ( ) ; i++ ) has[ s2[ i] ] -- ;
int cnt1= 0 , cnt2= 0 ;
for ( auto it : has) {
if ( it. second> 0 ) cnt1+= it. second;
else cnt2-= it. second;
}
if ( cnt2) cout<< "No" << " " << cnt2;
else cout<< "Yes" << " " << cnt1;
}
1095.校园内的汽车 **
# include <iostream>
# include <vector>
# include <unordered_map>
# include <algorithm>
# include <cstring>
using namespace std;
const int N= 10010 ;
struct Event {
int tm, status;
bool operator < ( const Event & t) const {
return tm< t. tm;
}
} ;
int get ( vector< Event> evt) {
int res= 0 ;
for ( int i= 0 ; i< evt. size ( ) ; i+= 2 ) {
res+= evt[ i+ 1 ] . tm- evt[ i] . tm;
}
return res;
}
int n, m;
int main ( ) {
scanf ( "%d %d" , & n, & m) ;
unordered_map< string, vector< Event>> Cars;
char id[ 10 ] , st[ 5 ] ;
for ( int i= 0 ; i< n; i++ ) {
int hh, mm, ss;
scanf ( "%s %d:%d:%d %s" , id, & hh, & mm, & ss, st) ;
int tm= hh* 3600 + mm* 60 + ss;
int status= 0 ;
if ( st[ 0 ] == 'o' ) status= 1 ;
Cars[ id] . push_back ( { tm, status} ) ;
}
vector< Event> events;
for ( auto & item : Cars) {
auto & evt = item. second;
sort ( evt. begin ( ) , evt. end ( ) ) ;
int k= 0 ;
for ( int i= 0 ; i< evt. size ( ) ; ) {
if ( evt[ i] . status== 0 ) {
if ( i+ 1 < evt. size ( ) && evt[ i+ 1 ] . status== 1 ) {
evt[ k++ ] = evt[ i] ;
evt[ k++ ] = evt[ i+ 1 ] ;
i+= 2 ;
}
else i++ ;
}
else i++ ;
}
evt. erase ( evt. begin ( ) + k, evt. end ( ) ) ;
for ( int i= 0 ; i< k; i++ ) events. push_back ( evt[ i] ) ;
}
sort ( events. begin ( ) , events. end ( ) ) ;
int k= 0 , cnt= 0 ;
while ( m-- ) {
int hh, mm, ss;
scanf ( "%d:%d:%d" , & hh, & mm, & ss) ;
int query= hh* 3600 + mm* 60 + ss;
while ( k< events. size ( ) && events[ k] . tm<= query) {
if ( events[ k] . status== 0 ) cnt++ ;
else cnt-- ;
k++ ;
}
printf ( "%d\n" , cnt) ;
}
int maxt= 0 ;
for ( auto & item : Cars)
maxt= max ( maxt, get ( item. second) ) ;
vector< string> res;
for ( auto item: Cars) {
if ( get ( item. second) == maxt) res. push_back ( item. first) ;
}
sort ( res. begin ( ) , res. end ( ) ) ;
for ( auto item: res) printf ( "%s " , item. c_str ( ) ) ;
printf ( "%02d:%02d:%02d\n" , maxt / 3600 , maxt % 3600 / 60 , maxt % 60 ) ;
}
1105.螺旋矩阵
# include <iostream>
# include <algorithm>
# include <vector>
using namespace std;
const int N= 1e4 + 10 ;
int n;
int num[ N] ;
int main ( ) {
cin>> n;
for ( int i= 0 ; i< n; i++ ) cin>> num[ i] ;
int r, c;
for ( int i= 1 ; i<= n/ i; i++ ) {
if ( n% i== 0 ) {
r= n/ i;
c= i;
}
}
sort ( num, num+ n, greater< int > ( ) ) ;
vector< vector< int >> res ( r, vector< int > ( c) ) ;
int dx[ 4 ] = { - 1 , 0 , 1 , 0 } , dy[ 4 ] = { 0 , 1 , 0 , - 1 } ;
for ( int i= 0 , x= 0 , y= 0 , d= 1 ; i< n; i++ ) {
res[ x] [ y] = num[ i] ;
int a= x+ dx[ d] , b= y+ dy[ d] ;
if ( a>= r|| a< 0 || b>= c|| b< 0 || res[ a] [ b] ) {
d= ( d+ 1 ) % 4 ;
a= x+ dx[ d] , b= y+ dy[ d] ;
}
x= a, y= b;
}
for ( int i= 0 ; i< r; i++ ) {
cout<< res[ i] [ 0 ] ;
for ( int j= 1 ; j< c; j++ ) {
cout<< " " << res[ i] [ j] ;
}
cout<< endl;
}
}
1109.合影
# include <iostream>
# include <algorithm>
# include <cstring>
# include <vector>
using namespace std;
const int N= 1e4 + 10 ;
int n, k;
struct person {
string name;
int h;
bool operator < ( const person & t) const {
if ( t. h!= h) return h> t. h;
else return name< t. name;
}
} p[ N] ;
string line[ N] ;
int main ( ) {
cin>> n>> k;
for ( int i= 0 ; i< n; i++ ) cin>> p[ i] . name>> p[ i] . h;
sort ( p, p+ n) ;
int cnt= 0 ;
for ( int i= 0 ; i< k; i++ ) {
int len= n/ k;
if ( ! i) len+= n% k;
for ( int r= len/ 2 + 1 , l= r- 1 ; l> 0 || r<= len; l-- , r++ ) {
if ( r<= len) line[ r] = p[ cnt++ ] . name;
if ( l> 0 ) line[ l] = p[ cnt++ ] . name;
}
cout<< line[ 1 ] ;
for ( int i= 2 ; i<= len; i++ ) cout<< " " << line[ i] ;
cout<< endl;
}
}
1121.单身狗
# include <iostream>
# include <cstring>
# include <unordered_map>
# include <vector>
# include <algorithm>
using namespace std;
const int N= 50010 , M= 2 * N;
bool st[ M] ;
int line[ N] ;
unordered_map< int , int > has;
int n, m;
int main ( ) {
cin>> n;
for ( int i= 0 ; i< n; i++ ) {
int a, b;
cin>> a>> b;
has[ a] = b, has[ b] = a;
}
cin>> m;
for ( int i= 0 ; i< m; i++ ) cin>> line[ i] , st[ line[ i] ] = true ;
sort ( line, line+ m) ;
int res[ N] , cnt= 0 ;
for ( int i= 0 ; i< m; i++ ) {
if ( ! has. count ( line[ i] ) || ! st[ has[ line[ i] ] ] ) {
res[ cnt++ ] = line[ i] ;
}
}
cout<< cnt<< endl;
if ( cnt) {
printf ( "%.05d" , res[ 0 ] ) ;
for ( int i= 1 ; i< cnt; i++ ) printf ( " %.05d" , res[ i] ) ;
}
}
1128.N皇后问题
# include <iostream>
# include <algorithm>
# include <cstring>
using namespace std;
const int N= 1010 ;
bool row[ N] , dg[ 2 * N] , udg[ 2 * N] ;
int main ( ) {
int k;
cin>> k;
while ( k-- ) {
int n;
cin>> n;
memset ( row, 0 , sizeof row) ;
memset ( dg, 0 , sizeof dg) ;
memset ( udg, 0 , sizeof udg) ;
bool success= true ;
for ( int y= 1 ; y<= n; y++ ) {
int x;
cin>> x;
if ( row[ x] || dg[ x+ y] || udg[ y- x+ n] ) success= false ;
row[ x] = dg[ x+ y] = udg[ y- x+ n] = true ;
}
if ( success) cout<< "YES" << endl;
else cout<< "NO" << endl;
}
}
1129.推荐系统
# include <iostream>
# include <algorithm>
# include <cstring>
using namespace std;
const int N= 50010 ;
int cnt[ N] ;
int line[ 11 ] ;
int main ( ) {
int n, k;
scanf ( "%d%d" , & n, & k) ;
for ( int i= 0 , m= 0 ; i< n; i++ ) {
int x;
scanf ( "%d" , & x) ;
if ( i) {
printf ( "%d:" , x) ;
for ( int j= 0 ; j< m; j++ ) printf ( " %d" , line[ j] ) ;
puts ( "" ) ;
}
cnt[ x] ++ ;
bool is_exist= false ;
for ( int j= 0 ; j< m; j++ ) {
if ( line[ j] == x) is_exist= true ;
}
if ( ! is_exist) line[ m++ ] = x;
sort ( line, line+ m, [ ] ( int x, int y) {
if ( cnt[ x] != cnt[ y] ) return cnt[ x] > cnt[ y] ;
else return x< y;
} ) ;
m= min ( m, k) ;
}
}
1132.切整数
# include <iostream>
# include <cstring>
using namespace std;
int main ( )
{
int T;
cin >> T;
while ( T -- )
{
string number;
cin >> number;
int len = number. size ( ) / 2 ;
int left = stoi ( number. substr ( 0 , len) ) ;
int right = stoi ( number. substr ( len) ) ;
int n = stoi ( number) ;
if ( left * right && n % ( left * right) == 0 ) puts ( "Yes" ) ;
else puts ( "No" ) ;
}
return 0 ;
}
1140.外观数列
# include <iostream>
# include <algorithm>
# include <cstring>
using namespace std;
int main ( ) {
int D, n;
cin>> D>> n;
string ans= to_string ( D) ;
for ( int i= 0 ; i< n- 1 ; i++ ) {
string next;
for ( int j= 0 ; j< ans. size ( ) ; ) {
char c= ans[ j] ;
int num= 0 ;
while ( j< ans. size ( ) && ans[ j] == c) j++ , num++ ;
next+= c+ to_string ( num) ;
}
ans= next;
}
cout<< ans;
}
1147.堆
# include <iostream>
# include <algorithm>
using namespace std;
const int N= 1010 ;
int m, n;
int h[ N] ;
void dfs ( int u) {
if ( u* 2 <= n) dfs ( u* 2 ) ;
if ( u* 2 + 1 <= n) dfs ( u* 2 + 1 ) ;
cout<< h[ u] ;
if ( u!= 1 ) cout<< " " ;
}
int main ( ) {
cin>> m>> n;
while ( m-- ) {
for ( int i= 1 ; i<= n; i++ ) cin>> h[ i] ;
bool lt= false , gt= false ;
for ( int i= 1 ; i<= n; i++ )
for ( int j= 0 ; j< 2 ; j++ ) {
if ( i* 2 + j<= n) {
int root = h[ i] , son= h[ i* 2 + j] ;
if ( root> son) gt= true ;
if ( root< son) lt= true ;
}
}
if ( gt && lt) cout<< "Not Heap" << endl;
else if ( gt) cout<< "Max Heap" << endl;
else cout<< "Min Heap" << endl;
dfs ( 1 ) ;
cout<< endl;
}
}