MC0301数字大王
语法题
#include <bits/stdc++.h>
using namespace std ;
int main()
{
cin.tie(nullptr)->ios::sync_with_stdio(false) ;
int n , mx = 0 ;
cin >> n ;
for(int i = 1 ; i <= n ; ++ i)
{
int x ;
cin >> x ;
mx = max(mx , x) ;
}
cout << mx << '\n' ;
return 0 ;
}
MC0302世界守护者
语法题
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
using namespace std ;
int main()
{
cin.tie(nullptr)->ios::sync_with_stdio(false) ;
vector<int> a(3) ;
for(auto & p : a) cin >> p ;
sort(all(a)) ;
for(auto p : a) cout << p << ' ' ;
return 0 ;
}
MC0303宝藏大冒险
筛素数
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
using namespace std ;
const int N = 1e5 + 10 ;
int primes[N] ;
bitset<N> st ;
void get_prime(int n)
{
for(int i = 2 ; i <= n ; ++ i)
{
if ( !st[i] ) primes[++primes[0]] = i ;
for(int j = 1 ; primes[j] <= n / i ; ++ j)
{
st[primes[j] * i] = 1 ;
if ( i % primes[j] == 0 ) break ;
}
}
}
int main()
{
cin.tie(nullptr)->ios::sync_with_stdio(false) ;
int n ;
cin >> n ;
get_prime(n) ;
cout << primes[0] ;
return 0 ;
}
MC0304拔河
二分答案
#include <bits/stdc++.h>
using namespace std ;
const int N = 1e5 + 10 ;
int n , m ;
double a[N] , b[N] ;
bool check(double mid)
{
double mn = 0 ;
for(int i = 1 ; i <= n ; ++ i) {
b[i] = a[i] - mid + b[i - 1] ;
if ( i >= m )
{
mn = min(mn , b[i - m]) ;
if ( b[i] - mn >= 0 ) return true ;
}
}
return false ;
}
int main()
{
cin.tie(nullptr)->ios::sync_with_stdio(false) ;
cin >> n >> m ;
for(int i = 1 ; i <= n ; ++ i) cin >> a[i] ;
double l = 1 , r = 2000 ;
while (r - l >= 1e-6)
{
double mid = (l + r) / 2;
if ( check(mid) ) l = mid ;
else r = mid ;
}
cout << (int)(r * 1000) << '\n' ;
return 0;
}
MC0305排名计算
语法题
#include <bits/stdc++.h>
using namespace std ;
int main()
{
cin.tie(nullptr)->ios::sync_with_stdio(false) ;
int n ;
cin >> n ;
map<int , int , greater<int>> mp ;
for(int i = 1 ; i <= n ; ++ i)
{
int x ;
cin >> x;
++ mp[x] ;
}
int q , p = 0 ;
cin >> q;
for(auto s : mp)
{
if ( s.first == q ) return cout << p + 1 << '\n' , 0 ;
p += s.second;
}
return 0 ;
}
MC0306字符魔鬼
语法题
#include<bits/stdc++.h>
using namespace std;
int main( )
{
char s ;
cin >> s ;
cout << (int)s ;
return 0;
}
MC0307迷宫挑战
BFS
#include <bits/stdc++.h>
using namespace std ;
const int N = 1e6 + 10 ;
int n , x , y , a[N] , d[N] ;
int main()
{
cin.tie(nullptr)->ios::sync_with_stdio(false) ;
cin >> n >> x >> y ;
for(int i = 1 ; i <= n ; ++ i) cin >> a[i];
memset(d , 0x3f , sizeof d) ;
queue<int> que ;
que.push(x) ;
d[x] = 0 ;
while (!que.empty())
{
int v = que.front() ; que.pop() ;
if ( v + a[v] <= n && d[v + a[v]] > d[v] + 1 )
{
d[v + a[v]] = d[v] + 1 ;
que.push(v + a[v]) ;
}
if ( v - a[v] >= 1 && d[v - a[v]] > d[v] + 1 )
{
d[v - a[v]] = d[v] + 1 ;
que.push(v - a[v]) ;
}
}
cout << (d[y] == 0x3f3f3f3f ? -1 : d[y]) << '\n' ;
return 0 ;
}
MC0308代课的一天
语法题
#include <bits/stdc++.h>
using namespace std ;
int main()
{
cin.tie(nullptr)->ios::sync_with_stdio(false) ;
string str ;
getline(cin , str) ;
int ret = 0 ;
for(auto s : str) if ( s >= 'A' && s <= 'Z' ) ++ ret ;
cout << ret << '\n' ;
return 0 ;
}
MC0309 魔法项链
拆位
#include <bits/stdc++.h>
#define int long long
using namespace std ;
signed main()
{
cin.tie(nullptr)->ios::sync_with_stdio(false) ;
int n ;
cin >> n ;
vector<int> a(n) , cnt(40 , 0) ;
int x = 0 , y = 0 , z = 0 ;
for(auto & p : a) {
cin >> p ;
x += p ;
for(int i = 30 ; i >= 0 ; -- i)
if ( p >> i & 1 )
++ cnt[i] ;
}
for(auto p : a)
{
for(int i = 30 ; i >= 0 ; -- i)
if ( p >> i & 1 )
{
y += (cnt[i] - 1) * (1 << i) ;
}
else
{
z += cnt[i] * (1 << i) ;
}
}
cout << x + y + z << '\n' ;
return 0 ;
}
MC0310挑战字符串
语法题
#include <bits/stdc++.h>
using namespace std ;
int main()
{
string str ;
cin >> str ;
reverse(str.begin(),str.end()) ;
cout << str ;
return 0 ;
}
MC0311云顶之奕
模拟
#include <bits/stdc++.h>
using namespace std ;
const int N = 510 ;
int cnt[N] , s ;
int main()
{
cin.tie(nullptr)->ios::sync_with_stdio(false) ;
for(int i = 1 ; i <= 8 ; ++ i)
{
int x ;
cin >> x ;
++cnt[x] ;
++ s ;
if ( cnt[x] == 3 )
{
cnt[x] = 0 ;
cnt[x * 10] ++ ;
s -= 2;
}
}
int n ;
cin >> n ;
for(int i = 1 ; i <= n ; ++ i)
{
int x ;
cin >> x ;
if ( cnt[x] == 2 )
{
cnt[x] = 0 ;
cnt[x * 10] ++ ;
s -- ;
if ( cnt[x * 10] == 3 )
{
cnt[x * 100] ++ ;
cnt[x * 10] = 0 ;
s -= 2 ;
}
}
else if ( s < 8 ) ++ cnt[x] , ++ s ;
}
int m ;
cin >> m ;
for(int i = 500 ; i >= m ; -- i) if ( cnt[i] ) return cout << "YES YES YES\n", 0 ;
cout << "NO NO NO\n" ;
return 0 ;
}
MC0312死亡名单
线段树上二分做法 O(nlogn)
#include <bits/stdc++.h>
#define int long long
using namespace std ;
#define ls ( x << 1 )
#define rs ( x << 1 | 1 )
const int N = 1e4 + 10 ;
int cnt[N << 2] , n , a[N] , m ;
inline void update(int x) { cnt[x] = cnt[ls] + cnt[rs] ; }
void build(int l,int r,int x) {
if ( l == r ) return cnt[x] = 1 , void() ;
int mid = ( l + r ) >> 1 ;
build(l , mid , ls) , build(mid +1 , r , rs) ;
update(x) ;
}
inline void modify(int pos,int l,int r,int x) {
if ( l == r ) return cnt[x] = a[pos] = 0 , void() ;
int mid = (l + r) >> 1 ;
if ( pos <= mid ) modify(pos , l , mid , ls) ;
else modify(pos , mid + 1 , r , rs) ;
update(x) ;
}
inline int query(int k,int l,int r,int x) {
if ( l == r ) return r ;
int mid = (l + r) >> 1 ;
if ( cnt[ls] >= k ) return query(k , l , mid , ls) ;
return query(k - cnt[ls] , mid + 1 , r , rs) ;
}
signed main()
{
cin.tie(nullptr)->ios::sync_with_stdio(false) ;
cin >> n ;
for(int i = 1 ; i <= n ; ++ i) cin >> a[i] ;
build(1 , n , 1) ;
cin >> m ;
for(int i = 1 ; i <= m ; ++ i)
{
int x ;
cin >> x ;
modify(query(x , 1 , n , 1) , 1 , n , 1) ;
}
for(int i = 1 ; i <= n ; ++ i)
if ( a[i] ) cout << a[i] << ' ' ;
return 0 ;
}
MC0313最佳邻居
语法题
#include <bits/stdc++.h>
using namespace std ;
int main()
{
cin.tie(nullptr)->ios::sync_with_stdio(false) ;
int n ;
cin >> n ;
vector<int> a(n * 2) ;
for(int i = 0 ; i < n ; ++ i)
{
cin >> a[i] ;
a[n + i] = a[i] ;
}
int p , mx = 0 ;
for(int i = 0 ; i < n ; ++ i)
{
int s = a[i] + a[i + 1] + a[i + 2] + a[i + 3] ;
if (mx < s) mx = s , p = i ;
}
cout << mx << '\n' << p + 1 << '\n' ;
return 0 ;
}