Codeforces Round #827
A. Sum
找到最大值即可
#include<bits/stdc++.h>
using namespace std;
int read(){
int x = 0 , f = 1 , ch = getchar();
while( (ch < '0' || ch > '9') && ch != '-' ) ch = getchar();
if( ch == '-' ) f = -1 , ch = getchar();
while( ch >= '0' && ch <= '9' ) x = ( x << 3 ) + ( x << 1 ) + ch - '0' , ch = getchar();
return x * f;
}
int main(){
for( int T = read() , a , b , c ; T ; T -- ){
a = read() , b = read() , c = read();
if( a < b ) swap( a , b );
if( a < c ) swap( a , c );
cout << ( a == b + c ? "YES\n" : "NO\n" );
}
}
B. Increasing
只要有相等的数就一定不行,所以用 set 去一下重就好
#include<bits/stdc++.h>
using namespace std;
int read(){
int x = 0 , f = 1 , ch = getchar();
while( (ch < '0' || ch > '9') && ch != '-' ) ch = getchar();
if( ch == '-' ) f = -1 , ch = getchar();
while( ch >= '0' && ch <= '9' ) x = ( x << 3 ) + ( x << 1 ) + ch - '0' , ch = getchar();
return x * f;
}
int main(){
for( int T = read() , n ; T ; T -- ){
n = read();
set<int> s;
for( int i = 1 , x ; i <= n ; i ++ )
x = read() , s.insert(x);
cout << ( s.size() == n ? "YES\n" : "NO\n" );
}
}
C. Stripes
最后一次画的一定是完整的一行或一列,并且除此之外不会有完整的行列,因为保证一行一列交替画
所有判断一下有没有完整的一行RRRRRRRR
即可
#include<bits/stdc++.h>
using namespace std;
string s[10];
void solve(){
for( int i = 0 ; i < 8 ; i ++ )
cin >> s[i];
for( int i = 0 ; i < 8 ; i ++ )
if( s[i] == "RRRRRRRR" ){
cout << "R\n";
return;
}
cout << "B\n";
return;
}
int32_t main() {
int t ; cin >> t;
for( ; t ; t -- )
solve();
return 0;
}
D. Coprime
虽然数字很多,但是数字的范围很小,我们记录一下每个数最后出现的位置,然后\(O(n^2)\)的找一下最大值就好
#include<bits/stdc++.h>
using namespace std;
int read() {
int x = 0, f = 1, ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') f = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
return x * f;
}
const int N = 1005;
int v[N] , res ;
void solve(){
fill( v , v + N , 0 );
res = -1;
for( int n = read() , i = 1 , x ; i <= n ; i ++ )
x = read() , v[x] = i;
for( int i = 1 ; i <= 1000 ; i ++ )
for( int j = i ; j <= 1000 ; j ++ ){
if( v[i] == 0 || v[j] == 0 || gcd( i , j ) != 1 ) continue;
res = max( res , v[i] + v[j] );
}
cout << res << "\n";
}
int32_t main() {
for( int t = read() ; t ; t -- )
solve();
return 0;
}
E. Scuza
求一下前缀最大值,然后在序列上二分查找就好
#include<bits/stdc++.h>
#define int long long
using namespace std;
int read() {
int x = 0, f = 1, ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') f = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
return x * f;
}
const int N = 2e5+5;
int a[N] , b[N];
void solve(){
int n = read() , q = read();
for( int i = 1 , x ; i <= n ; i ++ )
x = read() , a[i] = max( a[i-1] , x ) , b[i] = b[i-1] + x;
for( int t , x ; q ; q -- ){
x = read();
t = upper_bound( a + 1 , a+1+n , x ) - a - 1;
cout << b[t] << " ";
}
return;
}
int32_t main() {
for( int t = read() ; t ; t -- )
solve() , cout << "\n";
return 0;
}
F. Smaller
首先对于s 和 t,如果希望 s小于 t,那么最优的情况就是 s 按照升序排,t 按照降序排
那么这样的话,因为一开始s 和 t 都有一个 a,所以只要 t 有非 a 的字母一定可以
如果 t 没有非 a 字母,但是 s 有则一定不可以
如果 st 都没有,s 比 t 短可以
#include<bits/stdc++.h>
#define int long long
using namespace std;
int read() {
int x = 0, f = 1, ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') f = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
return x * f;
}
const int N = 2e5+5;
void solve(){
int cntA = 1 , otherA = 0 , cntB = 1 , otherB = 0;
string s;
for( int q = read() , k , x ; q ; q -- ){
k = read() , x = read() , cin >> s;
if( k == 1 ){
for( auto c : s ){
if( c == 'a' ) cntA += x;
else otherA = 1;
}
}
else{
for( auto c : s ){
if( c == 'a' ) cntB += x;
else otherB = 1;
}
}
if( otherB )
cout << "YES\n";
else if( otherA == 0 && cntA < cntB )
cout << "YES\n";
else
cout << "NO\n";
}
return;
}
int32_t main() {
for( int t = read() ; t ; t -- )
solve();
return 0;
}
G. Orray
因为数字的范围只有 1e9 所以,二进制下只有 30 位,那么最多只要选出 30 个数字就好
那么我们暴力的去找哪一个数字和当前数字或起来最大的,就输出
如果所有数字或起来不会更大就不用找了,直接输出剩下所有的数字
#include<bits/stdc++.h>
using namespace std;
int read() {
int x = 0, f = 1, ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') f = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
return x * f;
}
const int N = 2e5+5;
int a[N];
bitset<N> vis;
void solve(){
int n = read();
vis.reset();
for( int i = 1 ; i <= n ; i ++ )
a[i] = read();
for( int t = min( n , 30 ) , id , sumOR = 0 , maxOR ; t ; t -- ){
maxOR = sumOR , id = -1;
for( int i = 1 ; i <= n ; i ++ ){
if( vis[i] ) continue;
if( (sumOR | a[i]) > maxOR )
maxOR = (sumOR | a[i]) , id = i;
}
if( id == -1 ) break;
cout << a[id] << " ";
vis[id] = 1 , sumOR |= a[id];
}
for( int i = 1 ; i <= n ; i ++ )
if( !vis[i] ) cout << a[i] << " ";
cout << "\n";
}
int main(){
for( int t = read() ; t ; t -- )
solve();
}